Microsoft Speech Recognition setInputToDefaultAudioDevice throws exception

回眸只為那壹抹淺笑 提交于 2019-12-19 03:39:09

问题


hello guys I'm in trouble in MS Speech recognition.

my code is simple.

static void init()
    {
        string enUsEngine = string.Empty;


        foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
        {
            Console.WriteLine(ri.Culture);
            if (ri.Culture.Name.Equals("en-US") == true)
            {
                enUsEngine = ri.Id;
            }
        }

        SpeechRecognitionEngine recogEngine = new SpeechRecognitionEngine(enUsEngine);

        Grammar grammar = new Grammar("grammar.xml");
        recogEngine.LoadGrammar(grammar);

        recogEngine.SpeechRecognized += recogEngine_SpeechRecognized;
        recogEngine.RecognizeCompleted += recogEngine_RecognizeCompleted;

        recogEngine.SetInputToDefaultAudioDevice();

        recogEngine.RecognizeAsync(RecognizeMode.Multiple);

    }

and then throws InvalidOperationException in call

(System.InvalidOperationException: Cannot find the requested data item, such as a data key or value.)

SetInputToDefaultAudioDevice(); method

I downloaded MSSpeech sdk and installed it (Microsoft.speech.dll). also downloaded language packs. (en-us, ko-kr)

and also My microphone driver installed and enabled in control panel.

please help me.

My operating system is Windows 10 is that a problem for using Speech Recognition api?


回答1:


Most probably you are using Microsoft.Speech.Recognition and you reall should be using System.Speech.Recognition.

Change this:

using Microsoft.Speech.Recognition;

to this:

using System.Speech.Recognition;

You can leave the rest of the code as it is.

Wh? Well here are some answers: What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition?

In short Microsoft.Speech.Recognition is for servers and works with low quality audio like you find in call centres (used for automation etc.), this means it is not compatible with all audio input devices.

On contrary System.Speech.Recognition is for Desktop apps and it fully supports default recording devices installed on Windows.



来源:https://stackoverflow.com/questions/32961817/microsoft-speech-recognition-setinputtodefaultaudiodevice-throws-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!