I am creating a speech recognition Engine that's going to respond to user Commands.I have created a Button to enable and disable Speech recognition as per user convenience.I have used Dispose() of Speech engine to disable speech recoginition.here is the code
private void button1_Click(object sender, RoutedEventArgs e)
{
engineOn = !engineOn;
if (engineOn)
{
speechEngine = speech.createSpeechEngine(); //speech is a class that creates and returns a new speech engine.
speechEngine.AudioLevelUpdated += new EventHandler<AudioLevelUpdatedEventArgs>(speechEngine_AudioLevelUpdated);
// use the system's default microphone
speechEngine.SetInputToDefaultAudioDevice();
speechEngine.LoadGrammar(new DictationGrammar());
// start listening
speechEngine.RecognizeAsync(RecognizeMode.Multiple);
}
else
{
SpeechClass.myEngine.Dispose();
}
}
But Disposal of speech object takes time.How to do that asynchronously? is is there any other way to turn Speech recognition on and off? thanks in advance.