2

我正在构建一个可以识别来自用户的多个单词的应用程序;从而使用识别的单词组合一个句子。

这是我现在所拥有的:

namespace SentenceRecognitionFramework__v1_
{
    public partial class Form1 : Form
    {

        SpeechRecognitionEngine recog = new SpeechRecognitionEngine();
        SpeechSynthesizer sp = new SpeechSynthesizer();

        public Form1()
        {
            InitializeComponent();
        }

        private void btnListen_Click(object sender, EventArgs e)
        {
            Choices sList = new Choices();
            sList.Add(new String[] { "what","is", "a", "car" });

            Grammar gr = new Grammar(new GrammarBuilder(sList));

            recog.RequestRecognizerUpdate();
            recog.LoadGrammar(gr);
            recog.SpeechRecognized += sRecognize_SpeechRecognized;
            recog.SetInputToDefaultAudioDevice();
            recog.RecognizeAsync(RecognizeMode.Multiple);
            recog.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected;
        }

        private void sRecognize_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            sentenceBox.Text = "Sorry, I couldn't recognize";
        }

        private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            sentenceBox.Text = e.Result.Text.ToString();
        }
    }
}

但是,此代码一次只能识别一个单词。即使我编辑我的代码来做到这一点:

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            sentenceBox.Text = sentenceBox.Text + " " + e.Result.Text.ToString();
        }

当我连续说出“什么是汽车”这个词时,应用程序无法连续识别单词,而当我说出它们时没有中断。

为了让程序识别使用这些定义的单词构建的整个句子,我可以进行哪些更改,而不必在说出句子时出现语音中断?

需要输出:

我说出一句话:什么是汽车

应用展示:什么是汽车

完美示例:谷歌语音识别谷歌使用其词库中可用的单词开发一个句子

非常感谢你 :)

4

2 回答 2

4

它可以识别一个单词,因为您错误地构建了语法。由于您构建了由选择“what”、“is”、“a”、“car”其中一个词组成的语法,因此它可以准确识别其中一个词。

您可能想阅读语法和相关文档的介绍。

http://msdn.microsoft.com/en-us/library/hh378438(v=office.14).aspx

如果你想构建描述短语的语法,你可以像这样使用 GrammarBuilder:

  Grammar gr = new Grammar(new GrammarBuilder("what is a car"));

该语法将识别一个短语。

要了解 Choices 的工作原理,您可以阅读有关 Choices 的文档:

http://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.choices(v=office.14).aspx

于 2014-10-03T14:31:04.060 回答
3

这个答案可能有点晚了,但我还没有找到任何其他地方对这个问题有实际的答案。因此,为了节省其他人的时间和挫折感,我就是这样做的。

using System;
using System.Threading;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;

namespace SpeachTest
{
public class GrammerTest
{
        static void Main()
        {
        Choices choiceList = new Choices();
        choiceList.Add(new string[]{"what", "is", "a", "car", "are", "you", "robot"} );

        GrammarBuilder builder = new GrammarBuilder();
        builder.Append(choiceList);
        Grammar grammar = new Grammar(new GrammarBuilder(builder, 0, 4) );   //Will recognize a minimum of 0 choices, and a maximum of 4 choices

            SpeechRecognizer speechReco = new SpeechRecognizer();
            speechReco.LoadGrammar(grammar);



        }
}
}

这里的关键是这条线

新的 GrammarBuilder(builder, 0, 4)

这告诉语音识别器识别最多 4 次重复的元素 form builder,并且最少为 0。

所以它现在会识别

"what is a car"

如果您想要超过 4 次重复,只需更改new GrammarBuilder(builder, 0, 4)

new GrammarBuilder(builder, 0 "the number of repetitions you want")

有关更多信息,请参阅此 GrammarBuilder(builder, minRepeat, maxRepeat)

于 2015-02-11T23:07:26.087 回答