If I declare a new Form
before I call SpeechRecognitionEngine.SetInputToDefaultAudioDevice();
, then the SpeechRecognitionEngine
wont recognize any speech. Why is this.
Here is the code
namespace Test2
{
class Program
{
static void Main()
{
Form form1 = new Form();
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
recognizer.SetInputToDefaultAudioDevice();
recognizer.LoadGrammar(new DictationGrammar() );
recognizer.SpeechDetected += Program.SpeechDetectedEvent;
recognizer.RecognizeAsync();
while(true){}
}
static void SpeechDetectedEvent(Object sender, SpeechDetectedEventArgs e){
Console.WriteLine("Detected Speech");
}
}
}
You'll notice that if you move form1 = new Form();
ahead of SetInputToDefaultAudioDevice
, then the recognizer will detect speech.
My guess/hypothesis is that it has something to do with message loops and threading but my knowledge is to limited to judge.
Aucun commentaire:
Enregistrer un commentaire