Last reviewed: 7/27/2024 9:28:43 AM
.NET WPF Applications
Develop .NET WPF applications that manage lexicons using your favorite .NET WPF 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 LexiconKit with .NET WPF applications.
LexiconKit Assemblies
LexiconKit includes WPF 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 LexiconKit .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 Acapela TTS, Cepstral Swift, Microsoft Azure Speech, Microsoft SAPI5, Micosoft Speech Platform, and Microsoft WindowsMedia (via WinRT C++) speech technologies:
- Select the Chant.LexiconKit.Windows package and press the Install button.
-
For Microsoft WindowsMedia (via WinRT .NET) speech technologies:
- Select the Chant.LexiconKit.WinRT.WindowsMedia package and press the Install button.
To access the LexiconKit .NET classes within your application, add references to the Chant shared and LexiconKit assemblies in your code.
using System;
...
using Chant.LexiconKit.Windows;
using Chant.Shared.Windows;
Imports Chant.LexiconKit.Windows
Imports Chant.Shared.Windows
Class MainWindow
...
These applications require the applicable LexiconKit Speech API library in the same directory as the application .exe.
Speech API | LexiconKit Speech API class | LexiconKit Speech API library |
---|---|---|
Acapela TTS | NAcaTTSSynthesizer | CLexiconKit.AcaTTS.dll or CLexiconKitX64.AcaTTS.dll |
Cepstral Swift | NSwiftSynthesizer | CLexiconKit.Swift.dll or CLexiconKitX64.Swift.dll |
Microsoft Azure Speech | NMCSSynthesizer | CLexiconKit.MCS.dll or CLexiconKitX64.MCS.dll |
Microsoft SAPI 5 | NSAPI5Recognizer or NSAPI5Synthesizer | CLexiconKit.SAPI5.dll or CLexiconKitX64.SAPI5.dll |
Microsoft Speech Platform | NMSPRecognizer or NMSPSynthesizer | CLexiconKit.MSP.dll or CLexiconKitX64.MSP.dll |
Microsoft WindowsMedia | NWindowsMediaRecognizer or NWindowsMediaSynthesizer | CLexiconKit.WinRT.dll or CLexiconKitX64.WinRT.dll |
Platform Target
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 LexiconKit class, instantiate an instance, add the event handler, and set the credentials.
private NLexiconKit _LexiconKit;
private NSAPI5Synthesizer _Synthesizer = null;
public MainWindow()
{
InitializeComponent();
// Instantiate LexiconKit
_LexiconKit = new NLexiconKit();
if (_LexiconKit != null)
{
// Set credentials
_LexiconKit.SetCredentials("Credentials");
_Synthesizer = _LexiconKit.CreateSAPI5Synthesizer();
if (_Synthesizer != null)
{
_Synthesizer.APIError += this.Sythesizer_APIError;
}
}
}
Dim _LexiconKit As NLexiconKit
Dim WithEvents _Synthesizer As NSAPI5Synthesizer
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim engine As NChantEngine
' Instantiate LexiconKit
_LexiconKit = New NLexiconKit()
If (_LexiconKit IsNot Nothing) Then
' Set credentials
_LexiconKit.SetCredentials("Credentials")
_Synthesizer = _LexiconKit.CreateSAPI5Synthesizer()
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 Synthesizer_APIError(object sender, ChantAPIErrorEventArgs e)
{
// Format transcript message
string errorMsg = "";
errorMsg = "(" + e.RC.ToString() + ") ";
errorMsg += " " + e.Function.ToString() + " ";
errorMsg += e.Message;
...
}
Private Sub Synthesizer_APIError(ByVal sender As System.Object, ByVal e As ChantAPIErrorEventArgs) Handles _Synthesizer.APIError
Dim errorMsg As String
' Format transcript message
errorMsg = "(" + e.RC.ToString() + ") "
errorMsg += " " + e.Function.ToString() + " "
errorMsg += e.Message
...
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 deploying .NET Applications targeting Microsoft SAPI, Microsoft Speech Platform, or Microsoft WindowsMedia (via WinRT C++) 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.LexiconKit.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 LexiconKit 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 NLexiconKit.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.LexiconKit.Windows" version="10.0.0.0" publicKeyToken="88f55b96a2c67ff3" /> </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.LexiconKit.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 LexiconKit 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 NLexiconKitX64.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.LexiconKit.Windows" version="10.0.0.0" publicKeyToken="88f55b96a2c67ff3" /> </dependentAssembly> </dependency>
Sample Projects
.NET WPF sample projects that use nuget packages may be found in the following directory of the vssamples.zip download:
-
Applications that target Acapela TTS, Cepstral Swift, Microsoft Azure Speech, Microsoft SAPI5, Micosoft Speech Platform, and Microsoft WindowsMedia (via WinRT C++) speech technologies speech tecnologies:
- Chant\LexiconKit 10\NET\Windows\cs and
- Chant\LexiconKit 10\NET\Windows\vb.