Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzongming committed Sep 1, 2024
1 parent 66d7d39 commit 308773e
Show file tree
Hide file tree
Showing 29 changed files with 428 additions and 319 deletions.
4 changes: 2 additions & 2 deletions client/esp-ai/examples/I2S-pin-config/I2S-pin-config.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = { };
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数 " }
ESP_AI_wifi_config wifi_config = { "", "", "ESP-AI"};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数 " }
ESP_AI_server_config server_config = {};
ESP_AI_wake_up_config wake_up_config = {"edge_impulse", 0.95};

Expand Down
20 changes: 11 additions & 9 deletions client/esp-ai/examples/asrpro-wakeup/asrpro-wakeup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

ESP_AI esp_ai;

void setup()
{
void setup() {
Serial.begin(9600);
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数" }
ESP_AI_wifi_config wifi_config = { "", "", "ESP-AI" };
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数" }
ESP_AI_server_config server_config = {};
// [必 填] 唤醒方案: { 方案, 语音唤醒用的阈值(本方案忽略即可), 引脚唤醒方案(本方案忽略), 发送的字符串 }
ESP_AI_wake_up_config wake_up_config = {"asrpro", 1, 10, "start"};
// [必 填] 唤醒方案: { 方案, 语音唤醒用的阈值(本方案忽略即可), 引脚唤醒方案(本方案忽略), 发送的字符串 }
ESP_AI_wake_up_config wake_up_config = {};
strcpy(wake_up_config.wake_up_scheme, "asrpro"); // 唤醒方案
strcpy(wake_up_config.str, "start"); // 串口和天问asrpro 唤醒时需要配置的字符串,也就是从另一个开发版发送来的字符串

esp_ai.begin({debug, wifi_config, server_config, wake_up_config});
ESP_AI_volume_config volume_config = {34, 4096, 0.8};

esp_ai.begin({ debug, wifi_config, server_config, wake_up_config, volume_config });
}

void loop()
{
void loop() {
esp_ai.loop();
}
2 changes: 1 addition & 1 deletion client/esp-ai/examples/btn-wakeup/btn-wakeup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void setup() {
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = { };
ESP_AI_wifi_config wifi_config = { "", "", "ESP-AI" };

// [必 填] 热点配置:
ESP_AI_server_config server_config = { };
Expand Down
2 changes: 1 addition & 1 deletion client/esp-ai/examples/diy-ap-page/diy-ap-page.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};
// 自定义配网页面
char html_str[] = "HTML content";
wifi_config.html_str = (char *)malloc(strlen(html_str) + 1);
Expand Down
4 changes: 2 additions & 2 deletions client/esp-ai/examples/diy-wakeup/diy-wakeup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数 }
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数 }
ESP_AI_server_config server_config = {};
// [必 填] 离线唤醒方案:{ 方案, 识别阈值 }, "edge_impulse" | "diy",为 "diy" 时可调用 esp_ai.wakeUp() 方法进行唤醒
ESP_AI_wake_up_config wake_up_config = {"diy"};
Expand Down
4 changes: 2 additions & 2 deletions client/esp-ai/examples/intention/intention.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_server_config server_config = {};
// [必 填] 离线唤醒方案:{ 方案, 识别阈值 }, "edge_impulse" | "diy",为 "diy" 时可调用 esp_ai.wakeUp() 方法进行唤醒
ESP_AI_wake_up_config wake_up_config = {"edge_impulse", 0.95};
Expand Down
2 changes: 1 addition & 1 deletion client/esp-ai/examples/on-event/on-event.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};

// [必 填] 热点配置:
ESP_AI_server_config server_config = {};
Expand Down
4 changes: 2 additions & 2 deletions client/esp-ai/examples/serial-wakeup/btn-wakeup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_server_config server_config = {};
// [必 填] 唤醒方案: { 方案, 语音唤醒用的阈值(本方案忽略即可), 引脚唤醒方案(本方案忽略), 发送的字符串 }
ESP_AI_wake_up_config wake_up_config = {"serial", 1, 10, "start"};
Expand Down
4 changes: 2 additions & 2 deletions client/esp-ai/examples/voice-wakeup/voice-wakeup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ void setup()
// [必 填] 是否调试模式, 会输出更多信息
bool debug = true;
// [必 填] wifi 配置: { wifi 账号, wifi 密码, "热点名字" } 可不设置,连不上wifi时会打开热点:ESP-AI,连接wifi后打开地址: 192.168.4.1 进行配网(控制台会输出地址,或者在ap回调中也能拿到信息)
ESP_AI_wifi_config wifi_config = {};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_wifi_config wifi_config = {"", "", "ESP-AI"};
// [ 填] 服务配置: { 服务IP, 服务端口, "[可选] 请求参数,用免费服务时,在 dev.espai.fun 中复制 key 即可" }
ESP_AI_server_config server_config = {};
// [必 填] 唤醒方案: { 方案, 语音唤醒用的阈值 , 引脚唤醒方案(本方案忽略), 发送的字符串(本方案忽略) }
ESP_AI_wake_up_config wake_up_config = {"edge_impulse", 0.95};
Expand Down
8 changes: 3 additions & 5 deletions client/esp-ai/src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ int16_t mic_sampleBuffer[mic_sample_buffer_size];

String wake_up_scheme = "edge_impulse";


// 生成34位uiud
String generateUUID()
{
Expand Down Expand Up @@ -89,11 +90,8 @@ String generateUUID()
for (int i = 0; i < 12; i++)
{
uuid += String(random(0, 16), HEX);
}

// 使字符串的每个字符为大写
uuid.toUpperCase();

}
uuid.toUpperCase();
return uuid;
}

Expand Down
7 changes: 3 additions & 4 deletions client/esp-ai/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct ESP_AI_wifi_config
char wifi_name[60];
char wifi_pwd[60];
// 热点名字
char ap_name[60];
char ap_name[30];
// 自定义页面
char *html_str;
};
Expand All @@ -111,7 +111,7 @@ struct ESP_AI_server_config
{
char ip[16];
int port;
char params[256];
char params[200];
};

struct ESP_AI_CONFIG
Expand Down Expand Up @@ -171,8 +171,7 @@ extern ESP_AI_volume_config default_volume_config;
if (debug) \
{ \
Serial.println(x); \
}

}

/** Audio buffers, pointers and selectors */
typedef struct
Expand Down
2 changes: 1 addition & 1 deletion client/esp-ai/src/init/speaker_i2s_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
void ESP_AI::speaker_i2s_setup()
{
AudioLogger::instance().begin(Serial, AudioLogger::Info);
DEBUG_PRINT(debug, "扬声器采样率:");
DEBUG_PRINT(debug, F("扬声器采样率:"));
DEBUG_PRINTLN(debug, i2s_config_speaker.sample_rate);
DEBUG_PRINTLN(debug, "");
// 配置项文档
Expand Down
2 changes: 1 addition & 1 deletion client/esp-ai/src/private/get_server_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool ESP_AI::get_server_config()
String loc_api_key = get_local_data("api_key");
if (loc_api_key == "")
{
DEBUG_PRINTLN(debug, "[Info] api_key 为空,需要自行配置服务IP与端口。");
DEBUG_PRINTLN(debug, ("[Info] api_key 为空,需要自行配置服务IP与端口。"));
return true;
}
DEBUG_PRINTLN(debug, "[Info] api_key:" + loc_api_key);
Expand Down
24 changes: 14 additions & 10 deletions client/esp-ai/src/sdk/begin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
pinMode(wake_up_config.pin, INPUT);
}
}
if(wake_up_scheme == "edge_impulse"){
Serial.println("[Error] edge_impulse 唤醒方案在 ESP-AI v2.0.0 中暂未发布,预计2.2.x中进行发布,请先使用其它唤醒方案!");
return;
}

// led 指示灯
pinMode(LED_BUILTIN, OUTPUT);
Expand All @@ -86,7 +90,7 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
String loc_api_key = get_local_data("api_key");
String loc_ext1 = get_local_data("ext1");
String loc_ext2 = get_local_data("ext2");
DEBUG_PRINTLN(debug, "==================== Local Data ====================");
DEBUG_PRINTLN(debug, ("==================== Local Data ===================="));
DEBUG_PRINTLN(debug, "loc_is_ready: " + loc_is_ready);
if (loc_is_ready != "ok")
{
Expand All @@ -107,7 +111,7 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
DEBUG_PRINTLN(debug, "loc_api_key: " + loc_api_key);
DEBUG_PRINTLN(debug, "loc_ext1: " + loc_ext1);
DEBUG_PRINTLN(debug, "loc_ext2: " + loc_ext2);
DEBUG_PRINTLN(debug, "=====================================================");
DEBUG_PRINTLN(debug, ("====================================================="));

// 启动热点,用于配网
if (loc_wifi_name == "" && wifi_config.wifi_name == "")
Expand All @@ -129,7 +133,7 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
return;
}

DEBUG_PRINTLN(debug, "==================== Connect WIFI ====================");
DEBUG_PRINTLN(debug, ("==================== Connect WIFI ===================="));
String _wifi_name = loc_wifi_name;
String _wifi_pwd = loc_wifi_pwd;
if (_wifi_name == "")
Expand All @@ -144,7 +148,7 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
DEBUG_PRINTLN(debug, "wifi name: " + _wifi_name);
DEBUG_PRINTLN(debug, "wifi pwd: " + _wifi_pwd);
WiFi.begin(_wifi_name, _wifi_pwd);
DEBUG_PRINT(debug, "connect wifi ing..");
DEBUG_PRINT(debug, F("connect wifi ing.."));

int connect_count = 0;
// 10s 连不上Wifi的话
Expand All @@ -162,7 +166,7 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
}
if (connect_count > try_count)
{
DEBUG_PRINTLN(debug, "\n连接WIFI失败,请重新配网" );
DEBUG_PRINTLN(debug, ("\n连接WIFI失败,请重新配网"));
// 重新配网
WiFi.mode(WIFI_AP);
String ap_name = strlen(wifi_config.ap_name) > 0 ? wifi_config.ap_name : "ESP-AI";
Expand Down Expand Up @@ -201,28 +205,28 @@ void ESP_AI::begin(ESP_AI_CONFIG config)
WiFi.setSleep(false);

DEBUG_PRINTLN(debug, "");
DEBUG_PRINT(debug, "wifi 连接成功,设备 IP 地址: ");
DEBUG_PRINT(debug, F("wifi 连接成功,设备 IP 地址: "));
DEBUG_PRINTLN(debug, WiFi.localIP());
String ip_str = WiFi.localIP().toString();
if (onConnectedWifiCb != nullptr)
{
onConnectedWifiCb(ip_str);
}

DEBUG_PRINTLN(debug, "===============================================");
DEBUG_PRINTLN(debug, ("==============================================="));

if (wake_up_scheme == "edge_impulse")
{
DEBUG_PRINTLN(debug, "=================== Edge Impulse ================");
DEBUG_PRINTLN(debug, ("=================== Edge Impulse ================"));
wakeup_init();
DEBUG_PRINTLN(debug, "===============================================");
DEBUG_PRINTLN(debug, ("==============================================="));
}
else
{
// 其他情况也正常初始化麦克风,需要上传音频给 IAT
if (mic_i2s_init(16000))
{
DEBUG_PRINTLN(debug, "[Error] Failed to start I2S!");
DEBUG_PRINTLN(debug, ("[Error] Failed to start I2S!"));
}
}

Expand Down
17 changes: 8 additions & 9 deletions client/esp-ai/src/sdk/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ void ESP_AI::loop()
if (onNetStatusCb != nullptr && net_status == "2" && net_status != "0")
{
net_status = "0";
onNetStatusCb("0");
DEBUG_PRINTLN(debug, "WIFI 异常断开,将自动重启板子");
onNetStatusCb("0");
DEBUG_PRINTLN(debug, ("WIFI 异常断开,将自动重启板子"));
ESP.restart();
delay(3000);
}
}
}

int _cur_ctrl_val = analogRead(volume_config.input_pin);
Expand All @@ -71,6 +71,8 @@ void ESP_AI::loop()
DEBUG_PRINTLN(debug, volume_config.volume);
}

bool is_use_edge_impulse = wake_up_scheme == "edge_impulse";

// if (ws_connected && start_ed != "1" && (strcmp(wake_up_config.wake_up_scheme, "edge_impulse") == 0))
// {
// if (inference.buf_ready != 0 && can_voice == "1")
Expand All @@ -79,12 +81,9 @@ void ESP_AI::loop()
// }
// }

bool is_use_edge_impulse = wake_up_scheme == "edge_impulse";
// 内置语音唤醒优化 ing...
// if (ws_connected && start_ed != "1" && (strcmp(wake_up_config.wake_up_scheme, "edge_impulse") == 0))
if (is_use_edge_impulse && ws_connected)
{
// if (inference.buf_ready != 0 && can_voice == "1")
if (inference.buf_ready != 0)
{
wakeup_inference();
Expand All @@ -96,7 +95,7 @@ void ESP_AI::loop()
String command = Serial.readStringUntil('\n');
if (command == String(wake_up_config.str))
{
DEBUG_PRINTLN(debug, "收到串口数据, 唤醒成功");
DEBUG_PRINTLN(debug, ("收到串口数据, 唤醒成功"));
wakeUp();
}
}
Expand All @@ -114,7 +113,7 @@ void ESP_AI::loop()
if (prev_state != reading)
{
prev_state = reading;
DEBUG_PRINTLN(debug, "按下了按钮, 唤醒成功");
DEBUG_PRINTLN(debug, ("按下了按钮, 唤醒成功"));
wakeUp();
}
}
Expand All @@ -131,7 +130,7 @@ void ESP_AI::loop()
String clear_str = cleanString(command);
if (clear_str == String(wake_up_config.str))
{
DEBUG_PRINTLN(debug, "收到串口数据, 唤醒成功");
DEBUG_PRINTLN(debug, ("收到串口数据, 唤醒成功"));
wakeUp();
}
delay(3);
Expand Down
12 changes: 6 additions & 6 deletions client/esp-ai/src/sdk/setWifiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool ESP_AI::setWifiConfig(char wifi_name[60], char wifi_pwd[60], char api_key[6
strncpy(wifi_config.wifi_pwd, wifi_pwd, sizeof(wifi_config.wifi_pwd) - 1);
wifi_config.wifi_pwd[sizeof(wifi_config.wifi_pwd) - 1] = '\0';

DEBUG_PRINTLN(debug, "==================== 调用方法设置信息 ====================");
DEBUG_PRINTLN(debug, ("==================== 调用方法设置信息 ===================="));
DEBUG_PRINTLN(debug, "wifi name: " + String(wifi_config.wifi_name));
DEBUG_PRINTLN(debug, "wifi pwd: " + String(wifi_config.wifi_pwd));
WiFi.begin(wifi_config.wifi_name, wifi_config.wifi_pwd);
Expand All @@ -57,7 +57,7 @@ bool ESP_AI::setWifiConfig(char wifi_name[60], char wifi_pwd[60], char api_key[6
// 连接失败并且没有存储wifi信息就重启板子
if (WiFi.status() != WL_CONNECTED)
{
DEBUG_PRINTLN(debug, "设置 WIF 连接失败");
DEBUG_PRINTLN(debug, ("设置 WIF 连接失败"));
String loc_wifi_name = get_local_data("wifi_name");
String loc_wifi_pwd = get_local_data("wifi_pwd");
WiFi.begin(loc_wifi_name, loc_wifi_pwd);
Expand All @@ -72,22 +72,22 @@ bool ESP_AI::setWifiConfig(char wifi_name[60], char wifi_pwd[60], char api_key[6
net_status = "0_ing";
onNetStatusCb("0_ing");
}

connect_count++;
delay(500);
DEBUG_PRINT(debug, ".");
}
if (WiFi.status() != WL_CONNECTED)
{
DEBUG_PRINTLN(debug, "设置 WIFI 连接失败,重启板子");
DEBUG_PRINTLN(debug, ("设置 WIFI 连接失败,重启板子"));
ESP.restart();
}
return false;
}
DEBUG_PRINTLN(debug, "");
DEBUG_PRINT(debug, "IP address: ");
DEBUG_PRINT(debug, F("IP address: "));
DEBUG_PRINTLN(debug, WiFi.localIP());
DEBUG_PRINTLN(debug, "===============================================");
DEBUG_PRINTLN(debug, ("==============================================="));
// 持久保存, 这一步都是可选的
if (String(wifi_name).length() > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions client/esp-ai/src/sdk/wakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void ESP_AI::wakeUp()
data["type"] = "start";
String sendData = JSON.stringify(data);
webSocket.sendTXT(sendData);
DEBUG_PRINTLN(debug, "[Info] -> 开始录音");
DEBUG_PRINTLN(debug, ("[Info] -> 开始录音"));
}else{
Serial.println("[Error] -> 请先连接服务器");
Serial.println(F("[Error] -> 请先连接服务器"));
}
}
Loading

0 comments on commit 308773e

Please sign in to comment.