currently i try to implement speech recognition function to my UWP app, so far i create a continuous dictation function to recognize user's speech,but i want it just recognize the word or phase that in the grammar file how to create and add grammar for it?
here is my code for continuous recognition:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
SpeechRecognizer contSpeechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer();
await contSpeechRecognizer.CompileConstraintsAsync();
contSpeechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
contSpeechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.FromDays(1);
contSpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContinuousRecognitionSession_Completed(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args)
{
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
speechResult = args.Result.Text;
});
}