Skip to content

Instantly share code, notes, and snippets.

@lrodorigo
Last active July 12, 2021 17:44
Show Gist options
  • Save lrodorigo/6934bc025a81b7695e697b0c1ef97f86 to your computer and use it in GitHub Desktop.
Save lrodorigo/6934bc025a81b7695e697b0c1ef97f86 to your computer and use it in GitHub Desktop.
#include <speechapi_cxx.h>
#include <iostream>
#include <unistd.h>
int main() {
using namespace Microsoft::CognitiveServices::Speech;
using namespace Microsoft::CognitiveServices::Speech::Audio;
auto config = SpeechConfig::FromSubscription("<<the-key>>", "eastus");
// Creates a speech recognizer using microphone as audio input. The default language is "en-us".
auto recognizer = SpeechRecognizer::FromConfig(config, "it-IT");
auto audio_config = AudioConfig::FromMicrophoneInput("default"); // Or an alternative input
auto keyword_recognizer = KeywordRecognizer::FromConfig(audio_config);
keyword_recognizer->Recognized += [&](const KeywordRecognitionEventArgs &event) {
std::cout<<"Keyword recognized"<<std::endl;
};
auto keyword_model = KeywordRecognitionModel::FromFile("./my-model.table");
std::cout<<"Invoking RecognizeOnceAsync"<<std::endl;
keyword_recognizer->RecognizeOnceAsync(keyword_model);
//auto res = keyword_recognizer->RecognizeOnceAsync(keyword_model); // if the result is used the method is actually async
// this line is never reached if the result of RecognizeOnceAsync is not used (due to the future destruction)
std::cout<<"Waiting for keyword..."<<std::endl;
sleep(60);
}
@lrodorigo
Copy link
Author

lrodorigo commented Jul 12, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment