mardi 10 mars 2015

InvalidOperationException in System.speech (Simple speech dictation program)

The first time I start my program, it worked fine for the first two words I spoke before it stopped inputting text. The Exception error is shown on:


recognitionEngine.RecognizeAsync(RecognizeMode.Multiple)


" Cannot perform this operation while the recognizer is doing recognition."


Now, anytime I start my program it does not type anything I say, and I've no idea where to find the problem. the following is the rest of the code in the program, in case I've overlooked an Error.



public partial class Form1 : Form
{
private SpeechRecognitionEngine recognitionEngine;
public Form1()
{
InitializeComponent();

recognitionEngine = new SpeechRecognitionEngine();
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.SpeechRecognized += (s, args) =>
{
foreach (RecognizedWordUnit word in args.Result.Words)
{
if (word.Confidence > 0.8f)
richTextBox1.Text += word.Text + " ";
}
richTextBox1.Text += Environment.NewLine;
};
recognitionEngine.LoadGrammar(new DictationGrammar());
}

private void button1_Click(object sender, EventArgs e)
{
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
}

private void button2_Click(object sender, EventArgs e)
{
recognitionEngine.RecognizeAsyncStop();
}
}

Aucun commentaire:

Enregistrer un commentaire