问题描述
我想使用新的Cortana引擎在Windows 10上开发Windows应用程序。
I want to develop a Windows application on Windows 10 using the new Cortana engine.
据我所知,它似乎仅在Windows Phone上可用8.1项目(例如,我找不到从其他类型的Visual Studio项目访问Windows.Media.SpeechRecognition命名空间的方法。)
Unfortunately as far as I know, it seems to be available only on Windows Phone 8.1 project (for instance, I didn't find a way to access to the Windows.Media.SpeechRecognition namespace from a different type of Visual Studio project).
找不到很好的API文档,仅提供一些非常简单的示例。
Also I wasn't able to find a good API documentation, only some very simple examples.
编辑:
基于关于Peter Torr的回答,我已经写了一些代码。我已经能够识别一些单词,但是当引擎尝试识别诸如 Hello之类的简单单词时,引擎似乎很挣扎,而Cortana成功地识别了它。
Based on Peter Torr answer I've wrote some code. I've been able to recognize some word but the engine seems to struggle when it tried to recognize some simple words like "Hello", while Cortana recognized it successfully.
Am我做错了吗?
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 void Speak(string message)
{
synth.Speak(message);
}
public static void Listen()
{
speechRecognitionEngine.RecognizeAsync();
}
}
推荐答案
严格说来,Cortana API是。这些不适用于Classic(桌面)应用程序,但适用于Windows 10上的Universal Windows应用程序。Classic应用程序不能使用API的原因是因为它们依赖于诸如后台任务和App Identity之类的概念,
Strictly speaking, the Cortana APIs are the ones in the Windows.ApplicationModel.VoiceCommands
namespace. These are not available to Classic ("Desktop") apps, but are available to Universal Windows apps on Windows 10. The reason Classic apps can't use the APIs is because they rely on concepts such as Background Tasks and App Identity that don't apply to Classic apps.
也不适用于经典应用程序,但我不确定
The types in the Windows.Media.SpeechRecognition
namespace are also unavailable to Classic apps, but I'm not sure what the limitation is there.
注意:作为提到,您也许可以使这些类型在桌面应用程序中运行,但目前尚不明确支持。
Note: As @Andrew Pilley mentions, you might be able to get these types to work in a Desktop app but that's not explicitly supported at the moment.
如果只需要在.NET应用程序中进行语音识别,就可以使用,它使用相同的基础技术。
If you just want speech recognition in a .NET app, you can use the System.Speech.Recognition
namespace, which uses the same underlying technology.
这篇关于Cortana API是否可用于桌面应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!