0

我在访问 kinect 的音频流以在我的项目中用于语音控制时遇到问题。到目前为止,我还没有收到音频流的响应。我正在使用安装了最新的 kinect sdk 包的 xna。

我正在使用的代码来自 sdk 中使用 xna 中的语音控制的示例,但在控制台应用程序中。

没有触发任何侦听器事件,我认为这是由于某些原因导致音频流未启动?

任何帮助,将不胜感激。

这段代码在InitializeKinect()我的程序部分:

 // Obtain the KinectAudioSource to do audio capture
        KinectAudioSource source = kinectSensor.AudioSource;
        source.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample
        source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition
        source.Start();
        RecognizerInfo ri = GetKinectRecognizer();

        if (ri == null)
        {
            lol = "Could not find Kinect speech recognizer. Please refer to the sample requirements";
        }

        lol = "Using: {0}"+ ri.Name;

        // NOTE: Need to wait 4 seconds for device to be ready right after initialization

        using (var sre = new SpeechRecognitionEngine(ri.Id))
        {
            var colors = new Choices();
            colors.Add("Kinect");
            colors.Add("test center ");
            colors.Add("left");
            colors.Add("right");
            colors.Add("indirect controls");
            colors.Add("gesture control");
            colors.Add("exit application");

            var gb = new GrammarBuilder { Culture = ri.Culture };

            // Specify the culture to match the recognizer in case we are running in a different culture.                                 
            gb.Append(colors);

            // Create the actual Grammar instance, and then load it into the speech recognizer.
            var g = new Grammar(gb);
            sre.LoadGrammar(g);
            sre.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(sre_SpeechHypothesized);
            sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
            sre.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);

            using (Stream s = source.Start())
            {

                sre.SetInputToAudioStream(
                    s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                sre.RecognizeAsync(RecognizeMode.Multiple);
            }
        }
4

1 回答 1

0

这可能是你的问题。

using (var sre = new SpeechRecognitionEngine(ri.Id))
{
}

using到达块的末尾时,sre关闭。识别是异步的,因此该using块几乎会立即关闭。相反,尝试这样做,看看它是否有效。

var sre = new SpeechRecognitionEngine(ri.Id)
//...

然后sre.Dispose()在更合适的时间打电话。

于 2013-04-23T20:12:16.067 回答