0

私はC#で音声を認識するフォームアプリケーションを作成し、ユーザーは "hi"のような単純なコマンドを実行し、コンピュータは "hi there、can私はsometingであなたを助けます "。私はマイクが動作していることを100%確信していますが、プログラムをデバッグすると、マイクからコマンドやオーディオを認識できないようです。私はVisual Studio Community 2015を使用しています。私は不思議に思っていました。コンピュータはフォームを読み込んで私に話しますが、私の声は認識されません。助けていただければ幸いです。ありがとう!System.Speechはデバッグ中に音声を認識しません

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Speech.Synthesis; 
using System.Speech.Recognition; 

namespace VoiceHost 
{ 
    public partial class Form1 : Form 
    { 
     SpeechSynthesizer Host = new SpeechSynthesizer(); 
     Choices services = new Choices(); 

     public Form1() 
     { 


      SpeechRecognitionEngine UserRecog = new SpeechRecognitionEngine(); 

      services.Add(new string[] {"hi"}); 

      Grammar gr = new Grammar(new GrammarBuilder(services)); 
      Say("hello, my name is voice host, how can I help"); 

      try 
      { 
       UserRecog.RequestRecognizerUpdate(); 
       UserRecog.LoadGrammar(gr); 
       UserRecog.SpeechRecognized += UserRecog_SpeechRecognized; 
       UserRecog.SetInputToDefaultAudioDevice(); 
       UserRecog.RecognizeAsync(RecognizeMode.Multiple); 
      } 
      catch { return; } 
     } 
     public void Say(string responseMessage) 
     { 
      Host.Speak(responseMessage); 
     } 

     private void UserRecog_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
     { 
      string userOrder = e.Result.Text; 

      if (userOrder == "hi") 
      { 
       Say("hi there, can I help you with someting"); 
      } 
      InitializeComponent(); 

     } 
     private void Form1_Load(object sender, EventArgs e) 
     { 

     } 
    } 

}

+2

最初に間違っているのは、 'catch {return; } ';エラーを隠し、プログラミングするときにエラーについて知る必要があります。 –

+0

「良い方法は何ですか?」とはどういう意味ですか?例外をキャッチして、それについては何もしないでください。少なくともログに記録してください。 – mason

+3

例外をキャッチし、.MessageとinnerException.Message ..を参照するか、ログに記録するか、表示してください。無視しないでください –

答えて

-3

キャッチ{例外の元} 何が破損した場合、あなたのコードの中であなたが表示されますそのように。

+1

これは有効なコードではありません。 – Logarr

+0

例外を表示、ログ、または処理する必要があります。 –