Reputation: 203
I'm creating a smart mirror application using UWP, I try to integrate the application with continuous speech recognition, so users can use voice to control it. But Bing Speech REST API doesn't support continuous speech recognition, so anything else can I use? if you have source code, it would be better.
Upvotes: 1
Views: 585
Reputation: 203
I find some ideas from this code, I hope it also can help you.
public sealed partial class MainPage : Page
{ public MainPage()
{
this.InitializeComponent();
}
//連続音声認識のためのオブジェクト
private SpeechRecognizer contSpeechRecognizer;
private CoreDispatcher dispatcher;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
//ハックグラウンドスレッドからUIスレッドを呼び出すためのDispatcher
dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
//初期化
contSpeechRecognizer =
new Windows.Media.SpeechRecognition.SpeechRecognizer();
await contSpeechRecognizer.CompileConstraintsAsync();
//認識中の処理定義
contSpeechRecognizer.HypothesisGenerated +=
ContSpeechRecognizer_HypothesisGenerated;
contSpeechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
ContinuousRecognitionSession_ResultGenerated;
// 音声入力ないままタイムアウト(20秒位)した場合の処理
contSpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
//認識開始
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContinuousRecognitionSession_Completed(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args)
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = "Timeout.";
});
// 音声を再度待ち受け
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContSpeechRecognizer_HypothesisGenerated(
SpeechRecognizer sender, SpeechRecognitionHypothesisGeneratedEventArgs args)
{
//認識途中に画面表示
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = args.Hypothesis.Text;
});
}
private async void ContinuousRecognitionSession_ResultGenerated(
SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
//認識完了後に画面に表示
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = "Waiting ...";
output.Text += args.Result.Text + "。\n";
});
}
}
Upvotes: 2
Reputation: 4576
The Windows.Media.SpeechRecognition
supports Continuous Recognition. The Microsoft Github for UWP has an example of this in their Speech recognition and synthesis sample or check out the Microsoft Docs for Windows.Media.SpeechRecognition
Upvotes: 0