我非常喜欢Microsofts最新的语音识别(和SpeechSynthesis)产品。
http://msdn.microsoft.com/en-us/library/ms554855.aspx
http://estellasays.blogspot.com/2009/04/speech-recognition-in-cnet.html
然而,我觉得我在使用语法时有点受限。
不要误解我的意思,语法很好地告诉语音识别应该注意哪些单词/短语,但是如果我想让它识别一些我还没有给它提示的东西呢?或者我想解析一个短语,它是一半预先确定的命令名,另一半是随机词?
例如..。
场景A -我说的“谷歌漏油”,我希望它打开谷歌搜索结果的括号内,这可能是任何东西。
场景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);
}发布于 2010-07-29 23:16:21
你可以试试这样的..。它指定了一个已知命令的列表。还可以让你事后使用开放式听写。它希望在公开听写之前有一个命令。但你可以逆转这个..。但是,通过在命令类型(“")中添加一个空白,还可以直接进入听写部分。
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-06-15 17:08:15
你有两个选择:
https://stackoverflow.com/questions/3046921
复制相似问题