System.Speech.SpeechRecognizer works, SpeechRecognitionEngine doesn’t

April 24, 2011 08:53 by docbliny 

I believe I've found an issue with the managed speech recognition libraries. The short problem description is that I am unable to use SRGS/.grxml files that contain "ruleref" elements pointing to other files with System.Speech.Recognition.SpeechRecognitionEngine (InProc). They load fine when using SpeechRecognizer.

After debugging (and finally making a custom build of System.Speech.dll), I've narrowed down on the issue. When you use an InProc recognizer, RecognizerBase.cs sets a custom grammar loader (ISpGrammarResourceLoader). Unfortunately, the RecognizerBase.LoadResource method that is used will receive a null value for the last argument ("pbstrRedirectUrl"), and cause a null exception when it tries to do a split on the null string. This also explains why SpeechRecognizer does not have any issues with the same files.

The same issue happens with both 3.5 and 4.0 versions of the Framework.


I can’t get a speech recognition project I started in 2008 to correctly load the grammar definition files (.grxml / SRGS) in my current environment (Windows 7 64-bit) with SpeechRecognitionEngine.


Well, turns out that the shared SpeechRecognizer will correctly load the exact same GRXML files with external ruleref definitions. After hunting through the .NET source code, the culprit might be in the RecognizerBase.cs method named LoadSapiGrammarFromCfg(). It sets a custom grammar loader for SAPI only when using an InProc recognizer (which SpeechRecognitionEngine is). The comments even state “The rulerefs will be resolved locally.”

So, I have the following options:

  • Continue debugging .NET to see if the behavior has changed, and I’m simply missing some element in the XML file. This doesn’t seem likely, as ProcMonitor clearly states that only the first file even gets a open/read attempt. I’ve tried setting the base URI, used absolute paths, did a quick attempt at loading from a URL. The problem is made worse by the fact that I can’t step through the .NET code in either Visual Studio 2008 or 2010. Fixing that will take its own time… I could try using the .NET Framework code (fingers crossed all the required files are available) directly.
  • Switch to using SpeechRecognizer. I don’t want this, because I’d end up with a broader dictionary which will reduce accuracy.
  • Merge my GRXML files. Yuck. There’s a reason for ruleref support in the files. In addition, the app is meant to be extensible, and having to merge files just makes things harder for the developer and end users.
  • Go down the path of using SpeechLib/SAPI, but looking at the amount of code in the Framework, this seems totally redundant.

Error Info

  • SapiErrorInvalidImport A rule reference to an imported grammar cannot be resolved.
  • 0x80045024
  • -2147200988

Why does System.Speech.Internal.SrgsCompiler.CompileStream() default to “es-us” CultureInfo?

April 23, 2011 09:16 by docbliny 

UPDATE: Nevermind, this is a patch for the "es-us" culture which has the ID 0x540A.

I been trying to track down why I can’t get GRXML files that have ruleref elements pointing to external files working with Windows 7 (64-bit), and ran into the following line of code:

culture = (backend.LangId == 0x540a) ? new CultureInfo("es-us") : new CultureInfo(backend.LangId);

Note the "es-us" locale. Weird. Now back to banging my head against the original problem.

Setting up GWT Development - Quick Start

March 23, 2011 20:21 by docbliny 

The following assumes you’re starting from scratch and need to install the basic software to get going.

  1. Install Eclipse.
    1. Download the appropriate version from . I usually get the Java EE version.
    2. Unzipping this will take a moment. I highly recommend using 7-Zip and making sure you don’t unzip over/on a network drive.
    3. Copy the extracted files to an appropriate place. I drop mine in the Program Files folder.
    4. Create a desktop icon / shortcut for eclipse.exe.
  2. Download and install Java Development Kit JDK.
    1. Download the appropriate version from
    2. This takes even longer.
  3. Start Eclipse and set up the Google Eclipse plug-in. The first time you start Eclipse, it’ll prompt you for a location for the workspace.
    1. Click the Help-menu, and then click Install New Software….
    2. Enter the appropriate plug-in installation path from, and then click Add….
    3. Enter Google Plug-in or similar into the Name field, and then click OK.
    4. Check Plugin and SDKs.
    5. Follow the instructions to finish the wizard.
    6. Restart Eclipse when prompted.