Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the argument from a Cortana command with a phrase topic, activated via text?

Tags:

High Level:

I want to use my custom Cortana command "Notepad" in TEXT mode. For instance, by pressing WIN+S and typing "appname Notepad Example sentence!".
(This will open Notepad and input "Example sentence!".)

The Notepad command already works in VOICE mode: when I press WIN+C and say "appname Notepad Example sentence!", my notepad script is run with the payload "Example sentence!".

The Problem:

When I press WIN+S and input "appname Notepad Example sentence!", the text property of SpeechRecognitionResult is "Notepad ..." (as opposed to voice where it is "Notepad Example sentence!", as expected).

Code:

VCD.xml excerpt

<Command Name="notepad">
  <Example> Notepad Example Sentence! </Example>
  <ListenFor> Notepad {wildcardArgs} </ListenFor>
  <Feedback> Notepadding {wildcardArgs} </Feedback>
  <Navigate/>
</Command>

<PhraseTopic Label="wildcardArgs" Scenario="Dictation">
  <!--<Subject>Wildcard</Subject>-->
</PhraseTopic>

CommandHandler.cs

public static CortanaCommand ProcessCommand(SpeechRecognitionResult speechRecognitionResult, CommandDiagnostics diagnostics)
{
    // Get the name of the voice command and the raw text
    string voiceCommandName = speechRecognitionResult.RulePath[0];
    string text = speechRecognitionResult.Text;
    string mode = speechRecognitionResult.SemanticInterpretation.Properties[interpretationKey].FirstOrDefault();
    // When mode is voice, text is "Notepad Example sentence!"
    // When mode is text, text is "Notepad ..."
      // How can one retrieve "Example sentence!" from "..." !?
      // Is there some property other than speechRecognitionResult.Text that holds the raw text typed? 

    string argument = null;
    CortanaCommand processedCommand = null;

    switch (voiceCommandName)
    {
       // ...
       case CortanaCommand.Notepad:
           const string notepad = "Notepad";
           argument = CortanaCommand.StripOffCommandName(notepad, text);
           processedCommand = new NotepadCortanaCommand(argument, diagnostics);
           break;

        default:
                Debug.WriteLine("Command Name Not Found:  " + voiceCommandName);
            break;
    }
    return processedCommand;
}

Question Restated

How can the above code be changed to extract command arguments (i.e. everything other than the app name and command name) in text mode?

like image 510
C. McCoy IV Avatar asked May 09 '16 00:05

C. McCoy IV


1 Answers

case CortanaCommand.Notepad:
       argument = speechRecognitionResult.SemanticInterpretation.Properties["wildcardArgs"].FirstOrDefault();
       // the magic line ^
       processedCommand = new NotepadCortanaCommand(argument, diagnostics);
       break;
like image 125
C. McCoy IV Avatar answered Sep 28 '22 02:09

C. McCoy IV