Class KeywordRecognizer
class KeywordRecognizer
: public std::enable_shared_from_this< KeywordRecognizer >
专用于仅处理关键字激活的识别器类型。
首先,需要实例化对象:
auto audioConfig = AudioConfig::FromMicrophoneInput(); // Or an alternative input
auto recognizer = [KeywordRecognizer::FromConfig](#fromconfig)(audioConfig);
(可选)然后,事件需要有线才能接收通知:
recognizer->Recognized += [](const KeywordRecognitionEventArgs& event)
{
// Your logic here...
};
最后,需要开始识别。
auto keywordModel = [KeywordRecognitionModel::FromFile](keywordrecognitionmodel.md#fromfile)(modelPath);
auto resultFuture = recognizer->RecognizeKeywordOnceAsync(keywordModel);
resultFuture.wait();
auto result = resultFuture.get();
成员
已确认
语法:public EventSignal< const KeywordRecognitionEventArgs & > Recognized;
与关键字识别相关的事件的信号。
取消
语法:public EventSignal< const SpeechRecognitionCanceledEventArgs & > Canceled;
与取消交互相关的事件的信号。 该事件指示原因是直接取消还是错误。
性能
语法:public const PropertyCollection & Properties;
为此 KeywordRecognizer 定义的属性及其值的集合。
~KeywordRecognizer
语法:public inline ~KeywordRecognizer ( );
析构函数。
RecognizeOnceAsync
语法:public inline std::future< std::shared_ptr< KeywordRecognitionResult > > RecognizeOnceAsync ( std::shared_ptr< KeywordRecognitionModel > model );
启动关键字识别会话。 此会话将持续到识别第一个关键字。 发生这种情况时,将引发 已识别 事件,会话将结束。 若要重新排列关键字,需要在发出事件后再次调用该方法。
参数
-
model
描述要检测的关键字的 KeywordRecognitionModel。
退货
一个解析为 KeywordRecognitionResult 的未来,该关键字在检测到关键字后解析。
请注意,如果在输入中未检测到关键字,则任务永远不会解析(除非调用 StopRecognition。
StopRecognitionAsync
语法:public inline std::future< void > StopRecognitionAsync ( );
停止当前处于活动状态的关键字识别会话。
退货
一个在活动会话(如果有)停止时解决的未来。
FromConfig
语法:public inline static std::shared_ptr< KeywordRecognizer > FromConfig ( std::shared_ptr< Audio::AudioConfig > audioConfig );
从 AudioConfig 创建 KeywordRecognizer。 该配置旨在定义识别器对象要使用的音频输入。
参数
-
audioConfig
定义识别器要使用的音频输入。
退货
一个新的 KeywordRecognizer,它将使用来自指定输入的音频。
如果未提供音频配置,则它等效于使用 AudioConfig::FromDefaultMicrophoneInput 构造的配置进行调用