【问题标题】:Creating voice command synonyms in GRXML在 GRXML 中创建语音命令同义词
【发布时间】:2017-11-14 15:22:45
【问题描述】:

我在 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变量中。现在,我只需要支持一组非常有限的语音命令,而忽略其他所有命令,但在这组有限的命令中,我想要一些可变性。看来,this page 上的最后一个例子就是这样。于是我根据这个做了如下的语法文件:

<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>

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

【问题讨论】:

    标签: uwp c++-cx grxml


    【解决方案1】:

    我找到了一种使用 SRGS 做我想做的事情的方法(至少对于问题中描述的非常简单的情况)。所以,似乎&lt;tag&gt; 并没有直接改变识别结果(至少,不是tag-format="semantics/1.0",还有其他tag-format 的,如所述,例如here,他们可能会做其他事情) .相反,它填充了一些额外的属性集合。所以这就是我现在更改代码的方式:

    <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>
    

    现在,当“next”、“go”或“advance”被识别时,它仍然不变地转到args-&gt;Result-&gt;Text,但在args-&gt;Result-&gt;SemanticInterpretation-&gt;Properties 中也会有一个带有HONEY 键的新对和bunny 值。我可以检查是否是这种情况

    args->Result->SemanticInterpretation->Properties->HasKey("HONEY");
    

    如果是,则检索它的值

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

    【讨论】:

      【解决方案2】:

      或者不像我认为的那样工作

      标签是法律规则的扩展,标签不影响由语法定义的合法词模式或识别语音或给定语法的其他输入的过程。详情请查看 Tags section of Speech Recognition Grammar Specification

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

      语音识别将用户说出的单词转换为文本以供表单输入。 Constraints 或语法定义语音识别器可以匹配的口语单词和短语。您使用的语法用于定义匹配世界。如果您希望“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")
      {
      
      }
      

      详情请参考官方示例的Scenario_SRGSConstraint,其中包含方法HandleRecognitionResult

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-24
        • 1970-01-01
        • 2016-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-24
        • 2011-04-06
        相关资源
        最近更新 更多