Last reviewed: 7/27/2024 10:24:35 AM
.NET Windows Forms Applications
Develop .NET Windows Forms applications that speak and listen using your favorite .NET Windows Forms 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 Windows Forms applications.
SpeechKit Assemblies
SpeechKit includes Windows Forms compatible .NET assemblies for .NET Framework and .NET 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 Forms application, add project references to the following nuget packages depending on 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 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;
Imports Chant.SpeechKit.Windows
Imports Chant.Shared.Windows
Class MainWindow
...
These applications require the applicable SpeechKit Speech API library in the same directory 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 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;
Imports Chant.SpeechKit
Imports Chant.Shared
Class MainWindow
...
These applications do not require a SpeechKit Speech API library.
Speech API | SpeechKit Speech API class | SpeechKit Speech API library |
---|---|---|
Microsoft .NET System.Speech | NChantRecognizer or NChantSynthesizer | NA |
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 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;
Imports Chant.SpeechKit.WinRT.WindowsMedia
Imports Chant.Shared.WinRT.WindowsMedia
Class MainWindow
...
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 |
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.MCS;
Imports Chant.SpeechKit.MCS
Imports Chant.Shared.MCS
Class MainWindow
...
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 |
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.
Within your VB .NET Project
- Select the Compile tab under project properties.
- Press the Advanced Compile Options... button.
- Select x86 or x64 in the Target CPU dropdown list.
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 MainWindow()
{
InitializeComponent();
// Instantiate SpeechKit
_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();
if (_Synthesizer != null)
{
_Synthesizer.WordPosition += Synthesizer_WordPosition;
}
}
}
Dim _SpeechKit As NSpeechKit
Dim WithEvents _Recognizer As NChantRecognizer
Dim WithEvents _Synthesizer As NChantSynthesizer
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
' 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
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 void Synthesizer_WordPosition(object sender, WordPositionEventArgs e)
{
if (e != null)
{
int startPosition = e.Position;
int wordLength = e.Length;
...
}
}
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
Private Sub Synthesizer_WordPosition(ByVal sender As System.Object, ByVal e As WordPositionEventArgs) Handles _Synthesizer.WordPosition
Dim startPosition As Integer
Dim wordLength As Integer
If (e IsNot Nothing) Then
startPosition = e.Position
wordLength = e.Length
...
End If
End Sub
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 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="13.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="13.0.0.0" publicKeyToken="b7bf58a6a1b083a7" /> </dependentAssembly> </dependency>
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 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.
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.