Get any value from Cortana voice command result

筅森魡賤 提交于 2019-12-10 18:48:12

问题


Is it posible to read any value from Cortana voice command?

For example, when I say:

"Search {something} in my library"

I want to get the result from {something} in my app.

I found how to work with PhraseList and PhraseTopic, but in my case could be any word instead of some declared items or one topic.


回答1:


In your VoiceCommands.xml you need:

<PhraseTopic Label="something" Scenario="Natural Language">
  <Subject> Natural Language </Subject>
</PhraseTopic>

In your App.xaml.cs you need:

     private string SemanticInterpretation(string interpretationKey, SpeechRecognitionResult speechRecognitionResult)
    {
        return speechRecognitionResult.SemanticInterpretation.Properties[interpretationKey].FirstOrDefault();
    }
}

In the OnActivated Method (or wherever else you Handle the command) you can read it out with:

switch (voiceCommandName)
       {
        case "something":
              string something = this.SemanticInterpretation("something", speechRecognitionResult);

something will be everything between search and in my library



来源:https://stackoverflow.com/questions/33056223/get-any-value-from-cortana-voice-command-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!