【发布时间】:2016-05-09 00:09:29
【问题描述】:
高级:
我想在 TEXT 模式下使用我的自定义 Cortana 命令“记事本”。例如,按 WIN+S 并键入“appname Notepad Example!”。
(这将打开记事本并输入“例句!”。)
Notepad 命令已经在 VOICE 模式下工作:当我按 WIN+C 并说“appname Notepad Example sentence!”时,我的记事本脚本将使用有效负载“Example sentence!”运行。
问题:
当我按下 WIN+S 并输入“appname Notepad Example!”时,SpeechRecognitionResult 的 text 属性是“Notepad ...”(而不是语音,它是“Notepad Example!”,正如预期的那样)。
代码:
VCD.xml 摘录
<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;
}
问题重述
如何更改上述代码以在文本模式下提取命令参数(即除应用名称和命令名称之外的所有内容)?
【问题讨论】:
标签: c# win-universal-app cortana