这可能有点早,但我正在运行Windows 10 Technical Preview Build 10122.我想设置Cortana以获得自定义命令.以下是她的工作方式:
Hey Cortana, <she'll listen and process this command>
Run Code Online (Sandbox Code Playgroud)
Microsoft将处理该命令,如果没有任何内容,她将只搜索bing上的输入.但是,我想能够说出类似的话,例如
Hey Cortana, I'm going to bed now
Run Code Online (Sandbox Code Playgroud)
并让输入I'm going to bed now触发器运行批处理脚本,VBScript,命令或任何某种自定义响应,基本上执行以下操作.
C:\> shutdown -s
Run Code Online (Sandbox Code Playgroud)
有没有办法为Cortana设置预定义的自定义命令?
更新:
我创建了这个基本的YouTube教程,这个更高级的教程与相应的GitHub回购基于talkitbr的优秀且非常有用的答案如下.
起初他的答案超出了我的理解,所以我决定将其细节分解为像我这样的未来用户.
我正在努力创建自定义Cortana命令.使用通用Windows平台应用程序注册和执行命令.(GitHub的)
例如,我已经注册了以下命令
<Command Name="ShutDown">
<ListenFor>Shut down</ListenFor>
<Navigate/>
</Command>
Run Code Online (Sandbox Code Playgroud)
在UWP应用程序中运行此功能
static async void ShutDown()
{
var dialog = new MessageDialog("This is where I would shut the computer down.");
await dialog.ShowAsync();
//System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
}
Run Code Online (Sandbox Code Playgroud)
但是在设置之后System.Diagnostics.Process,UWP不支持我学到的东西.
我想运行的自定义命令涉及某种执行,例如启动外部程序,运行其他脚本或打开网站.
UWP不支持它们是有意义的,因为它是通用的,XBox或手机可能无法做到这些,但我希望在Windows 10 PC上有一些替代或黑客的方法来实现这一点.
我有办法Process在UWP应用程序中执行命令或具有类似功能的其他东西吗?似乎即使我可以让Cortana执行我的C#代码,UWP也不支持在这种情况下有用的东西.
提前致谢.
我在Windows 7上安装了Windows 10技术预览版Build 9926,即1月版.
我试图在我的Virtuabox上使用cortana的语音辅助,但我无法这样做.麦克风在我的主机Windows 7机器上完美运行
有什么建议我应该这样做,我的麦克风在virtualBox中工作?
我想使用新的Cortana引擎在Windows 10上开发Windows应用程序.
不幸的是,据我所知,它似乎仅在Windows Phone 8.1项目中可用(例如,我没有找到从不同类型的Visual Studio项目访问Windows.Media.SpeechRecognition命名空间的方法).
此外,我无法找到一个好的API文档,只有一些非常简单的例子.
编辑:
根据Peter Torr的回答,我写了一些代码.我已经能够识别出一些词,但是当它试图识别一些像"你好"这样简单的词时,引擎似乎很挣扎,而Cortana成功识别它.
难道我做错了什么?
public static class SpeechSynthetizerManager
{
private static readonly SpeechSynthesizer synth = new SpeechSynthesizer();
private static readonly SpeechRecognitionEngine speechRecognitionEngine = new SpeechRecognitionEngine();
public static event EventHandler<SpeechRecognizedEventArgs> SpeechRecognized
{
add { speechRecognitionEngine.SpeechRecognized += value; }
remove { speechRecognitionEngine.SpeechRecognized -= value; }
}
public static event EventHandler<RecognizeCompletedEventArgs> RecognizeCompleted
{
add { speechRecognitionEngine.RecognizeCompleted += value; }
remove { speechRecognitionEngine.RecognizeCompleted -= value; }
}
static SpeechSynthetizerManager()
{
synth.SelectVoiceByHints(VoiceGender.Female);
speechRecognitionEngine.LoadGrammar(new DictationGrammar());
speechRecognitionEngine.SetInputToDefaultAudioDevice();
}
public static …Run Code Online (Sandbox Code Playgroud) 我正在尝试为Cortana编写一个小应用程序.
我的想法是,我说:(我启用了"嘿Cortana"功能)
Hey Cortana, Convert 45 degrees to farenheit
Run Code Online (Sandbox Code Playgroud)
然后我在输出窗口(Visual Studio)中获得(此刻)日志.我试着准确地说出这句话,而Cortana完全理解我,但Cortana打开浏览器并将其输入Bing.
为什么?我做错了什么?我没有得到任何语法错误.
这是我的代码:
// commands.xml
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-us" Name="MyCommands_en-us">
<CommandPrefix> Convert, </CommandPrefix>
<Example> Convert 45 degrees to farenheit </Example>
<Command Name ="farenheitToDegrees">
<Example> 73 farenheit to degrees</Example>
<ListenFor> {farenheit} farenheit to degrees </ListenFor>
<Feedback> {farenheit} are ... in degrees </Feedback>
<Navigate/>
</Command>
<Command Name="degreesToFarenheit">
<Example> 45 degrees to farenheit </Example>
<ListenFor> {degrees} degrees to farenheit </ListenFor>
<Feedback> {degrees} degrees are ... in fareneheit </Feedback>
<Navigate/>
</Command> …Run Code Online (Sandbox Code Playgroud) 我目前在我的Silverlight应用程序中实现了Cortana.语音命令存储在CortanaCommands.xml中,这里是代码:
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-US">
<CommandPrefix>Dr. Bailey</CommandPrefix>
<Example> Open app to take dictation </Example>
<Command Name="Text">
<Example> Is it going to rain? </Example>
<ListenFor> [create] {dictation} </ListenFor>
<Feedback> "" </Feedback>
<Navigate Target="/Views/CortanaText.xaml" />
</Command>
<PhraseTopic Label="dictation" Scenario="Dictation">
<Subject> Cal 123 </Subject>
</PhraseTopic>
</CommandSet>
</VoiceCommands>"
Run Code Online (Sandbox Code Playgroud)
在这个例子中,如果用户部署Cortana并说"Bailey博士,它会下雨吗?",那么应用程序导航到CortanaText.xaml.这被硬编码到XML中,我希望用户能够自定义其命令前缀及其命令.
通过使用2个文本框,我在C#中编码了一个包含整个XML的字符串,但是从包含新命令前缀和命令的文本框中插入选项.这个字符串叫做cortanaXMLstring.使用新字符串覆盖CortanaCommands.xml中现有代码的最佳方法是什么?我认为这比修改现有XML的2个不同区域更容易.我还认为可以删除CortanaCommands.xml(使用c#代码),然后通过简单地插入字符串再次创建该XML,因为字符串包含XML所需的所有文本?或者,有关如何在XML中修改这两个字段的任何其他建议吗?这是命令前缀和命令示例.感谢您提供的任何帮助!
我有一个Cortana XML文件,我需要输入一个数字.我该怎么做才能确保将其转换为数字?
<Command Name="AddMoney">
<Example> Add 10 dollars </Example>
<ListenFor> add {amount} {currency} </ListenFor>
<Feedback> Adding some money </Feedback>
<Navigate/>
</Command>
<PhraseList Label="currency">
<item>dollar</item>
<item>euro</item>
<item>pound</item>
</PhraseList>
<PhraseList Label="amount">
</PhraseList>
Run Code Online (Sandbox Code Playgroud) 所以我在我的应用程序中添加了Cortana的语音命令识别功能.我的VCD文件已全部设置完毕,所有内容都按预期工作,所以现在我必须找一些小东西.
我在我的应用程序中拥有所有需要的图标(我知道),但当我的应用程序出现在Cortana屏幕上时("我能说什么?"屏幕),我的应用程序显示为默认图标,而不是我添加的.
所以我的问题是,我没有看到什么是缺少的图标?

ps:官方远程桌面应用程序也显示相同的图标,所以我想我不是唯一一个缺少图标:)
我有一个Windows Phone 8.1通用应用程序,我正在努力添加基本的Cortana支持.很多关于这个的文章都是针对Silverlight等的 - 我发现很难找到关于这个的真正好的信息.
到目前为止,如果应用已经运行或暂停,我有激活工作.但是,如果应用程序完全退出,则在激活时它会立即崩溃.我已经尝试过使用Hockey和一个简单的"LittleWatson"例程来捕捉崩溃,但似乎发生得太快就被抓住了.我已经看到一些引用私有测试版并试图获得崩溃转储,但到目前为止我没有任何运气.
这是我的激活码的样子app.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args) {
base.OnActivated(args);
ReceivedSpeechRecognitionResult = null;
if (args.Kind == ActivationKind.VoiceCommand) {
var commandArgs = args as VoiceCommandActivatedEventArgs;
if (commandArgs != null) {
ReceivedSpeechRecognitionResult = commandArgs.Result;
var rootFrame = Window.Current.Content as Frame;
if (rootFrame != null) {
rootFrame.Navigate(typeof(CheckCredentials), null);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我检查命令结果:
private async Task CheckForVoiceCommands() {
await Task.Delay(1); // not sure why I need this
var speechRecognitionResult = ((App)Application.Current).ReceivedSpeechRecognitionResult;
if (speechRecognitionResult == null) {
return; …Run Code Online (Sandbox Code Playgroud) 我想在TEXT模式下使用我的自定义Cortana命令"Notepad" .例如,按下WIN + S并输入"appname Notepad Example sentence!".
(这将打开记事本并输入"例句!".)
记事本命令已经在VOICE模式下工作:当我按下WIN + C并说"appname Notepad Example sentence!"时,我的记事本脚本与有效负载一起运行"例句!".
当我按下WIN + S并输入"appname Notepad Example sentence!"时,SpeechRecognitionResult的text属性为"Notepad ..."(与语音相反,它是"Notepad Example sentence!",如预期的那样).
<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>
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) cortana ×10
c# ×6
windows-10 ×4
uwp ×2
windows ×2
microphone ×1
nlp ×1
scripting ×1
virtualbox ×1
xml ×1