2017-07-10 133 views
1

我正在創建一個使用UWP的智能鏡像應用程序,我嘗試將應用程序與持續語音識別進行集成,以便用戶可以使用語音來控制它。但是Bing Speech REST API不支持連續的語音識別,所以我可以使用其他任何功能?如果你有源代碼,那會更好。連續語音識別UWP

回答

1

我從這段代碼中找到了一些想法,我希望它也能幫助你。

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"; 
     }); 
    } 
}