11

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

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

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

但是,我觉得在使用语法时我有些受限。

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

例如..

场景 A - 我说“Google [Oil Spill]”,我希望它打开 Google 的搜索结果,括号中的术语可以是任何内容。

场景 B - 我说“定位 [曼彻斯特]”,我希望它在 Google 地图或其他任何非预先确定的地方搜索曼彻斯特

我想让它知道“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);
}
4

2 回答 2

6

你可以尝试这样的事情......它指定了一个已知命令的列表......但也让你之后使用开放听写。它希望在打开的听写之前给出一个命令..但是您可以将其反转...并附加 th 但是,通过在命令类型(“”)中添加一个空白,它也可以让您直接进入听写部分。

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(); )。

于 2010-07-29T23:16:21.750 回答
4

你有两个选择:

  1. 您可以使用GrammarBuilder::AppendDictation将听写节点用于自由文本。问题是由于识别器没有任何上下文,识别不是最高质量的。
  2. 您可以使用文本缓冲区节点并使用GrammarBuilder::Append(String, SubsetMatchingMode)提供一组项目。这将为识别器提供足够的上下文来获得高质量的识别,而不必每次都重建整个语法树。
于 2010-06-15T17:08:15.753 回答