none
Speech Recognition in WPF RRS feed

  • Question

  • Hi,

    I've been trying to get speech recognition working with the official SDK... i can get the demo working fine so everything is installed, and i can also get it working when i do a command line application. When i try to put the exact code into a WPF app the recognition doesn't work anymore (no speech is being detected). Is this supported in this release? is there something i have to do? my code is essentially the same as the speech sample that ships with the SDK.

    Thanks in advance!
    Rob 

    Friday, June 17, 2011 11:09 AM

Answers

  • hi

    Be sure to check out the "Sample Shape Game" and the class "Recognizer" there. I use a simplified version of this class for my testing and it worked perfectly well.

    In your command line application you have no problem with threading, which becomes a problem in your WPF application when not handled properly. Check out the above mentioned class. The threading stuff there is pretty neat...

    Frounz

    • Marked as answer by GracelessROB Saturday, June 18, 2011 12:29 AM
    Friday, June 17, 2011 2:42 PM

All replies

  • hi

    Be sure to check out the "Sample Shape Game" and the class "Recognizer" there. I use a simplified version of this class for my testing and it worked perfectly well.

    In your command line application you have no problem with threading, which becomes a problem in your WPF application when not handled properly. Check out the above mentioned class. The threading stuff there is pretty neat...

    Frounz

    • Marked as answer by GracelessROB Saturday, June 18, 2011 12:29 AM
    Friday, June 17, 2011 2:42 PM
  • Awesome! such a simple fix, just had to wrap the audio source creation in a new thread (with lambda syntax it's even neater), and it works great now!

    Thanks so much for your help :)

    Saturday, June 18, 2011 12:32 AM
  • Awesome! such a simple fix, just had to wrap the audio source creation in a new thread (with lambda syntax it's even neater), and it works great now!

    Thanks so much for your help :)

    Can you share how you wrapped the audio source?
    Sunday, June 19, 2011 1:08 AM
  • It's line 215 in the Shape Game's "Recognizer.cs":

    //Be sure to have "using System.Threading;"
    var t = new Thread(StartDMO);
    t.Start();
    


    StartDMO is a void defined in line 238:

    private void StartDMO()
        {
          kinectSource = new KinectAudioSource();
          kinectSource.SystemMode = SystemMode.OptibeamArrayOnly;
          kinectSource.FeatureMode = true;
          kinectSource.AutomaticGainControl = false;
          kinectSource.MicArrayMode = MicArrayMode.MicArrayAdaptiveBeam;
          var kinectStream = kinectSource.Start();
          sre.SetInputToAudioStream(kinectStream, new SpeechAudioFormatInfo(
                             EncodingFormat.Pcm, 16000, 16, 1,
                             32000, 2, null));
          sre.RecognizeAsync(RecognizeMode.Multiple);
        }
    

    Worked for me :)

    Sunday, June 19, 2011 12:34 PM
  • To elaborate just a bit more, what I'm guessing is happening here is problem 1 in the audio FAQ (http://social.msdn.microsoft.com/Forums/en-US/kinectsdkaudioapi/thread/36c8ce4d-b4c4-4585-ac80-becea6753f21):

    1. Problem: COM exception when using KinectAudioSource
    Characteristics: Most commonly seen in Visual Basic as a COM casting error, but can also be seen in multithreaded C# applications.
    Solution: Make sure thread is marked with [MTAThread] attribute and not [STAThread] attribute, since underlying COM object only supports multi-threaded apartments. Note that Visual Basic threads are STA by default and C# threads are MTA by default.

    Speech engine silently catches exceptions like this one, so you unfortunately don't get additional information about what the problem was. For example, try adding [STAThread] annotation to Main method in Program.cs for Speech sample and my guess is that you'll see it failing in the same way as your WPF app was failing for you. I believe that WPF main threads are STA, and the kinect audio component requires MTA.

    Hope this helps,
    Eddy


    I'm here to help
    Monday, June 20, 2011 10:02 PM