Last reviewed: 12/15/2024 8:40:12 AM
Windows Desktop (WinUI) Applications
Develop Windows Desktop (WinUI) applications that speak and listen using your favorite Windows App SDK development tools. This includes development environments such as Microsoft Visual Studio.
The following sections describe the steps for integrating SpeechKit with Windows Desktop (WinUI) applications.
SpeechKit Assemblies
SpeechKit includes Windows App SDK compatible .NET assemblies to support most applications' target framework. If you need a specific target framework, then contact Chant Product Support.
To access SpeechKit .NET classes within a Windows Desktop (WinUI) application, add project references with the applicable nuget package depending on the application type and desired speech APIs:
- 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.
-
For System.Speech and Microsoft.Speech speech technologies:
- Select the Chant.SpeechKit package and press the Install button.
-
For Microsoft Azure Speech (via .NET) speech technologies:
- Select the Chant.SpeechKit.MCS package and press the Install button.
-
For Acapela TTS, Cepstral Swift, CereProc CereVoice, Microsoft Azure Speech (via C++), Microsoft SAPI5, Micosoft Speech Platform, Microsoft WindowsMedia (via WinRT C++), and Nuance Dragon NaturallySpeaking speech technologies:
- Select the Chant.SpeechKit.Windows package and press the Install button.
-
For Microsoft WindowsMedia (via WinRT .NET) speech technologies:
- Select the Chant.SpeechKit.WinRT.WindowsMedia package and press the Install button.
To access the SpeechKit .NET classes within applications that target Microsoft System.Speech and Microsoft.Speech speech technologies, add references to the Chant shared and SpeechKit assemblies in your code.
using System;
...
using Chant.SpeechKit;
using Chant.Shared;
These applications do not require a SpeechKit Speech API library.
| Speech API | SpeechKit Speech API class | SpeechKit Speech API library |
|---|---|---|
| Microsoft .NET System.Speech | NSAPI5Recognizer or NSAPI5Synthesizer | NA |
| Microsoft .NET Microsoft.Speech | NMSPRecognizer or NMSPSynthesizer | NA |
To access the SpeechKit .NET classes within applications that target Microsoft Azure Speech (via .NET) speech technologies, add references to the Chant shared and SpeechKit assemblies in your code.
using System;
...
using Chant.SpeechKit.MCS;
using Chant.Shared.WinRT.MCS;
These applications do not require a SpeechKit Speech API library.
| Speech API | SpeechKit Speech API class | SpeechKit Speech API library |
|---|---|---|
| Microsoft Azure Speech | NMCSRecognizer or NMCSSynthesizer | NA |
To access the SpeechKit .NET classes within applications that target Acapela TTS, Cepstral Swift, CereProc CereVoice, Microsoft Azure Speech (via C++), Microsoft SAPI5, Micosoft Speech Platform, Microsoft WindowsMedia (via WinRT C++), and Nuance Dragon NaturallySpeaking speech technologies, add references to the Chant shared and SpeechKit assemblies in your code.
using System;
...
using Chant.SpeechKit.Windows;
using Chant.Shared.Windows;
These applications require the applicable SpeechKit Speech API library in the same directory (Appx) as the application .exe.
| Speech API | SpeechKit Speech API class | SpeechKit Speech API library |
|---|---|---|
| Acapela TTS | NAcaTTSSynthesizer | CSpeechKit.AcaTTS.dll or CSpeechKitX64.AcaTTS.dll |
| Cepstral Swift | NSwiftSynthesizer | CSpeechKit.Swift.dll or CSpeechKitX64.Swift.dll |
| CereProc CereVoice | NCereVoiceSynthesizer | CSpeechKit.CereVoice.dll or CSpeechKitX64.CereVoice.dll |
| Microsoft Azure Speech | NMCSRecognizer or NMCSSynthesizer | CSpeechKit.MCS.dll or CSpeechKitX64.MCS.dll |
| Microsoft SAPI 5 | NSAPI5Recognizer or NSAPI5Synthesizer | CSpeechKit.SAPI5.dll or CSpeechKitX64.SAPI5.dll |
| Microsoft Speech Platform | NMSPRecognizer or NMSPSynthesizer | CSpeechKit.MSP.dll or CSpeechKitX64.MSP.dll |
| Microsoft WindowsMedia (WinRT C++) | NChantRecognizer or NChantSynthesizer | CSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll |
| Microsoft WindowsMedia (WinRT C++) | NWindowsMediaRecognizer or NWindowsMediaSynthesizer | CSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll |
| Nuance Dragon NaturallySpeaking | NDgnRecognizer | CSpeechKit.Dgn.dll or CSpeechKitX64.Dgn.dll |
To access the SpeechKit .NET classes within applications that target Microsoft WindowsMedia (via WinRT .NET), add references to the Chant shared and SpeechKit assemblies in your code.
using System;
...
using Chant.SpeechKit.WinRT.WindowsMedia;
using Chant.Shared.WinRT.WindowsMedia;
These applications do not require a SpeechKit Speech API library.
| Speech API | SpeechKit Speech API class | SpeechKit Speech API library |
|---|---|---|
| Microsoft WindowsMedia (WinRT .NET) | NChantRecognizer or NChantSynthesizer | NA |
| Microsoft WindowsMedia (WinRT .NET) | NWindowsMediaRecognizer or NWindowsMediaSynthesizer | NA |
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 NDgnRecognizer? _Recognizer = null;
//private NMCSRecognizer? _Recognizer = null;
//private NMSPRecognizer? _Recognizer = null;
//private NSAPI5Recognizer? _Recognizer = null;
//private NWindowsMediaRecognizer? _Recognizer = null;
private NChantSynthesizer? _Synthesizer = null;
//private NAcaTTSSynthesizer? _Synthesizer = null;
//private NCereVoiceSynthesizer? _Synthesizer = null;
//private NMCSSynthesizer? _Synthesizer = null;
//private NMSPSynthesizer? _Synthesizer = null;
//private NSAPI5Synthesizer? _Synthesizer = null;
//private NSwiftSynthesizer? _Synthesizer = null;
//private NWindowsMediaSynthesizer? _Synthesizer = null;
public MainWindow()
{
InitializeComponent();
// Instantiate SpeechKit
_SpeechKit = new NSpeechKit();
if (_SpeechKit != null)
{
// Set credentials
_SpeechKit.SetCredentials("Credentials");
_Recognizer = _SpeechKit.CreateChantRecognizer();
//_Recognizer = _SpeechKit.CreateMCSRecognizerFromAuthorizationToken("speechAuthorizationToken", "speechRegion");
//_Recognizer = _SpeechKit.CreateMCSRecognizerFromEndpoint("speechEndpointUri", "speechKey");
//_Recognizer = _SpeechKit.CreateMCSRecognizerFromHost("speechHostUri", "speechKey");
//_Recognizer = _SpeechKit.CreateMCSRecognizerFromSubscription("speechSubscriptionKey", "speechRegion");
//_Recognizer = _SpeechKit.CreateSAPI5Recognizer();
//_Recognizer = _SpeechKit.CreateMSPRecognizer();
//_Recognizer = _SpeechKit.CreateWindowsMediaRecognizer();
//_Recognizer = _SpeechKit.CreateDgnRecognizer();
if (_Recognizer != null)
{
_Recognizer.RecognitionCommand += this.Recognizer_RecognitionCommand;
}
_Synthesizer = _SpeechKit.CreateChantSynthesizer();
//_Synthesizer = _SpeechKit.CreateAcaTTSSynthesizer();
//_Synthesizer = _SpeechKit.CreateSwiftSynthesizer();
//_Synthesizer = _SpeechKit.CreateCereVoiceSynthesizer();
//_Synthesizer = _SpeechKit.CreateMCSSynthesizerFromAuthorizationToken("speechAuthorizationToken", "speechRegion");
//_Synthesizer = _SpeechKit.CreateMCSSynthesizerFromEndpoint("speechEndpointUri", "speechKey");
//_Synthesizer = _SpeechKit.CreateMCSSynthesizerFromHost("speechHostUri", "speechKey");
//_Synthesizer = _SpeechKit.CreateMCSSynthesizerFromSubscription("speechSubscriptionKey", "speechRegion");
//_Synthesizer = _SpeechKit.CreateSAPI5Synthesizer();
//_Synthesizer = _SpeechKit.CreateMSPSynthesizer();
//_Synthesizer = _SpeechKit.CreateWindowsMediaSynthesizer();
if (_Synthesizer != null)
{
_Synthesizer.WordPosition += Synthesizer_WordPosition;
}
}
}
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 void Synthesizer_WordPosition(object sender, WordPositionEventArgs e)
{
if (e != null)
{
int startPosition = e.Position;
int wordLength = e.Length;
...
}
}
Package.appxmanifest Capablities
If the application requires speech recognition, it requires use of the microphone. If it uses cloud-based speech technologies, it requires Internet (client) capabilities. Select Internet and Microphone under Package.appxmanifest Capabilities in Visual Studio or add the following to the Package.appxmanifest file:
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<Capability Name="internetClient"/>
<DeviceCapability Name="microphone"/>
</Capabilities>
Platform Target
For applications that require the applicable SpeechKit Speech API library, set the project Platform target to either x86 for 32-bit application or x64 for 64-bit application as follows:
Within your C# project
- Select the Build tab under project properties.
- Select x86 or x64 in the Platform target dropdown list.
Development and Deployment Checklist
When developing and deploying .NET applications, ensure you have a valid license, bundle the correct Chant class libraries, and configure your installation properly on the target system.
Review the following checklist before deploying .NET applications targeting System.Speech or Microsoft.Speech speech technologies:
- Develop and deploy .NET applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.SpeechKit.dll and Chant.Shared.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
Review the following checklist before deploying .NET applications targeting Microsoft Azure Speech (via .NET) speech technologies:
- Develop and deploy .NET applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.SpeechKit.MCS.dll and Chant.Shared.MCS.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
Review the following checklist before developing and deploying .NET applications targeting Acapela TTS, Cepstral Swift, CereProc CereVoice, Microsoft Azure Speech (via C++), Microsoft SAPI5, Micosoft Speech Platform, Microsoft WindowsMedia (via WinRT C++), and Nuance Dragon NaturallySpeaking speech technologies:
- Develop and deploy .NET applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.SpeechKit.Windows.dll and Chant.Shared.Windows.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
- Copy applicable 32-bit SpeechKit Speech API DLL(s) to the target system and place in the same directory with your application.
- Copy applicable 32-bit Microsoft Cognitive Services client DLLs to the target system and place in the same directory with your application when using Azure Speech.
- Copy NSpeechKit.dll to the target system,
- register as a COM library on the target system, or
- place in the same directory with .NET application and include an App.manifest with a dependent assembly declaration:
<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Chant.SpeechKit.Windows" version="14.0.0.0" publicKeyToken="b7bf58a6a1b083a7" /> </dependentAssembly> </dependency>
- Develop and deploy .NET applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.SpeechKit.Windows.dll and Chant.Shared.Windows.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
- Copy applicable 64-bit SpeechKit Speech API DLL(s) to the target system and place in the same directory with your application.
- Copy applicable 64-bit Microsoft Cognitive Services client DLLs to the target system and place in the same directory with your application when using Azure Speech.
- Copy NSpeechKitX64.dll to the target system,
- register as a COM library on the target system, or
- place in the same directory with .NET application and include an App.manifest with a dependent assembly declaration:
<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Chant.SpeechKit.Windows" version="14.0.0.0" publicKeyToken="b7bf58a6a1b083a7" /> </dependentAssembly> </dependency>
Review the following checklist before deploying .NET applications targeting WindowsMedia (via WinRT .NET) speech technologies:
- Develop and deploy .NET applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.SpeechKit.WinRT.WindowsMedia.dll and Chant.Shared.WinRT.WindowsMedia.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
Sample Projects
Windows Desktop (WinUI) sample projects are installed at the following location:
- Documents\Chant\SpeechKit 14\WinUI\Windows\cs.