Last reviewed: 7/27/2024 10:23:26 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 to the following nuget packages:

  • 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;
private NChantSynthesizer _Synthesizer = null;
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
    Dim WithEvents _Synthesizer As NChantSynthesizer
    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 compilation is complete 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

Microsoft Visual C++ sample projects that use nuget packages may be found in the following directory of the vssamples.zip download:

  • Chant\SpeechKit 13\UWP\cs and
  • Chant\SpeechKit 13\UWP\vb.