2012-02-13 14 views
1

新しいmicrosoft.speech APIを使用するプログラムを構築しています。私が最初にプログラムを始めるとき、私はSpeechRecognizerを文法で読み込み、すべてがうまくいきます。ただし、Microsoft Async CTPを使用して、文法に追加する単語を取得する作業をしています。新しい文法を読み込みたいときに返します。ベローは、非同期CTP部分である...ここでMicrosoft.Speech.Recognitionで新しい文章を読み込む

class UR 
{ 
    private CancellationTokenSource _cancelationToken; 

    public UR() 
    { 
     _cancelationToken = new CancellationTokenSource(); 
    } 

    public async void StartRecognition() 
    { 
     String someword = await Recognize(_cancelationToken.Token); 
     //Load the new grammar 
     SpeechRecognizer sr = SpeechRecognizer.Instance; 
     sr.LoadNewGrammar(someword); 
    } 
} 

がLoadNewGrammar方法で、新しい文法をロードするために、あなたは文法をロードし、その後、私は認識エンジンを停止する「RecognizeAsyncCancel」を使用しようとしていますことがわかりますユーザー "RecognizeAsync"を使用して認識プログラムを再起動します。

public void LoadNewGrammar(String someword) 
    { 
     Commands = new Dictionary<string, WhatSaid>() 
     { 
      {"DoThis",   new WhatSaid()  {verb=Verbs.DoThis}}, 
      {"DoThat",   new WhatSaid()  {verb=Verbs.DoThat}}, 
      {someword,   new WhatSaid()  {verb=Verbs.Someword}} 
     }; 

     if (sre == null) 
     { 
      RecognizerInfo ri = GetKinectRecognizer(); 
      sre = new SpeechRecognitionEngine(ri); 
     } 
     //Stop the speech recognizer temporarily in order to load the new grammar 
     sre.RecognizeAsyncCancel(); 

     // Build a grammar of commands 
     var basicCmds = new Choices(); 
     foreach (var phrase in Commands) 
     { 
      basicCmds.Add(phrase.Key); 
     } 

     // Combine all choices 
     var allChoices = new Choices(); 
     allChoices.Add(basicCmds); 

     //Create a grammar builder to be used in the grammar object 
     var gb = new GrammarBuilder(); 
     gb.Culture = sre.RecognizerInfo.Culture; 
     gb.Append(allChoices); 

     var g = new Grammar(gb); 
     sre.LoadGrammar(g); 
     sre.RecognizeAsync(RecognizeMode.Multiple); 
    } 

問題は、私はsre.RecognizeAsyncCancelを呼び出すときに私のプログラムが完全にフリーズすることのようです。私は同じ結果でRecognizeAsyncStopも試みました。私はここでスレッドの問題を抱えていますが、これを修正するためにどこから始めるべきかわからないので、気持ちがあります。

答えて

関連する問題