none
How to end SpeechRecognition correctly (with SDKbeta refresh)? RRS feed

  • Question

  • Hi,

    for my project I need permanent speech recognition. Therefore I have the following code, but on WindowClosed the nui isn't closed correctly (with the new SDKbeta refresh) and the ir-sensor is still in progress. Sometimes the speechanalysis works after closing the window. Could anybody tell me how to end speechrecognition in a correct way?

    bool readContinue = true;
    
    public void WindowLoaded(object sender, RoutedEventArgs e)
    {
    nui = new Runtime();
    nui.Initialize(...);
    StartSpeechRecognition();
    ...
    }
    
    public void WindowClosed(object sender, EventArgs e)
    {
    readContinue = false;
    nui.Uninitialize();
    }
    
    
    private void StartSpeechRecognition()
    {
    var thread = new Thread(new ThreadStart(RecognizeAudio));
    thread.SetApartmentState(ApartmentState.MTA);
    thread.Start();
    }
    
    private void RecognizeAudio()
    {
    ...
    while (readContinue)
    {
    sre.Recognize();
    }
    }
    


    Tuesday, August 30, 2011 11:07 AM

Answers

  • geogekuna,

    The Runtime.Initialize/Uninitialize methods only control the Kinect video streams, not the audio functionality. The audio functionality is controlled via the KinectAudioSource object. I don't see your initialization of KinectAudioSource, but I'm guessing it's somewhere in your RecognizeAudio thread?

    Look at Recognizer.StartDMO and Recognizer.Stop methods in Recognizer.cs in C:\Users\Public\Documents\Microsoft Research KinectSDK Samples\NUI\ShapeGame\CS sample.

    Besides the code that looks like

    if (sre != null)
    {
      sre.RecognizeAsyncCancel();
      sre.RecognizeAsyncStop();
      kinectSource.Dispose();
    }

    You probably should have your WindowClosed function call "Thread.Stop"

    Eddy


    I'm here to help
    Tuesday, August 30, 2011 9:23 PM

All replies

  • geogekuna,

    The Runtime.Initialize/Uninitialize methods only control the Kinect video streams, not the audio functionality. The audio functionality is controlled via the KinectAudioSource object. I don't see your initialization of KinectAudioSource, but I'm guessing it's somewhere in your RecognizeAudio thread?

    Look at Recognizer.StartDMO and Recognizer.Stop methods in Recognizer.cs in C:\Users\Public\Documents\Microsoft Research KinectSDK Samples\NUI\ShapeGame\CS sample.

    Besides the code that looks like

    if (sre != null)
    {
      sre.RecognizeAsyncCancel();
      sre.RecognizeAsyncStop();
      kinectSource.Dispose();
    }

    You probably should have your WindowClosed function call "Thread.Stop"

    Eddy


    I'm here to help
    Tuesday, August 30, 2011 9:23 PM
  • thanks eddy, that helps!
    Wednesday, August 31, 2011 7:11 AM