0

I am currently developing a Voice Recognition Application. For this I have the requirement of allowing the users to spell letters of a particular word, such as for example a name. I tried to add the alphabet as choices using a grammarbuilder, but it only recognizes one particular Letter.

Following is my code

    public static class GrammarManager{
            public static GrammarBuilder getAlphabet()
            {
                Settings.CultureInfo = "en-GB";

                GrammarBuilder dictaphoneGB = new GrammarBuilder();
                dictaphoneGB.Culture = new System.Globalization.CultureInfo(Settings.CultureInfo);
                dictaphoneGB.Append(new Choices("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"));

                return dictaphoneGB;
            }
    }

public class SpeechEngine{
        static System.Speech.Recognition.SpeechRecognitionEngine recognizer = null;
        private void initializeEmulator()
        {
            GrammarBuilder builder = new GrammarBuilder();
            builder.AppendDictation();

            recognizer = new System.Speech.Recognition.SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-GB"));
            recognizer.RequestRecognizerUpdate();
            recognizer.LoadGrammar(new Grammar(GrammarManager.getAlphabet()));
            recognizer.SpeechRecognized += recognizer_SpeechRecognized;
        }

        public void startEmulatorRecognition(string word)
        {
            recognizer.EmulateRecognizeAsync(word);
        }
}

I am invoking the startEmulateRecognition() method by starting a particular string parametr. Now when I pass values like "A", "G", or "B" to that particular method, it's getting recognized. But when I pass "A B C" or "ABC" or words such as "G O O G L E", they are not being recognized.

I would really appreciate if someone can suggest me a method to achieve this, to allow recognizing words that are being spelled such as "G O O G L E" etc.?

Thanks in advance!

4

1 回答 1

0

您需要使用另一个 GrammarBuilder 和重复构造函数来构造匹配重复序列的语法:

private void lettterGrammar() {
    GrammarBuilder letterGb = new GrammarBuilder();
    Choices letterChoices = new Choices("A", "B", "C", "D);
    GrammarBuilder speellingGb = new GrammarBuilder(
                 (GrammarBuilder)letterChoices, 1, 50);
    Grammar grammar = new Grammar(spellingGb);
}

有关详细信息,请参阅MSDN 上的文档

于 2013-06-13T16:38:11.893 回答