DCSIMG
How to add words to an already loaded grammar using System.Speech and SAPI 5.3 - .NET Geek

.NET Geek

"It is upon the Trunk that a gentleman works" - Confucius

How to add words to an already loaded grammar using System.Speech and SAPI 5.3

I asked a question on StackOverflow about a week ago. Since I’ve gotten no response there, I thought that I’ll post it here. Maybe someone has a solution. Before I get to the question, a short detour. If you are building custom grammars with the System.Speech API here’s a neat little trick that I found when assembling some complex grammars. If you spell the words in your grammar more like they sound than how they’re really spelled, the recognition engine often gives me better results. Let’s say you want to recognize the word “pun”. If you spell it “punn” in the grammar, the recognition is better. In addition to calibrating the audio settings, some creative rewriting of some words increases the recognition confidence. Especially on short words.

Now to the question:

Given the following sample code,

Choices choices = new Choices();

choices.Add(new GrammarBuilder(new SemanticResultValue("product", "<product/>")));

GrammarBuilder builder = new GrammarBuilder();

builder.Append(new SemanticResultKey("options", choices.ToGrammarBuilder()));

Grammar grammar = new Grammar(builder) { Name = Constants.GrammarNameLanguage };

grammar.Priority = priority;

_recognition.LoadGrammar(grammar);


How can I add additional words to the loaded grammar? I know this can be achieved both in native code and using the SpeechLib interop, but I prefer to use the managed library.

Update: What I want to achieve, is not having to load an entire grammar repeatedly because of individual changes. For small grammars I got good results by calling

_recognition.RequestRecognizerUpdate();


and then doing the unload of the old grammar and loading of a rebuilt grammar in the event:

void Recognition_RecognizerUpdateReached(object sender, RecognizerUpdateReachedEventArgs e)


For large grammars this becomes too expensive.

Update2: It actually works pretty well, and the performance is better than I first thought, but it still bothers me that I can’t add phrases to a loaded grammar. Anyone?

Posted: Dec 07 2008, 03:49 PM by Kim | with no comments
תגים:, , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: