Uwp 在GRXML中创建语音命令同义词

Uwp 在GRXML中创建语音命令同义词,uwp,c++-cx,grxml,Uwp,C++ Cx,Grxml,我已经用C++/CX创建了一个语音控制的UWP应用程序(如果有必要的话,用于Hololens)。一个非常简单的,主要根据一些示例,这是语音识别事件处理程序: void MyAppMain::HasSpoken(SpeechContinuousRecognitionSession ^sender, SpeechContinuousRecognitionResultGeneratedEventArgs ^args) { if (args->Result->Confidence =

我已经用C++/CX创建了一个语音控制的UWP应用程序(如果有必要的话,用于Hololens)。一个非常简单的,主要根据一些示例,这是语音识别事件处理程序:

void MyAppMain::HasSpoken(SpeechContinuousRecognitionSession ^sender, SpeechContinuousRecognitionResultGeneratedEventArgs ^args)
{
    if (args->Result->Confidence == SpeechRecognitionConfidence::Medium
        || args->Result->Confidence == SpeechRecognitionConfidence::High)
    {
        process_voice_command(args->Result->Text);
    }
}
到目前为止一切正常,识别结果在
args->result->Text
变量中。现在,我只需要支持一组非常有限的语音命令,而忽略所有其他命令,但在这组有限的命令中,我需要一些可变性。看起来,最后一个例子就是关于这个的。因此,我基于此创建了以下语法文件:

<grammar version="1.0" xml:lang="en-US" root="nextCommands" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">

  <rule id="nextCommands">
    <item>
      <one-of>
        <item>next</item>
        <item>go</item>        
        <item>advance</item>
      </one-of>
      <tag>out="next";</tag>
    </item>
  </rule>

</grammar>

下一个
去
进展
out=“下一步”;
我想要的是,当我说“下一步”、“前进”或“前进”时,识别引擎只返回“下一步”,因此它位于上面的
args->Result->Text
中。它现在对我的实际作用是将已识别的单词集限制为这三个单词,但它只是返回我所说的单词,而没有将其转换为“next”。看起来它要么忽略了
元素,要么我必须在我的C++/CX程序中以不同的方式检索它的内容。或者
不像我想的那样工作。我应该做什么改变才能让它工作

或者不是我想的那样

标记是一种法律规则扩展,标记不会影响语法定义的法律单词模式或识别语音或给定语法的其他输入的过程。详情请查收

我想要的是,当我说“下一步”、“前进”或“前进”时,识别引擎只返回“下一步”

语音识别将用户说出的单词转换为文本,用于表单输入,或语法,定义语音识别器可以匹配的口语单词和短语。您使用的语法用于定义匹配世界。如果希望“next”、“go”或“advance”执行相同的命令,可以在处理文本结果时处理它们。比如说,

// Start recognition.
Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync();
// Do something with the recognition result.
if (speechRecognitionResult.Text == "go" || speechRecognitionResult.Text == "next" || speechRecognitionResult.Text == "advance")
{

}

详细信息请参考官方样本,其中包含方法
HandlerRecognitionResult

我已经找到了一种方法来处理SRG(至少对于问题中描述的非常简单的案例)。因此,似乎
不会直接改变识别结果(至少,不是使用
标记格式=“语义/1.0”
,还有其他
标记格式,如前所述,例如,它们可能做其他事情)。相反,它填充一些额外的属性集合。这就是我现在更改代码的方式:

<grammar version="1.0" xml:lang="en-US" 
root="nextCommands" xmlns="http://www.w3.org/2001/06/grammar" 
tag-format="semantics/1.0">

  <rule id="nextCommands">
    <item>
      <one-of>
        <item>next</item>
        <item>go</item>        
        <item>advance</item>
      </one-of>
      <tag>out.HONEY="bunny";</tag>
    </item>
  </rule>

</grammar>
如果是,则使用

args->Result->SemanticInterpretation->Properties->Lookup("HONEY")->GetAt(0); //returns "bunny"
args->Result->SemanticInterpretation->Properties->Lookup("HONEY")->GetAt(0); //returns "bunny"