Last reviewed: 12/15/2024 8:11:13 AM
Windows Desktop (WinUI) Applications
Develop Windows Desktop (WinUI) applications that manage grammars 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 GrammarKit with Windows Desktop (WinUI) applications.
GrammarKit Assemblies
GrammarKit 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 GrammarKit .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.GrammarKit package and press the Install button.
-
For Microsoft SAPI, Microsoft Speech Platform, and Microsoft WindowsMedia (via WinRT C++) speech technologies:
- Select the Chant.GrammarKit.Windows package and press the Install button.
-
For Microsoft WindowsMedia (via WinRT .NET) speech technologies:
- Select the Chant.GrammarKit.WinRT.WindowsMedia package and press the Install button.
To access the GrammarKit .NET classes within applications that target Microsoft System.Speech and Microsoft.Speech speech technologies, add references to the Chant shared and GrammarKit assemblies in your code.
using System;
...
using Chant.GrammarKit;
using Chant.Shared;
These applications do not require a GrammarKit Speech API library.
| Speech API | GrammarKit Speech API class | GrammarKit Speech API library |
|---|---|---|
| Microsoft .NET System.Speech | NSAPI5Recognizer | NA |
| Microsoft .NET Microsoft.Speech | NMSPRecognizer | NA |
To access the GrammarKit .NET classes within applications that target Microsoft SAPI5, Micosoft Speech Platform, and Microsoft WindowsMedia (via WinRT C++) speech technologies, add references to the Chant shared and GrammarKit assemblies in your code.
using System;
...
using Chant.GrammarKit.Windows;
using Chant.Shared.Windows;
These applications require the applicable GrammarKit Speech API library in the same directory (Appx) as the application .exe.
| Speech API | GrammarKit Speech API class | GrammarKit Speech API library |
|---|---|---|
| Microsoft SAPI 5 | NSAPI5Recognizer | CGrammarKit.SAPI5.dll or CGrammarKitX64.SAPI5.dll |
| Microsoft Speech Platform | NMSPRecognizer | CGrammarKit.MSP.dll or CGrammarKitX64.MSP.dll |
| Microsoft WindowsMedia (WinRT C++) | NWindowsMediaRecognizer | CGrammarKit.WinRT.dll or CGrammarKitX64.WinRT.dll |
To access the GrammarKit .NET classes within applications that target Microsoft WindowsMedia (via WinRT .NET) speech technologies, add references to the Chant shared and GrammarKit assemblies in your code.
using System;
...
using Chant.GrammarKit.WinRT.WindowsMedia;
using Chant.Shared.WinRT.WindowsMedia;
These applications do not require a GrammarKit Speech API library.
| Speech API | GrammarKit Speech API class | GrammarKit Speech API library |
|---|---|---|
| Microsoft WindowsMedia (via WinRT .NET) | NWindowsMediaRecognizer | NA |
Object Instantiation
Declare variables for the GrammarKit classes, instantiate instance, add the event handlers, and set the credentials.
private NGrammarKit _GrammarKit = null;
private NSAPI5Recognizer _Recognizer = null;
public MainWindow()
{
InitializeComponent();
// Instantiate GrammarKit
_GrammarKit = new NGrammarKit();
if (_GrammarKit != null)
{
// Set credentials
_GrammarKit.SetCredentials("Credentials");
_Recognizer = _GrammarKit.CreateSAPI5Recognizer();
if (_Recognizer != null)
{
_Recognizer.CompileDone += this.Compile_CompileDone;
_Recognizer.CompileError += this.Compile_CompileError;
}
}
}
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 Compile_CompileDone(object sender, CompileEventArgs e)
{
...
}
private void Compile_CompileError(object sender, CompileEventArgs e)
{
// Format transcript message
string errorMsg = "";
errorMsg = "(" + e.Error.ToString() + ") ";
errorMsg += "error " + e.LineNumber.ToString() + " ";
errorMsg += e.Description;
...
}
Platform Target
For applications that require the applicable GrammarKit 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 Windows Desktop (WinUI) 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 Windows Desktop (WinUI) applications targeting System.Speech or Microsoft.Speech speech technologies:
- Develop and deploy Windows Desktop (WinUI) applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.GrammarKit.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 Windows Desktop (WinUI) applications targeting Microsoft SAPI, Microsoft Speech Platform, or Microsoft WindowsMedia (via WinRT C++) speech technologies:
- Develop and deploy Windows Desktop (WinUI) applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.GrammarKit.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 GrammarKit Speech API DLL(s) to the target system and place in the same directory with your application.
-
Copy NGrammarKit.dll to the target system,
- register as a COM library on the target system, or
- place in the same directory with Windows Desktop (WinUI) application and include an App.manifest with a dependent assembly declaration:
<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Chant.GrammarKit.Windows" version="11.0.0.0" publicKeyToken="90fe21044a41aa86" /> </dependentAssembly> </dependency>
- Develop and deploy Windows Desktop (WinUI) applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.GrammarKit.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 GrammarKit Speech API DLL(s) to the target system and place in the same directory with your application.
- Copy NGrammarKitX64.dll to the target system,
- register as a COM library on the target system, or
- place in the same directory with Windows Desktop (WinUI) application and include an App.manifest with a dependent assembly declaration:
<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Chant.GrammarKit.Windows" version="11.0.0.0" publicKeyToken="90fe21044a41aa86" /> </dependentAssembly> </dependency>
Review the following checklist before deploying Windows Desktop (WinUI) applications targeting WindowsMedia (via WinRT .NET) speech technologies:
- Develop and deploy Windows Desktop (WinUI) applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy Chant.GrammarKit.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\GrammarKit 11\WinUI\Windows\cs.