SpeechRecognitionEngine没有开始工作 [英] SpeechRecognitionEngine not getting to work

查看:164
本文介绍了SpeechRecognitionEngine没有开始工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想用SpeechRecognitionEngine编写一个应用程序。演示应用程序SpeechBasics-WPF运行正常(使用语音命令导航乌龟)。

i want to write an application using SpeechRecognitionEngine. The Demo Application SpeechBasics-WPF runs fine (navigating a turtle with voice commands).

所以我尝试将样本中的代码用于我自己的应用程序。以下是我的工作:

So i tried using the code from the sample for my own application. Here is what i do:

        private void InitSpeechRecognition()
        {
            RecognizerInfo ri = GetKinectRecognizer();
            if (ri != null)
            {
                SpeechRecognitionEngine speechEngine = new SpeechRecognitionEngine(ri.Id);

                var directions = new Choices();
                directions.Add(new SemanticResultValue("forward", "FORWARD"));
                directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                directions.Add(new SemanticResultValue("straight", "FORWARD"));
                directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                directions.Add(new SemanticResultValue("back", "BACKWARD"));
                directions.Add(new SemanticResultValue("turn left", "LEFT"));
                directions.Add(new SemanticResultValue("turn right", "RIGHT"));

                var gb = new GrammarBuilder { Culture = ri.Culture };
                gb.Append(directions);

                var g = new Grammar(gb);
                speechEngine.LoadGrammar(g);

                speechEngine.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(speechEngine_SpeechDetected);

                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(),
                    new Microsoft.Speech.AudioFormat.SpeechAudioFormatInfo(Microsoft.Speech.AudioFormat.EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));

                speechEngine.EmulateRecognize("test");

                speechEngine.RecognizeAsync(RecognizeMode.Multiple);

            }
        }

private static RecognizerInfo GetKinectRecognizer()
        {

            System.Collections.ObjectModel.ReadOnlyCollection<RecognizerInfo> recs = SpeechRecognitionEngine.InstalledRecognizers();

            foreach (RecognizerInfo recognizer in recs)
            {
                string value;
                recognizer.AdditionalInfo.TryGetValue("Kinect", out value);
                if ("True".Equals(value, StringComparison.OrdinalIgnoreCase) && "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return recognizer;
                }
            }

            return null;
        }

Everthing似乎初始化正常。  EmulateRecognize("test")会导致SpeechDetected事件。

Everthing seems to initialize fine.  EmulateRecognize("test") causes a SpeechDetected Event.

但任何语音输入都没有事件。

But there is no event on any speech input.

主要是SpeechRecognition正在使用乌龟样本,但不是我的代码......

Principally the SpeechRecognition is working with the turtle sample but not with my code...

我做错了什么?

推荐答案

当我设置

speechEngine .SetInputToDefaultAudioDevice();

speechEngine.SetInputToDefaultAudioDevice();

和不

speechEngine.SetInputToAudioStream(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; sensor.AudioSource.Start(),

&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新SpeechAudioFormatInfo(Microsoft.Speech.AudioFormat.EncodingFormat.Pcm,16000,16, 1,32000,2,null));

speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(),
                    new SpeechAudioFormatInfo(Microsoft.Speech.AudioFormat.EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));

它有效。但是,只有将kinect麦克风设置为默认情况下才能在Windows设置中进行录制。如果我将笔记本麦克风设置为默认声音识别将与我的笔记本麦克风一起使用。我不想设置任何Windows麦克风设置。 I
想要设置用于语音识别的kinect麦克风阵列,但第二行代码不起作用。在上面提到的示例中,它有效......

it works. But only if the kinect microphones are set as default for recording in windows settings. If i set my notebook microphone as default sound recognition will work with my notebook microphone. I don't want to set any windows microphone settings. I want to set the kinect microphone array for speech recognition but the second line of code does not work. In the sample mentioned above it works...

任何提示?


这篇关于SpeechRecognitionEngine没有开始工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆