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.
  • Chant SpeechKit package
  • For Microsoft Azure Speech (via .NET) speech technologies:
    • Select the Chant.SpeechKit.MCS package and press the Install button.
  • Chant SpeechKit MCS package
  • 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.
  • Chant SpeechKit Windows package
  • For Microsoft WindowsMedia (via WinRT .NET) speech technologies:
    • Select the Chant.SpeechKit.WinRT.WindowsMedia package and press the Install button.
  • Chant SpeechKit WinRT WindowsMedia package

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 TTSNAcaTTSSynthesizerCSpeechKit.AcaTTS.dll or CSpeechKitX64.AcaTTS.dll
Cepstral SwiftNSwiftSynthesizerCSpeechKit.Swift.dll or CSpeechKitX64.Swift.dll
CereProc CereVoiceNCereVoiceSynthesizerCSpeechKit.CereVoice.dll or CSpeechKitX64.CereVoice.dll
Microsoft Azure SpeechNMCSRecognizer or NMCSSynthesizerCSpeechKit.MCS.dll or CSpeechKitX64.MCS.dll
Microsoft SAPI 5NSAPI5Recognizer or NSAPI5SynthesizerCSpeechKit.SAPI5.dll or CSpeechKitX64.SAPI5.dll
Microsoft Speech PlatformNMSPRecognizer or NMSPSynthesizerCSpeechKit.MSP.dll or CSpeechKitX64.MSP.dll
Microsoft WindowsMedia (WinRT C++)NChantRecognizer or NChantSynthesizerCSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll
Microsoft WindowsMedia (WinRT C++)NWindowsMediaRecognizer or NWindowsMediaSynthesizerCSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll
Nuance Dragon NaturallySpeakingNDgnRecognizerCSpeechKit.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.SpeechNChantRecognizer or NChantSynthesizerNA
Microsoft .NET System.SpeechNSAPI5Recognizer or NSAPI5SynthesizerNA
Microsoft .NET Microsoft.SpeechNMSPRecognizer or NMSPSynthesizerNA

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 NChantSynthesizerNA
Microsoft WindowsMedia (WinRT .NET)NWindowsMediaRecognizer or NWindowsMediaSynthesizerNA

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 SpeechNMCSRecognizer or NMCSSynthesizerNA

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

  1. Select the Build tab under project properties.
  2. Select x86 or x64 in the Platform target dropdown list.

Within your VB .NET Project

  1. Select the Compile tab under project properties.
  2. Press the Advanced Compile Options... button.
  3. 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.