语音识别模块类
更多...
#include <speech_recognizer.h>
|
enum | ErrorCode : uint32_t {
kOK = 0
, kI2cDataTooLongToFitInTransmitBuffer = 1
, kI2cReceivedNackOnTransmitOfAddress = 2
, kI2cReceivedNackOnTransmitOfData = 3
,
kI2cOtherError = 4
, kI2cTimeout = 5
, kInvalidParameter = 6
, kUnknownError = 7
} |
| 错误码 更多...
|
|
enum | RecognitionMode : uint8_t { kRecognitionAuto
, kButtonTrigger
, kKeywordTrigger
, kKeywordOrButtonTrigger
} |
| 识别模式 更多...
|
|
enum | Event : uint8_t {
kEventNone = 0
, kEventStartWaitingForTrigger
, kEventButtonTriggered
, kEventKeywordTriggered
,
kEventStartRecognizing
, kEventSpeechRecognized
, kEventSpeechRecognitionTimedOut
} |
| 事件类型 更多...
|
|
|
static constexpr uint8_t | kDefaultI2cAddress = 0x30 |
| 语音识别模块默认I2C地址
|
|
static constexpr uint8_t | kMaxKeywordDataBytes = 50 |
| 每条关键词最大字符数
|
|
◆ ErrorCode
错误码
枚举值 |
---|
kOK | 0:成功
|
kI2cDataTooLongToFitInTransmitBuffer | 1:I2C数据太长,无法装入传输缓冲区
|
kI2cReceivedNackOnTransmitOfAddress | 2:在I2C发送地址时收到NACK
|
kI2cReceivedNackOnTransmitOfData | 3:在I2C发送数据时收到NACK
|
kI2cOtherError | 4:其他I2C错误
|
kI2cTimeout | 5:I2C通讯超时
|
kInvalidParameter | 6:参数错误
|
kUnknownError | 7: 未知错误
|
◆ Event
事件类型
枚举值 |
---|
kEventNone | 无事件
|
kEventStartWaitingForTrigger | 开始等待触发
|
kEventButtonTriggered | 被按键触发
|
kEventKeywordTriggered | 被关键词触发
|
kEventStartRecognizing | 开始识别
|
kEventSpeechRecognized | 识别成功
|
kEventSpeechRecognitionTimedOut | 识别超时
|
◆ RecognitionMode
识别模式
枚举值 |
---|
kRecognitionAuto | 自动识别模式
|
kButtonTrigger | 按键触发识别模式
|
kKeywordTrigger | 关键词触发识别模式
|
kKeywordOrButtonTrigger | 按键或关键词触发识别模式
|
◆ SpeechRecognizer()
emakefun::SpeechRecognizer::SpeechRecognizer |
( |
TwoWire & |
wire = Wire , |
|
|
const uint8_t |
i2c_address = kDefaultI2cAddress |
|
) |
| |
|
explicit |
构造函数
- 参数
-
i2c_address | 语音识别模块I2C地址,默认为0x30 |
◆ AddKeyword()
void emakefun::SpeechRecognizer::AddKeyword |
( |
const uint8_t |
index, |
|
|
const String & |
keyword |
|
) |
| |
添加语音识别关键词
最多可以添加50个词,每个词最大长度为50个字节
- 参数
-
◆ GetEvent()
获取当前事件
- 返回
- 事件类型,参考枚举: Event
◆ Initialize()
初始化函数
- 参数
-
[in] | wire | Wire对象,用于I2C通讯,可选,默认使用Arduino标准的Wire对象进行I2C通讯 |
- 返回
- 初始化结果
- 返回值
-
true | 成功 |
false | 失败,如I2C无法与语音识别模块通讯 |
◆ Recognize()
int16_t emakefun::SpeechRecognizer::Recognize |
( |
| ) |
|
进行语音识别
在loop函数中循环调用该函数以推进语音识别模块的工作, 调用该函数后可以获取识别结果,可以通过( GetEvent )获取事件
- 返回
- 关键词的索引值
- 返回值
-
◆ SetRecognitionMode()
void emakefun::SpeechRecognizer::SetRecognitionMode |
( |
const RecognitionMode |
recognition_mode | ) |
|
◆ SetTimeout()
void emakefun::SpeechRecognizer::SetTimeout |
( |
const uint32_t |
timeout_ms | ) |
|
该类的文档由以下文件生成: