简体   繁体   中英

Microsoft Speech Recognition setInputToDefaultAudioDevice throws exception

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM