Last reviewed: 12/15/2024 8:39:12 AM

.NET UWP Applications

Develop .NET UWP applications that speak and listen using your favorite .NET UWP development tools. This includes development environments such as Microsoft Visual C# .NET and Microsoft Visual Basic .NET.

The following sections describe the steps for integrating SpeechKit with .NET UWP applications.

SpeechKit Assemblies

SpeechKit includes UWP compatible .NET assemblies to support your application's target framework.

To access SpeechKit .NET classes within a UWP application, add project references with the following nuget package:

  • Select the application project in the Solution Explorer
  • Right-click the mouse and select the Manage Nuget Packages… menu item.
  • Enter Chant in the search bar.
  • Select the Chant.SpeechKit.WindowsMedia package and press the Install button.
  • Chant SpeechKit WindowsMedia package

To access the SpeechKit .NET classes within your application, add references to the SpeechKit assemblies in your code:


using System;
...
using Chant.SpeechKit.WindowsMedia;
using Chant.Shared.WindowsMedia;

Imports Chant.SpeechKit.WindowsMedia
Imports Chant.Shared.WindowsMedia
Public NotInheritable Class MainPage
...

Object Instantiation

Declare a global variable for the SpeechKit class, instantiate an instance, add the event handler, and set the credentials.


private NSpeechKit _SpeechKit = null;
private NChantRecognizer _Recognizer = null; // Platform default - Microsoft WindowsMedia
private NChantSynthesizer _Synthesizer = null; // Platform default - Microsoft WindowsMedia
public MainPage()
{
    this.InitializeComponent();
    _SpeechKit = new NSpeechKit();
    if (_SpeechKit != null)
    {
        // Set credentials
        _SpeechKit.SetCredentials("Credentials");
        _Recognizer = _SpeechKit.CreateChantRecognizer();
        if (_Recognizer != null)
        {
            _Recognizer.RecognitionCommand += this.Recognizer_RecognitionCommand;
        }
        _Synthesizer = _SpeechKit.CreateChantSynthesizer();
    }
}

Public NotInheritable Class MainPage
    Inherits Page
    Dim _SpeechKit As NSpeechKit
    Dim WithEvents _Recognizer As NChantRecognizer // Platform default - Microsoft WindowsMedia
    Dim WithEvents _Synthesizer As NChantSynthesizer // Platform default - Microsoft WindowsMedia
    Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
        ' Instantiate SpeechKit
        _SpeechKit = New NSpeechKit()
        If (_SpeechKit IsNot Nothing) Then
            ' Set credentials
            _SpeechKit.SetCredentials("Credentials")
            _Recognizer = _SpeechKit.CreateChantRecognizer()
            _Synthesizer = _SpeechKit.CreateChantSynthesizer()
        End If
    End Sub
End Class

.NET UWP applications do not require a SpeechKit Speech API library.

Speech API SpeechKit Speech API class SpeechKit Speech API library
Microsoft WindowsMedia (UWP)NChantRecognizer or NChantSynthesizerNA
Microsoft WindowsMedia (UWP)NWindowsMediaRecognizer or NWindowsMediaSynthesizerNA

Event Callbacks

Event callbacks are the mechanism in which the class object sends information back to the application such as speech recognition occurred, audio playback finished, or there was an error.


private void Recognizer_RecognitionCommand(object sender, RecognitionCommandEventArgs e)
{
    if ((e != null) && (e.Phrase != null))
    {
        ...
    }
}

Private Sub Recognizer_RecognitionCommand(ByVal sender As System.Object, ByVal e As RecognitionCommandEventArgs) Handles _Recognizer.RecognitionCommand
    If ((e IsNot Nothing) And (e.Phrase IsNot Nothing)) Then
        ...
    End If
End Sub

Package.appxmanifest Capablities

If the application requires speech recognition, it requires use of the microphone. Select Microphone under Package.appxmanifest Capabilities in Visual Studio or add the following to the Package.appxmanifest file:

<Capabilities>
    <DeviceCapability Name="microphone" />
</Capabilities>

Microphone Privacy Settings

If the application requires speech recognition, it requires use of the microphone. Set the Microphone usage to On for the app under Settings->Privacy->Microphone.

Speech Privacy Settings

If the application requires continuous speech recognition (dictation vocabulary), it needs to be enabled on the platform. Set the Speech Privacy usage to On for the system under Settings->Privacy->Speech.

Development and Deployment Checklist

When developing and deploying UWP applications, you need to ensure you have a valid license. See the section License for more information about licensing Chant software.

Sample Projects

.NET UWP sample projects are installed at the following location:

  • Documents\Chant\SpeechKit 14\UWP\cs and
  • Documents\Chant\SpeechKit 14\UWP\vb.