我试图使用带有自定义语法的SpeechRecognizer来处理以下模式:
“您能打开{item}吗?”其中{item}使用DictationGrammar。
我正在使用内置在Vista和.NET 4.0中的语音引擎。
我希望能够得到SemanticValues的信任返回。见下面的例子。
如果我只使用"recognizer.AddGrammar(新DictationGrammar() )",我就可以浏览e.Results.Alternates并查看每个备选方案的可信度值。如果DictationGrammar位于顶级,这是可行的。
编造的例子:
但是,如果我构建了一个语法,查找“您能打开{semanticValue Key='item‘GrammarBuilder=new DictationGrammar()}吗?”,那么我得到以下内容:
H 121你能不能打开?语义.63 -=nullH 222F 223>
.91向我展示了它对匹配“您能打开{item}”模式有多大的信心?但并没有进一步区分。
但是,如果我接着查看e.Result.Alternates.Semantics.Where( s => s.Key == "item“)并查看他们的信心,我就会得到以下结果:
这对我没多大帮助。
当我看到匹配的SemanticValues的信心时,我真正想要的是这样的东西:
看起来应该是这样的..。
,我是不是做错什么了?在语音框架内甚至有办法做到这一点吗?
我希望有一些内置的机制,这样我就可以用“正确”的方式去做了。
至于另一种可能有效的方法..。
RecognitionResult.GetAudioForWordRange)
)
..。但这比我真正想做的要多。
发布于 2011-03-24 12:43:34
我认为听写语法只做转录。它对文本进行语音处理,而不提取语义意义,因为根据定义,听写语法支持所有单词,并且没有任何关于特定语义映射的线索。您需要使用自定义语法来提取语义。如果提供SRGS语法,或在代码中或使用SpeechServer工具构建语法,则可以为某些单词和短语指定语义映射。然后,识别器可以提取语义意义,并给你一个语义的信心。
您应该能够在识别时从识别器获得信任值,请尝试System.Speech.Recognition.RecognitionResult.Confidence.。
Microsoft语音平台10.2SDK附带的帮助文件有更多详细信息。(这是服务器应用程序的Microsoft.Speech API,非常类似于客户端应用程序的System.Speech API )参见(http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4.)或http://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.semanticvalue(v=office.13).aspx上的Microsoft.Speech文档
对于SemanticValue类,它说:
全语音平台识别引擎输出为所有识别输出提供了有效的SemanticValue实例,甚至没有明确的语义结构的短语。
短语的SemanticValue实例是使用RecognizedPhrase对象(或继承它的对象,如RecognitionResult)上的语义属性获得的。
对于没有语义结构的可识别短语SemanticValue对象,的特点是:
没有孩子(计数为0)
Value属性为空。
人工置信水平为1.0 (由置信度返回)
通常情况下,应用程序间接地创建SemanticValue实例,通过使用SemanticResultValue和SemanticResultKey实例以及选择和GrammarBuilder对象将它们添加到语法对象中。
在创建强类型语法时,直接构造SemanticValue非常有用。
当您在语法中使用SemanticValue特性时,您通常试图将不同的短语映射到单个意义上。在您的例子中,短语"I.E“或”“应该映射到相同的语义意义。您可以在语法中设置选项,以理解每个可以映射到特定意义的短语。下面是一个简单的Winform示例:
private void btnTest_Click(object sender, EventArgs e)
{
SpeechRecognitionEngine myRecognizer = new SpeechRecognitionEngine();
Grammar testGrammar = CreateTestGrammar();
myRecognizer.LoadGrammar(testGrammar);
// use microphone
try
{
myRecognizer.SetInputToDefaultAudioDevice();
WriteTextOuput("");
RecognitionResult result = myRecognizer.Recognize();
string item = null;
float confidence = 0.0F;
if (result.Semantics.ContainsKey("item"))
{
item = result.Semantics["item"].Value.ToString();
confidence = result.Semantics["item"].Confidence;
WriteTextOuput(String.Format("Item is '{0}' with confidence {1}.", item, confidence));
}
}
catch (InvalidOperationException exception)
{
WriteTextOuput(String.Format("Could not recognize input from default aduio device. Is a microphone or sound card available?\r\n{0} - {1}.", exception.Source, exception.Message));
myRecognizer.UnloadAllGrammars();
}
}
private Grammar CreateTestGrammar()
{
// item
Choices item = new Choices();
SemanticResultValue itemSRV;
itemSRV = new SemanticResultValue("I E", "explorer");
item.Add(itemSRV);
itemSRV = new SemanticResultValue("explorer", "explorer");
item.Add(itemSRV);
itemSRV = new SemanticResultValue("firefox", "firefox");
item.Add(itemSRV);
itemSRV = new SemanticResultValue("mozilla", "firefox");
item.Add(itemSRV);
itemSRV = new SemanticResultValue("chrome", "chrome");
item.Add(itemSRV);
itemSRV = new SemanticResultValue("google chrome", "chrome");
item.Add(itemSRV);
SemanticResultKey itemSemKey = new SemanticResultKey("item", item);
//build the permutations of choices...
GrammarBuilder gb = new GrammarBuilder();
gb.Append(itemSemKey);
//now build the complete pattern...
GrammarBuilder itemRequest = new GrammarBuilder();
//pre-amble "[I'd like] a"
itemRequest.Append(new Choices("Can you open", "Open", "Please open"));
itemRequest.Append(gb, 0, 1);
Grammar TestGrammar = new Grammar(itemRequest);
return TestGrammar;
}https://stackoverflow.com/questions/5415262
复制相似问题