2017-08-07 12 views
0

現在、私はUWPアプリケーションに音声認識機能を実装しようとしていますが、これまではユーザーの音声を認識するための連続口述機能を作成していますが、文法ファイルの文法を作成して追加する方法は?ここ
が連続認識のための私のコードです:あなたの条件についてはuwp音声認識のための文法ファイルを作成して追加する方法

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; 

    }); 
} 

答えて

1

、あなたはcontSpeechRecognizerSRGS fileを追加することができます。そして、私はあなたのセグメントコードの簡単なサンプルベースを作成しています。

contSpeechRecognizerの制約として使用されているファイルは、Colors.grxmlです。より多くの場合

<grammar xml:lang="en-US" 
     root="colors" 
     version="1.0" 
     tag-format="semantics/1.0" 
     xmlns="http://www.w3.org/2001/06/grammar"> 

    <!-- The following rules recognize variants of yes and no. --> 
    <rule id="colors"> 
    <one-of> 
     <item> 
     <one-of> 
      <item>green</item> 
      <item>yellow</item> 
      <item>orange</item> 
      <item>yup</item> 
      <item>un huh</item> 
      <item>yay yus</item> 
     </one-of> 
     <tag>out="yes";</tag> 
     </item> 
     <item> 
     <one-of> 
      <item>no</item> 
      <item>nope</item> 
      <item>nah</item> 
      <item>uh uh</item> 
     </one-of> 
     <tag>out="no";</tag> 
     </item> 
    </one-of> 
    </rule> 
</grammar> 

使用

protected async override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; 
    SpeechRecognizer contSpeechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(); 
    var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Colors.grxml")); 
    var grammarFileConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionGrammarFileConstraint(storageFile, "colors"); 
    contSpeechRecognizer.Constraints.Add(grammarFileConstraint); 
    await contSpeechRecognizer.CompileConstraintsAsync(); 

    contSpeechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.FromSeconds(2); 
    contSpeechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;  
    contSpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed; 

    await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync(); 
} 

Define custom recognition constraintsを参照してください。

関連する問題