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!".
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).
<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>
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;
}
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?
case CortanaCommand.Notepad:
argument = speechRecognitionResult.SemanticInterpretation.Properties["wildcardArgs"].FirstOrDefault();
// the magic line ^
processedCommand = new NotepadCortanaCommand(argument, diagnostics);
break;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With