如何从带有短语主题的Cortana命令中提取参数,通过文本激活?

高水平:

我想在TEXT模式下使用我的自定义Cortana命令“Notepad”。 例如,按下WIN + S并输入“appname Notepad Example sentence!”。
(这将打开记事本并输入“例句!”。)

Notepad命令已经在VOICE模式下工作:当我按下WIN + C并说“appname Notepad Example sentence!”时,我的记事本脚本运行有效负载“例句!”。

问题:

当我按下WIN + S并输入“appname Notepad Example sentence!”时,SpeechRecognitionResult的text属性为“Notepad …”(与语音相反,它是“Notepad Example sentence!”,正如预期的那样)。

码:

VCD.xml摘录

  Notepad Example Sentence!   Notepad {wildcardArgs}   Notepadding {wildcardArgs}     <!--Wildcard-->  

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

问题重申

如何更改上述代码以在文本模式下提取命令参数(即应用程序名称和命令名称以外的所有内容)?

 case CortanaCommand.Notepad: argument = speechRecognitionResult.SemanticInterpretation.Properties["wildcardArgs"].FirstOrDefault(); // the magic line ^ processedCommand = new NotepadCortanaCommand(argument, diagnostics); break;