class KeywordRecognizer
class KeywordRecognizer
: public std::enable_shared_from_this< KeywordRecognizer >
Recognizer type that is specialized to only handle keyword activation.
First, the object needs to be instantiated:
auto audioConfig = AudioConfig::FromMicrophoneInput(); // Or an alternative input
auto recognizer = [KeywordRecognizer::FromConfig](#fromconfig)(audioConfig);
(optional) Then, the events need to be wired in order to receive notifications:
recognizer->Recognized += [](const KeywordRecognitionEventArgs& event)
{
// Your logic here...
};
And finally, recognition needs to be started.
auto keywordModel = [KeywordRecognitionModel::FromFile](keywordrecognitionmodel.md#fromfile)(modelPath);
auto resultFuture = recognizer->RecognizeKeywordOnceAsync(keywordModel);
resultFuture.wait();
auto result = resultFuture.get();
Members
Recognized
Syntax: public EventSignal< const KeywordRecognitionEventArgs & > Recognized;
Signal for events related to the recognition of keywords.
Canceled
Syntax: public EventSignal< const SpeechRecognitionCanceledEventArgs & > Canceled;
Signal for events relating to the cancellation of an interaction. The event indicates if the reason is a direct cancellation or an error.
Properties
Syntax: public const PropertyCollection & Properties;
A collection of properties and their values defined for this KeywordRecognizer.
~KeywordRecognizer
Syntax: public inline ~KeywordRecognizer ( );
Destructor.
RecognizeOnceAsync
Syntax: public inline std::future< std::shared_ptr< KeywordRecognitionResult > > RecognizeOnceAsync ( std::shared_ptr< KeywordRecognitionModel > model );
Starts a keyword recognition session. This session will last until the first keyword is recognized. When this happens, a Recognized event will be raised and the session will end. To rearm the keyword, the method needs to be called again after the event is emitted.
Parameters
model
The KeywordRecognitionModel that describes the keyword we want to detect.
Returns
A future that resolves to a KeywordRecognitionResult that resolves once a keyword is detected.
Note that if no keyword is detected in the input, the task will never resolve (unless StopRecognition is called.
StopRecognitionAsync
Syntax: public inline std::future< void > StopRecognitionAsync ( );
Stops a currently active keyword recognition session.
Returns
A future that resolves when the active session (if any) is stopped.
FromConfig
Syntax: public inline static std::shared_ptr< KeywordRecognizer > FromConfig ( std::shared_ptr< Audio::AudioConfig > audioConfig );
Creates a KeywordRecognizer from an AudioConfig. The config is intended to define the audio input to be used by the recognizer object.
Parameters
audioConfig
Defines the audio input to be used by the recognizer.
Returns
A new KeywordRecognizer that will consume audio from the specified input.
If no audio config is provided, it will be equivalent to calling with a config constructed with AudioConfig::FromDefaultMicrophoneInput