Share via


Problems with SpeechRecognitionEngine [Speech Recognition]

Question

Friday, October 16, 2015 4:04 PM

I want to program an app for my Raspberry Pi IoT (I am actually doing it in a class library for now) with integrated speech recognition (using System.Speech.Recognition), however as I bought my PC in Germany I have problems with the SpeechRecognitionEngine in Visual Studio.

"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Speech.dll

Additional information: The language for the grammar does not match the language of the speech recognizer." - Me trying to load the grammar into the engine.

__________________________________________________________

EDIT 1:

I did some testing and if I initialize the engine with 'new CultureInfo("en-US") I get this error:

"An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll

Additional information: The type initializer for 'CSR_COM.Test' threw an exception."

But if I initialize the engine after creating it, I get this error:

"An unhandled exception of type 'System.ArgumentException' occurred in System.Speech.dll

Additional information: No recognizer of the required ID found."

__________________________________________________________

It seems as if my PC only supports german speech recognition (recognitionEngine.RecognizerInfo.Culture = "de-De"), but how do I change this to english or should I even consider to Microsofts SAPI (I tried that too, however my download and installation seems buggy)?

__________________________________________________________

Edit 2:

I installed the Speech Platform Runtime and some language engines, but the Edit 1 error still exists.

(Please note that de-DE, zh-CN, en-US, ja-JP, en-US are installed ( SpeechRecognitionEngine.InstalledRecognizers() )

__________________________________________________________

My code:

        static SpeechRecognitionEngine recEngine;

        static void Main()
        {
            recEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")); // Exception (Edit 1)
            TestRecognition();
            Console.ReadKey();
        }

        static void TestRecognition()
        {
            Choices commands = new Choices();
            commands.Add(new string[] { "moove", /*...*/ "CSR" });
            GrammarBuilder gb = new GrammarBuilder();
            gb.Culture = new CultureInfo("en-US");
            gb.Append(commands);
            Grammar gr = new Grammar(gb);
            recEngine.LoadGrammar(gr);
            recEngine.SetInputToDefaultAudioDevice();
            recEngine.SpeechRecognized += RecEngine_SpeechRecognized;
            recEngine.RecognizeAsync(RecognizeMode.Multiple);
        }

        private static void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            // TODO
        }

All replies (5)

Monday, October 19, 2015 4:19 AM âś…Answered

Now that I gave this some thought, you might be better off using one of the online Speech recognition to do this job. Check out these links for some ideas on how to use the Bing Azure Speech recognition and translator. This is free for up to 500,000 transactions a MONTH!, see these links for more information, I am definitely going to use it set up a Halloween surprise that uses the Klingon translation tool!  Hope this help out, please mark as answered if you found this interesting.

Sam Stokes


Friday, October 16, 2015 6:28 PM

Hi Phrosten!

It may be your microphone set-up, check for this line in your app manifest:

Sam Stokes


Saturday, October 17, 2015 8:29 AM

Thank you for your fast answer (and sorry for my late response)!

Sorry for not mentioning, but I am programming in a class library for the project, so there is no app manifest. For actual checking I am setting the output to a ConsoleProgram for now.

I tried setting the thread-culture to "en-US" but it didn't change anything.

I think the main problem is that this PC doesn't have the SpeechRecognitionEngine for the language "English", so I am trying to install the engine for the English language on a German Windows 10 OS (which is running completely in English).


Saturday, October 17, 2015 10:16 AM | 1 vote

First you need the main Speech Platform Runtime. That thing is really just a handy set of wrapper classes around the complex guess-science that is speech recognition.
https://www.microsoft.com/en-us/download/details.aspx?id=27225

Then you need the engine for each specific language. That is all the language sciency stuff needed to understand speech, designed to fit nicely into the Runtime classes:
https://msdn.microsoft.com/en-us/library/hh478476.aspx
Here you are stuck with what you got. You can't just write one your own, way beyond the area of programmers

Both (Runtime and fitting Langauge Engine) need to be installed on the machine running your application as well. They become standing requirements like the .NET Framework itself.

Thirdly, accept that Speech to Text is still terrible. It is a mess of guesswork and higher science without any clear formula and even 95% hit-ratio is considered very good.
Having a very limited gramar to choose from might be more reliable then totally free recognition (higher tollerancies possible).

"Additional information: The language for the grammar does not match the language of the speech recognizer."
Each speech engine is two parts:
The actuall engine that tries to make sense of sounds (https://en.wikipedia.org/wiki/Pitch_detection_algorithm)
A "grammar" a simple collection of strings the received stuff is compared against.
Basically the engine just itterates over the grammar collection, trying to to match those identified sounds/letters to the strings. What get's the highest propability of match is returned.


Saturday, October 17, 2015 11:23 AM

I installed the Speech Platform Runtime and some language runtime engines.

The following code

List<RecognizerInfo> engines = SpeechRecognitionEngine.InstalledRecognizers().ToList();

for(int i = 0; i < engines.Count; i++)
{
    Console.WriteLine(engines[i].Culture);
}

produces the following output:

"de-DE
zh-CN
en-US
ja-JP
en-US"

But the "Edit 1" Error still happens.