问题
I use Microsoft Speech Platform to recognize speech at output it on screen. But, i have problem: for example, i have grammar (constructs by GrammarBuilder and Choices - "red","green","black")
When i say- "red green black"- i can get only "red", maybe "red green" , but not "red green black".
Some code:
Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");
// Create a new SpeechRecognitionEngine instance.
_sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("ru-RU"));
_sre.SpeechHypothesized += _sre_SpeechHypothesized;
_sre.SpeechDetected += _sre_SpeechDetected;
//_sre.SetInputToWaveFile(@"c:\Test\Wavs\Wavs-converted\file.wav");
_sre.SetInputToDefaultAudioDevice();
public void LoadGrammarIntoEngine(IEnumerable<String> textColl)
{
Choices choices = new Choices();
GrammarBuilder gb = new GrammarBuilder();
gb.Culture = new CultureInfo("ru-RU");
if (choices != null && textColl != null)
{
choices.Add(textColl.ToArray());
gb.Append(choices);
}
}
public void Recognize() {
if (_sre != null && _sre.Grammars.Count != 0) {
_sre.RecognizeAsync(RecognizeMode.Multiple);
}
}
So, how to fix this problem? Should i make SGRS-grammar with rules? The grammar file is txt file with words like that:
Dictionary.txt
green
black
yellow
red
some other words
回答1:
You can use Append method with repeat:
gb.Append(choices, 1, 10);
来源:https://stackoverflow.com/questions/27879560/microsoft-speech-platform-recognize-word-repetitions