如何从带有文本主题的短语主题的Cortana命令中提取参数? [英] How to extract the argument from a Cortana command with a phrase topic, activated via text?

查看:82
本文介绍了如何从带有文本主题的短语主题的Cortana命令中提取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 TEXT 模式下使用自定义的Cortana命令记事本。例如,通过按WIN + S并键入 appname记事本示例语句!。


(这将打开记事本并输入例句!。)



Notepad命令已在 VOICE 模式:当我按WIN + C并说 appname记事本示例语句!时,我的记事本脚本将与有效负载示例语句!一起运行。

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!".

当我按WIN + S并输入 appname记事本示例语句!时, SpeechRecognitionResultResult的文本属性是记事本...(与语音相反,它是记事本示例句!,正如预期的那样)。

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>



CommandHandler.cs



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?

推荐答案

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

这篇关于如何从带有文本主题的短语主题的Cortana命令中提取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆