How can I use ARPA files with MS Speech? The documentation for the Microsoft Speech Platform 11 Recognizer implies that one can compile a grammar from an ARPA file.
I am able to compile an ARPA file -- for instance, the tiny example provided by Microsoft -- using the following command line:
CompileGrammar.exe -In stock.arpa -InFormat ARPA
I'm able to use the resulting CFG file in the following test:
using Microsoft.Speech.Recognition;
// ...
using (var engine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
engine.LoadGrammar(new Grammar("stock.cfg"));
var result = engine.EmulateRecognize("will stock go up");
Assert.That(result, Is.Not.Null);
}
This test passes, but note that it uses EmulateRecognize()
. When I switch to using an actual audio file, like this:
using (var engine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
engine.LoadGrammar(new Grammar("stock.cfg"));
engine.SetInputToWaveFile("go-up.wav");
var result = engine.Recognize();
}
result is always null and the test fails.
Microsoft states quite clearly that it's supported, yet even very simple examples don't seem to work. What am I doing wrong?
There are two different answers to this question depending on which version of the Microsoft Speech SDK you're using. (See: What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition? )
System.Speech (Desktop Version)
In this case, see seiya1223's answer. The sample code there works great.
Microsoft.Speech (Server Version)
Perhaps because the server version does not include the "dictation engine," the Microsoft.Speech library will apparently never match an ARPA-sourced CFG. However, it will still hypothesize what was said via the
SpeechRecognitionRejected
event. Here are the necessary changes from seiya1223's desktop code:SpeechRecognitionRejected
event.e.Result.Text
property for the final hypothesis.The following snippet should help illustrate:
This handler is called once at the end of recognition. For example, here is the output from seiya1223's code, but using all of the available event handlers and a bunch of extra logging (emphasis mine):