我真的很喜欢微软最新的语音识别(和 SpeechSynthesis)产品。

http://msdn.microsoft.com/en-us/library/ms554855.aspx

http://estellasays.blogspot.com/2009/04/speech-recognition-in-cnet.html

然而我觉得我在使用语法时受到了一些限制。

不要误会我的意思,语法非常适合告诉语音识别到底要注意哪些单词/短语,但是如果我希望它识别一些我没有提醒它的东西怎么办?或者我想解析一个由一半预先确定的命令名称和一半随机单词组成的短语?

例如..

场景A - 我说“Google [石油泄漏]”,我希望它打开 Google,并显示括号中的术语的搜索结果,该术语可以是任何内容。

场景B - 我说“找到[曼彻斯特]”,我希望它在谷歌地图中搜索曼彻斯特或任何其他非预先确定的内容

我想让它知道“Google”和“Locate”是命令,后面的内容是参数(可以是任何东西)。

问题 :有谁知道如何混合使用预定语法(语音识别应该识别的单词)和不在预定语法中的单词?

代码片段..

using System.Speech.Recognition;

...
...

SpeechRecognizer rec = new SpeechRecognizer();
rec.SpeechRecognized += rec_SpeechRecognized;

var c = new Choices();
c.Add("search");

var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true; 

...
...

void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text == "search")
    {
        string query = "How can I get a word not defined in Grammar recognised and passed into here!";

        launchGoogle(query);
    }
}

...
...


private void launchGoogle(string term)
{
    Process.Start("IEXPLORE", "google.com?q=" + term);
}
有帮助吗?

解决方案

您可以尝试这样的事情... 它指定已知命令的列表。但是,您还可以使用开放听写之后。 该公司预计那里是开放的听写前给出的命令..但你可以改变这种...并追加日 然而,通过在命令类型(”“)将在一个空白的它也将让你直奔听写部分。

Choices commandtype = new Choices();
commandtype.Add("search");
commandtype.Add("print");
commandtype.Add("open");
commandtype.Add("locate");

SemanticResultKey srkComtype = new SemanticResultKey("comtype",commandtype.ToGrammarBuilder());

 GrammarBuilder gb = new GrammarBuilder();
 gb.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
 gb.Append(srkComtype);
 gb.AppendDictation();

 Grammar gr = new Grammar(gb);

然后在你的识别仅仅使用结果文本等

private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    System.Console.WriteLine(e.Result.Text);

}

您可以添加更多的选择方案,并SemanticResultKeys的结构,如果你希望做更复杂的模式。还一个通配符(例如gb.AppendWildcard())。

其他提示

你有两个选择:

  1. 您可以使用听写节点进行自由文本 GrammarBuilder::追加听写. 。问题在于,由于识别器没有任何上下文,因此识别质量不是最高的。
  2. 您可以使用文本缓冲区节点并使用提供一组项目 GrammarBuilder::Append(字符串, SubsetMatchingMode). 。这将为识别器提供足够的上下文来获得高质量的识别,而不必每次都重建整个语法树。
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top