c# - 听写语法与自定义语法

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

我正在编写以下代码

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);
            }


        }
    }
}

在这里,语法是我饿了,但计算机被要求说我饿了。但实际情况是,识别事件被触发,并表示文本完全等于我饿了。在输出框中,您还可以检查音素!

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

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

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

最佳答案

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

听写语法不是这样的,它只是尝试匹配计算机理解的内容,而不是用户确切所说的内容。

可以通过训练语音引擎来最大限度地减少这种情况。

关于c# - 听写语法与自定义语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16809031/

相关文章:

c# - 使用关联的应用程序打开所选文件

visual-studio-2010 - Visual Studio ipch 文件夹

c# - 如何检查或验证文本框输入的日期是否为 DD/MM/YYYY 格式?

c# - 图像 PropertyItems 和处置的 MemoryStream

c# - 如果没有这样的键,我如何更改 Dictionary 以便它返回自定义默认值而不是抛出异常?

c# - LINQ to SQL 表达式 "Orderby"帮助

c# - 如何使用 C# 连接到 Redis 服务器?

c# - 将 Microsoft.AspNet.Identity.EntityFramework.3.0.0-rc1-final 安装到类库中

c# - 代码中的表格布局被认为是错误的原因是什么?

visual-studio-2010 - Visual Studio 2010 不需要的 dll 依赖项