1. 完成了语音识别的C++业务层封装,测试通过
2. 试着测试了一下LVGL_GIF渲染+音乐播放+语音识别的组合简单优化后,
发现lvgl渲染略显卡顿,语音识别有缓冲区空警告,不过无伤大雅,还需要进一步深度优化。
This commit is contained in:
@@ -113,8 +113,98 @@ void testPetSystem() {
|
||||
std::cout << SDFileManager::getInstance()->catCommand("/sdcard/pet_data/my_pet.json") << std::endl;
|
||||
}
|
||||
|
||||
|
||||
#include "SpeechRecognizer.h"
|
||||
#include <nvs.h>
|
||||
#include <nvs_flash.h>
|
||||
// 命令回调函数
|
||||
void commandCallback(int command_id, const std::string& phrase, float probability) {
|
||||
ESP_LOGI("Example", "Received command: ID=%d, Phrase='%s', Probability=%.2f",
|
||||
command_id, phrase.c_str(), probability);
|
||||
|
||||
// 根据命令执行相应操作
|
||||
switch (command_id) {
|
||||
case 0:
|
||||
ESP_LOGI("Example", "执行命令0");
|
||||
// 执行命令0的操作
|
||||
break;
|
||||
case 1:
|
||||
ESP_LOGI("Example", "执行命令1");
|
||||
// 执行命令1的操作
|
||||
break;
|
||||
case 2:
|
||||
ESP_LOGI("Example", "执行命令2");
|
||||
// 执行命令2的操作
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI("Example", "未知的命令ID: %d", command_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 状态回调函数
|
||||
void stateCallback(const std::string& state) {
|
||||
ESP_LOGI("Example", "状态改变到: %s", state.c_str());
|
||||
}
|
||||
#include "SDFileManager.h"
|
||||
void testMIC() {
|
||||
// 初始化NVS
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
// 初始化SD卡管理器
|
||||
SDFileManager::getInstance()->tryInitSDCard();
|
||||
|
||||
// 获取SpeechRecognizer实例
|
||||
SpeechRecognizer* recognizer = SpeechRecognizer::getInstance();
|
||||
|
||||
// 配置识别器
|
||||
SpeechRecognizerConfig config;
|
||||
config.enable_vad = true;
|
||||
config.vad_mode = VAD_MODE_3; // 更高的VAD灵敏度
|
||||
config.model_path = "/sdcard/srmodels";
|
||||
|
||||
// 初始化
|
||||
if (!recognizer->init(config)) {
|
||||
ESP_LOGE("main", "Failed to initialize speech recognizer");
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加自定义命令
|
||||
std::vector<std::pair<int, std::string>> commands = {
|
||||
{0, "kai deng"}, // 开灯
|
||||
{1, "guan deng"}, // 关灯
|
||||
{2, "ti gao liang du"}, // 提高亮度
|
||||
{3, "jiang di liang du"}, // 降低亮度
|
||||
{4, "bo fang yin yue"}, // 播放音乐
|
||||
{5, "ting zhi bo fang"} // 停止播放
|
||||
};
|
||||
|
||||
if (!recognizer->addCommands(commands)) {
|
||||
ESP_LOGE("main", "Failed to add some commands");
|
||||
}
|
||||
|
||||
// 注册回调函数
|
||||
recognizer->registerCommandCallback(commandCallback);
|
||||
recognizer->registerStateCallback(stateCallback);
|
||||
|
||||
// 开始识别
|
||||
if (!recognizer->start()) {
|
||||
ESP_LOGE("main", "Failed to start speech recognition");
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI("main", "Speech recognition system started successfully");
|
||||
|
||||
}
|
||||
|
||||
void Cpp_Hand() {
|
||||
testPetSystem();
|
||||
testMIC();
|
||||
// testPetSystem();
|
||||
|
||||
OTAClass oc;
|
||||
oc.Init();
|
||||
|
||||
Reference in New Issue
Block a user