0

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.

gaurav9021
  • 65
  • 2
  • 8
  • Have you looked at RecognizeAsyncStop method? http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.recognizeasyncstop.aspx – Suresh Apr 14 '13 at 20:37

1 Answers1

0

You just use RecogniseAsync / RecogniseAsyncStop to turn it off and on again:

http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.aspx

Alternatively, you could try loading an empty grammar list so essentially the kinect has nothing to listen out for.

Additionally, I'd avoid disposing the object altogether unless you no longer want to use (e.g. When the application is shutting down). There are major overheads associated with the disposing of the object (particularly the speechrecognitionengine), then recreating it again.

Lojko
  • 173
  • 1
  • 13