Last reviewed: 7/27/2024 8:19:52 AM
.NET UWP Applications
Develop .NET UWP applications that manage grammars using your favorite .NET UWP 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 GrammarKit with .NET UWP applications.
GrammarKit Assemblies
GrammarKit includes UWP compatible .NET assemblies to support your application's target framework.
To access GrammarKit .NET classes within a UWP application, add project references to the following nuget packages:
- 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.
- Select the Chant.GrammarKit.WindowsMedia package and press the Install button.

To access the GrammarKit .NET classes within your application, add references to the GrammarKit assemblies in your code:
using System;
...
using Chant.GrammarKit.WindowsMedia;
using Chant.Shared.WindowsMedia;
Imports Chant.GrammarKit.WindowsMedia
Imports Chant.Shared.WindowsMedia
Public NotInheritable Class MainPage
...
Object Instantiation
Declare a global variable for the GrammarKit class, instantiate an instance, add the event handler, and set the credentials.
private NGrammarKit _GrammarKit = null;
private NWindowsMediaRecognizer _Recognizer = null;
public MainPage()
{
this.InitializeComponent();
_GrammarKit = new NGrammarKit();
if (_GrammarKit != null)
{
// Set credentials
_GrammarKit.SetCredentials("Credentials");
_Recognizer = _GrammarKit.CreateWindowsMediaRecognizer();
if (_Recognizer != null)
{
_Recognizer.CompileDone += this.Compile_CompileDone;
_Recognizer.CompileError += this.Compile_CompileError;
}
}
}
Public NotInheritable Class MainPage
Inherits Page
Dim _GrammarKit As NGrammarKit
Dim WithEvents _Recognizer As NWindowsMediaRecognizer
Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
' Instantiate GrammarKit
_GrammarKit = New NGrammarKit()
If (_GrammarKit IsNot Nothing) Then
' Set credentials
_GrammarKit.SetCredentials("Credentials")
_Recognizer = _GrammarKit.CreateWindowsMediaRecognizer()
End If
End Sub
End Class
.NET UWP applications do not require a GrammarKit Speech API library.
Speech API | GrammarKit Speech API class | GrammarKit Speech API library |
---|---|---|
Microsoft WindowsMedia (UWP) | NWindowsMediaRecognizer | NA |
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;
...
}
Private Sub Compile_CompileDone(ByVal sender As System.Object, ByVal e As CompileEventArgs) Handles _Recognizer.CompileDone
...
End Sub
Private Sub Compile_CompileError(ByVal sender As System.Object, ByVal e As CompileEventArgs) Handles _Recognizer.CompileError
Dim errorMsg As String
' Format transcript message
errorMsg = "(" + e.Error.ToString() + ") "
errorMsg += "error " + e.LineNumber.ToString() + " "
errorMsg += e.Description
...
End Sub
Development and Deployment Checklist
When developing and deploying UWP applications, you need to ensure you have a valid license. See the section License for more information about licensing Chant software.
Sample Projects
Microsoft Visual C++ sample projects that use nuget packages may be found in the following directory of the vssamples.zip download:
- Chant\GrammarKit 10\UWP\cs and
- Chant\GrammarKit 10\UWP\vb.