【问题标题】:Dictation grammar vs custom grammar听写语法与自定义语法
【发布时间】:2013-05-29 08:32:40
【问题描述】:

我正在编写以下代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
using System.IO;

namespace US_Speech_Recognizer
{
    public class RecognizeSpeech
    {
        private SpeechRecognitionEngine sEngine; //Speech recognition engine
        private SpeechSynthesizer sSpeak; //Speech synthesizer
        string text3 = "";

        public RecognizeSpeech()
        {
            //Make the recognizer ready
            sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));


            //Load grammar
            Choices sentences = new Choices();
            sentences.Add(new string[] { "I am hungry" });

            GrammarBuilder gBuilder = new GrammarBuilder(sentences);

            Grammar g = new Grammar(gBuilder);

            sEngine.LoadGrammar(g);

            //Add a handler
            sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);


            sSpeak = new SpeechSynthesizer();
            sSpeak.Rate = -2;



            //Computer speaks the words to get the phones
            Stream stream = new MemoryStream();
            sSpeak.SetOutputToWaveStream(stream);


            sSpeak.Speak("I was hungry");
            stream.Position = 0;
            sSpeak.SetOutputToNull();


            //Configure the recognizer to stream
            sEngine.SetInputToWaveStream(stream);

            sEngine.RecognizeAsync(RecognizeMode.Single);


        }


        //Start the speech recognition task
        private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string text = "";

            if (e.Result.Text == "I am hungry")
            {
                foreach (RecognizedWordUnit wordUnit in e.Result.Words)
                {
                    text = text + wordUnit.Pronunciation + "\n";
                }

                MessageBox.Show(e.Result.Text + "\n" + text);
            }


        }
    }
}

在这里,语法是I am hungry,但要求计算机说出I was hungry。但情况是,识别事件被触发并说文本完全等于I am hungry。在输出框中,您也可以查看音素!

避免这种情况的唯一方法是加载DictationGrammar

我认为提供自定义语法是限制应用程序监听不需要的所有内容的最佳方式,但似乎自定义语法失败了!

我的问题是,有没有办法避免这种情况?为什么会这样?

【问题讨论】:

    标签: c# .net visual-studio-2010 text-to-speech voice-recognition


    【解决方案1】:

    我找到了答案。 Custom Grammar 将通过给引擎施加很大压力来过滤用户的发音,以使用提供的有限语法来识别用户的声音。

    Dictation grammar 不是这样的,它只会尝试匹配 WHAT COMPUTER UNDERSTOOD 而不是用户准确地说的内容。

    这可以通过训练语音引擎来最小化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 2011-03-29
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多