#include <Arduino.h>
#include <Wire.h>
#include "speech_recognizer.h"
switch (event) {
return F("kEventStartWaitingForTrigger");
return F("kEventStartRecognizing");
return F("kEventSpeechRecognized");
return F("kEventSpeechRecognitionTimedOut");
return F("kEventButtonTriggered");
return F("kEventKeywordTriggered");
default:
return F("");
}
}
void setup() {
Serial.begin(115200);
Serial.println(F("setup"));
Wire.begin();
const auto ret = g_speech_recognizer.
Initialize(&Wire);
if (0 == ret) {
Serial.println(F("speech recognizer initialization was successful"));
} else {
Serial.println(String(F("speech recognizer initialization failed: ")) + ret);
while (true)
;
}
g_speech_recognizer.
AddKeyword(0, F(
"xiao yi xiao yi"));
g_speech_recognizer.
AddKeyword(2, F(
"chong qin"));
g_speech_recognizer.
AddKeyword(4, F(
"shang hai"));
g_speech_recognizer.
AddKeyword(9, F(
"xian yang"));
g_speech_recognizer.
AddKeyword(10, F(
"cheng de"));
g_speech_recognizer.
AddKeyword(11, F(
"hang zhou"));
g_speech_recognizer.
AddKeyword(12, F(
"shen zhen"));
g_speech_recognizer.
AddKeyword(18, F(
"chang sha"));
g_speech_recognizer.
AddKeyword(19, F(
"zheng zhou"));
g_speech_recognizer.
AddKeyword(20, F(
"qin huang dao"));
g_speech_recognizer.
AddKeyword(27, F(
"lan zhou"));
g_speech_recognizer.
AddKeyword(29, F(
"kun ming"));
g_speech_recognizer.
AddKeyword(30, F(
"xiang gang"));
g_speech_recognizer.
AddKeyword(33, F(
"xin jiang"));
g_speech_recognizer.
AddKeyword(34, F(
"nei mong gu"));
g_speech_recognizer.
AddKeyword(35, F(
"liao ning"));
g_speech_recognizer.
AddKeyword(36, F(
"chao zhou"));
g_speech_recognizer.
AddKeyword(37, F(
"sui ning"));
g_speech_recognizer.
AddKeyword(38, F(
"qiqihaer"));
g_speech_recognizer.
AddKeyword(39, F(
"huang gang"));
g_speech_recognizer.
AddKeyword(40, F(
"wu lu mu qi"));
g_speech_recognizer.
AddKeyword(41, F(
"yan shan"));
g_speech_recognizer.
AddKeyword(42, F(
"xin xiang"));
g_speech_recognizer.
AddKeyword(45, F(
"jiu jiang"));
Serial.println(F("setup was successful"));
}
void loop() {
const auto result = g_speech_recognizer.
Recognize();
if (result >= 0) {
Serial.print(F("result: "));
Serial.println(result);
}
Serial.print(F("event: "));
Serial.println(EventToString(g_speech_recognizer.
GetEvent()));
}
}
语音识别模块类
Definition speech_recognizer.h:12
static constexpr uint8_t kDefaultI2cAddress
语音识别模块默认I2C地址
Definition speech_recognizer.h:17
Event GetEvent()
获取当前事件
Definition speech_recognizer.cpp:116
int32_t Initialize(TwoWire *const wire=&Wire)
初始化函数
Definition speech_recognizer.cpp:44
@ kRecognitionAuto
自动识别模式
Definition speech_recognizer.h:28
int16_t Recognize()
进行语音识别
Definition speech_recognizer.cpp:99
void AddKeyword(const uint8_t index, const String &keyword)
添加语音识别关键词
Definition speech_recognizer.cpp:76
void SetRecognitionMode(const RecognitionMode recognition_mode)
设置识别模式
Definition speech_recognizer.cpp:60
Event
事件类型
Definition speech_recognizer.h:38
@ kEventNone
无事件
Definition speech_recognizer.h:39
@ kEventStartWaitingForTrigger
开始等待触发
Definition speech_recognizer.h:40
@ kEventStartRecognizing
开始识别
Definition speech_recognizer.h:43
@ kEventSpeechRecognized
识别成功
Definition speech_recognizer.h:44
@ kEventSpeechRecognitionTimedOut
识别超时
Definition speech_recognizer.h:45
@ kEventButtonTriggered
被按键触发
Definition speech_recognizer.h:41
@ kEventKeywordTriggered
被关键词触发
Definition speech_recognizer.h:42