-->

Get any value from Cortana voice command result

2019-07-05 14:37发布

问题:

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