Emakefun Speech Recognizer 2.1
载入中...
搜索中...
未找到
lots_of_keywords.ino
/**
* @example lots_of_keywords.ino
*/
#include <Arduino.h>
#include <Wire.h>
#include "speech_recognizer.h"
#define INFINITE_LOOP_ON_FAILURE InfiniteLoopOnFailure(__FUNCTION__, __LINE__)
namespace {
emakefun::SpeechRecognizer g_speech_recognizer;
void InfiniteLoopOnFailure(const char* function, const uint32_t line_number) {
Serial.println(String(F("entering an infinite loop due to failure in ")) + function + F(", at line number: ") + line_number);
while (true) {
yield();
}
}
String EventToString(const emakefun::SpeechRecognizer::Event event) {
switch (event) {
return F("kEventStartWaitingForTrigger");
return F("kEventStartRecognizing");
return F("kEventSpeechRecognized");
return F("kEventSpeechRecognitionTimedOut");
return F("kEventButtonTriggered");
return F("kEventKeywordTriggered");
default:
return F("");
}
}
} // namespace
void setup() {
Serial.begin(115200);
Serial.println(F("setup"));
Wire.begin();
const auto ret = g_speech_recognizer.Initialize();
Serial.println(F("speech recognizer initialization was successful"));
} else {
Serial.println(String(F("speech recognizer initialization failed: ")) + ret);
INFINITE_LOOP_ON_FAILURE;
}
g_speech_recognizer.SetRecognitionMode(emakefun::SpeechRecognizer::kRecognitionAuto);
g_speech_recognizer.AddKeyword(0, F("xiao yi xiao yi"));
g_speech_recognizer.AddKeyword(1, F("bei jing"));
g_speech_recognizer.AddKeyword(2, F("chong qin"));
g_speech_recognizer.AddKeyword(3, F("cheng du"));
g_speech_recognizer.AddKeyword(4, F("shang hai"));
g_speech_recognizer.AddKeyword(5, F("tian jin"));
g_speech_recognizer.AddKeyword(6, F("wu han"));
g_speech_recognizer.AddKeyword(7, F("nan jing"));
g_speech_recognizer.AddKeyword(8, F("lan zhou"));
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(13, F("su zhou"));
g_speech_recognizer.AddKeyword(14, F("taizhou"));
g_speech_recognizer.AddKeyword(15, F("dalian"));
g_speech_recognizer.AddKeyword(16, F("wu xi"));
g_speech_recognizer.AddKeyword(17, F("he fei"));
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(21, F("huaian"));
g_speech_recognizer.AddKeyword(22, F("yan tai"));
g_speech_recognizer.AddKeyword(23, F("zhu hai"));
g_speech_recognizer.AddKeyword(24, F("sha men"));
g_speech_recognizer.AddKeyword(25, F("fuzhou"));
g_speech_recognizer.AddKeyword(26, F("nanning"));
g_speech_recognizer.AddKeyword(27, F("lan zhou"));
g_speech_recognizer.AddKeyword(28, F("gui lin"));
g_speech_recognizer.AddKeyword(29, F("kun ming"));
g_speech_recognizer.AddKeyword(30, F("xiang gang"));
g_speech_recognizer.AddKeyword(31, F("ao men"));
g_speech_recognizer.AddKeyword(32, F("tai bei"));
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(43, F("da tuan"));
g_speech_recognizer.AddKeyword(44, F("en shi"));
g_speech_recognizer.AddKeyword(45, F("jiu jiang"));
g_speech_recognizer.AddKeyword(46, F("fu yang"));
g_speech_recognizer.AddKeyword(47, F("ji nan"));
g_speech_recognizer.AddKeyword(48, F("jin hua"));
g_speech_recognizer.AddKeyword(49, F("xi an"));
Serial.println(F("setup successful"));
}
void loop() {
const auto result = g_speech_recognizer.Recognize();
if (result >= 0) {
Serial.print(F("result: "));
Serial.println(result);
}
if (g_speech_recognizer.GetEvent() != emakefun::SpeechRecognizer::kEventNone) {
Serial.print(F("event: "));
Serial.println(EventToString(g_speech_recognizer.GetEvent()));
}
}
语音识别模块类
Definition speech_recognizer.h:13
@ kRecognitionAuto
自动识别模式
Definition speech_recognizer.h:44
@ kOK
Definition speech_recognizer.h:30
Event
事件类型
Definition speech_recognizer.h:54
@ kEventNone
无事件
Definition speech_recognizer.h:55
@ kEventStartWaitingForTrigger
开始等待触发
Definition speech_recognizer.h:56
@ kEventStartRecognizing
开始识别
Definition speech_recognizer.h:59
@ kEventSpeechRecognized
识别成功
Definition speech_recognizer.h:60
@ kEventSpeechRecognitionTimedOut
识别超时
Definition speech_recognizer.h:61
@ kEventButtonTriggered
被按键触发
Definition speech_recognizer.h:57
@ kEventKeywordTriggered
被关键词触发
Definition speech_recognizer.h:58