Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Cortana APIs available for desktop applications?

I want to develop a Windows application on Windows 10 using the new Cortana engine.

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).

Also I wasn't able to find a good API documentation, only some very simple examples.

Edit:

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 I doing something wrong?

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();
    }
}
like image 386
simoneL Avatar asked Aug 10 '15 22:08

simoneL


People also ask

Can Cortana open apps on PC?

When you turn on Voice activation, Cortana will respond when you say the wake word. Cortana can open any setting for you. For example, to open Bluetooth settings try, "Cortana, open Bluetooth settings." Cortana can also open apps on your computer. For example, say something like "Cortana, open Word."

Why is Cortana being discontinued?

The planned shutdown of the app was first announced in July 2020, when Microsoft said it would be shifting toward a "transformational AI-powered assistant experience" in its Microsoft 365 apps, which would involve refocusing its "areas of innovation and development."

Where is Cortana available?

Currently, Cortana is only available in 13 countries; Australia, Brazil, Canada, China, France, Germany, India, Italy, Japan, Mexico, Spain, United Kingdom, and the United States. Cortana is not available outside of these countries.


2 Answers

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.

If you just want speech recognition in a .NET app, you can use the System.Speech.Recognition namespace, which uses the same underlying technology.

like image 64
Peter Torr - MSFT Avatar answered Sep 20 '22 12:09

Peter Torr - MSFT


So, while Peter Torr is right about Cortana (the Windows.ApplicationModel.VoiceCommands API), the new Speech Recognition WinRT APIs (Windows.Media.SpeechRecognition) can be used in a classic C# app, if you're willing to use the WinRT Interop libraries.

I've detailed how to set that up in this answer to a stack overflow question, although the person who asked that question is having some trouble replicating what I've gotten to work locally.

like image 35
Andrew Pilley Avatar answered Sep 20 '22 12:09

Andrew Pilley