如何从带有短语主题的 Cortana 命令中提取参数,通过文本激活?
How to extract the argument from a Cortana command with a phrase topic, activated via text?
高级别:
我想在 TEXT 模式下使用自定义 Cortana 命令 "Notepad"。例如,按 WIN+S 并键入 "appname Notepad Example sentence!"。
(这将打开记事本并输入 "Example sentence!"。)
记事本命令已经在 VOICE 模式下工作:当我按 WIN+C 并说 "appname Notepad Example sentence!" 时,我的记事本脚本是 运行,有效负载 "Example sentence!" .
问题:
当我按 WIN+S 并输入 "appname Notepad Example sentence!" 时,SpeechRecognitionResult 的文本 属性 是 "Notepad ..."(与预期的语音 "Notepad Example sentence!" 相反).
代码:
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;
}
重述问题
如何更改上述代码以在文本模式下提取命令参数(即除应用程序名称和命令名称之外的所有内容)?
case CortanaCommand.Notepad:
argument = speechRecognitionResult.SemanticInterpretation.Properties["wildcardArgs"].FirstOrDefault();
// the magic line ^
processedCommand = new NotepadCortanaCommand(argument, diagnostics);
break;
高级别:
我想在 TEXT 模式下使用自定义 Cortana 命令 "Notepad"。例如,按 WIN+S 并键入 "appname Notepad Example sentence!"。
(这将打开记事本并输入 "Example sentence!"。)
记事本命令已经在 VOICE 模式下工作:当我按 WIN+C 并说 "appname Notepad Example sentence!" 时,我的记事本脚本是 运行,有效负载 "Example sentence!" .
问题:
当我按 WIN+S 并输入 "appname Notepad Example sentence!" 时,SpeechRecognitionResult 的文本 属性 是 "Notepad ..."(与预期的语音 "Notepad Example sentence!" 相反).
代码:
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;
}
重述问题
如何更改上述代码以在文本模式下提取命令参数(即除应用程序名称和命令名称之外的所有内容)?
case CortanaCommand.Notepad:
argument = speechRecognitionResult.SemanticInterpretation.Properties["wildcardArgs"].FirstOrDefault();
// the magic line ^
processedCommand = new NotepadCortanaCommand(argument, diagnostics);
break;