c# - 如何为SpeechRecognizer创建自定义词典?

时间:2012-12-02 04:54:40

标签: c# speech-recognition

我使用以下代码创建语音识别器,但我只想识别3件事,即驾驶执照,邮政编码和格式日期

M1234-56789-01234
L9B 2X5
yyyy/mm/dd

我不关心这些字符'/','',' - '。 (因为它们不应包括在识别器识别的文本中)。

我只关心字母和数字。

我创建了一个只有数字和字母的语法,但在谈话时,识别器会创建像'TO'或'THERE'这样的单词。有没有办法限制只识别单个字母和数字?

        SpeechRecognizer sr = new SpeechRecognizer();

        Choices chars = new Choices();
        chars.Add(new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "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" });

        GrammarBuilder gb = new GrammarBuilder();
        gb.Append(chars);

        // Create the Grammar instance.
        Grammar g = new Grammar(gb);

        sr.LoadGrammar(g);

        sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);

0 个答案:

没有答案