Reputation: 41
I am trying to get Windows::Media::SpeechRecognition
working on Windows10 but I have trouble making my Hello World App working.
Here is what I did:
I created a new UWP Blank App in VS2017
In the OnLaunched()
method, I call my Init()
method to initialize Speech Recognition:
void App::Init()
{
speechRecognizer = ref new Windows::Media::SpeechRecognition::SpeechRecognizer(Windows::Media::SpeechRecognition::SpeechRecognizer::SystemSpeechLanguage);
Platform::Collections::Vector<String^>^ speech_command_list = ref new Platform::Collections::Vector<String^>();
speech_command_list->Append(StringReference(L"pause"));
speech_command_list->Append(StringReference(L"play"));
speech_command_list->Append(StringReference(L"download"));
speech_command_list->Append(StringReference(L"test"));
SpeechRecognitionListConstraint^ speech_constraint = ref new SpeechRecognitionListConstraint(speech_command_list);
speechRecognizer->Constraints->Append(speech_constraint);
create_task(speechRecognizer->CompileConstraintsAsync()).then([this](SpeechRecognitionCompilationResult^ compilationResult)
{
if (compilationResult->Status == SpeechRecognitionResultStatus::Success)
{
speechRecognizer->ContinuousRecognitionSession->ResultGenerated += ref new TypedEventHandler<SpeechContinuousRecognitionSession^, SpeechContinuousRecognitionResultGeneratedEventArgs^>(this, &App::OnSpeechRecognized);
speechRecognizer->HypothesisGenerated += ref new TypedEventHandler<Windows::Media::SpeechRecognition::SpeechRecognizer^, SpeechRecognitionHypothesisGeneratedEventArgs^>(this, &App::OnHypothesisGenerated);
speechRecognizer->StateChanged += ref new TypedEventHandler<Windows::Media::SpeechRecognition::SpeechRecognizer^, SpeechRecognizerStateChangedEventArgs^>(this, &App::OnStateChanged);
speechRecognizer->RecognitionQualityDegrading += ref new TypedEventHandler<Windows::Media::SpeechRecognition::SpeechRecognizer^, SpeechRecognitionQualityDegradingEventArgs^>(this, &App::OnQualityIssue);
TimeSpan endSilenceTime;
endSilenceTime.Duration = 12000000L;
speechRecognizer->Timeouts->EndSilenceTimeout = endSilenceTime; // (1.2 seconds in nanoseconds)
speechRecognizer->ContinuousRecognitionSession->StartAsync();
}
else
{
// Handle errors here.
}
});
}
The code compiles, and launches, the compilation of speech constraints is successful, and I break once in the callback OnStateChanged
with a new state value as Idle
And that's it. I do not receive any more callbacks when speaking into my mic.
For the record, my mic is properly plugged, it is the default mic on Windows, and it is functional.
Upvotes: 0
Views: 158
Reputation: 41
I found what was wrong on my application. I post here the answer in case anyone has the same issue.
It turns out that this type of UWP applications comes embedded with a file called Package.appxmanifest, that holds some settings of the application.
This manifest file has a "Capabilities" section, on which I had to turn on "Internet (client)" and "Microphone" capabilities.
After recompilation, everything was working fine.
Upvotes: 1