Last reviewed: 7/27/2024 11:54:18 AM
.NET WPF Applications
Develop .NET WPF applications that manage conversations 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 VoiceXMLKit with .NET WPF applications.
VoiceXMLKit Assemblies
VoiceXMLKit 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 VoiceXMLKit .NET classes within a WPF application, add project references to the following nuget package:
- 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.VoiceXMLKit.Windows package and press the Install button.
To access the VoiceXMLKit .NET classes within your application, add references to the Chant shared and VoiceXMLKit assemblies in your code.
using System;
...
using Chant.VoiceXMLKit.Windows;
using Chant.Shared.Windows;
Imports Chant.VoiceXMLKit.Windows
Imports Chant.Shared.Windows
Class MainWindow
...
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 VoiceXMLKit class, instantiate an instance, add the event handler, and set the credentials.
private NVoiceXMLKit _VoiceXMLKit = null;
private NSAPI5VoiceXML _VoiceXML = null;
private NSAPI5Recognizer _Recognizer = null;
private NSAPI5Synthesizer _Synthesizer = null;
public MainWindow()
{
InitializeComponent();
// Instantiate VoiceXMLKit object
_VoiceXMLKit = new NVoiceXMLKit();
if (_VoiceXMLKit != null)
{
// Set credentials
_VoiceXMLKit.SetCredentials("Credentials");
// Create VoiceXML
_VoiceXML = _VoiceXMLKit.CreateSAPI5VoiceXML();
// Create recognizer
_Recognizer = _VoiceXMLKit.CreateSAPI5Recognizer();
// Create synthesizer
_Synthesizer = _VoiceXMLKit.CreateSAPI5Synthesizer();
// Register for the events
if (_VoiceXML != null)
{
_VoiceXML.Done += VoiceXML_Done;
_VoiceXML.CompileError += VoiceXML_CompileError;
_VoiceXML.DlgAddChoice += VoiceXML_DlgAddChoice;
_VoiceXML.DlgClearChoices += VoiceXML_DlgClearChoices;
_VoiceXML.DlgClearText += VoiceXML_DlgClearText;
_VoiceXML.DlgCreateDialog += VoiceXML_DlgCreateDialog;
_VoiceXML.DlgHideChoices += VoiceXML_DlgHideChoices;
_VoiceXML.DlgHideDialog += VoiceXML_DlgHideDialog;
_VoiceXML.DlgHideText += VoiceXML_DlgHideText;
_VoiceXML.DlgSelectChoice += VoiceXML_DlgSelectChoice;
_VoiceXML.DlgSetPrompt += VoiceXML_DlgSetPrompt;
_VoiceXML.DlgSetText += VoiceXML_DlgSetText;
_VoiceXML.DlgShowChoices += VoiceXML_DlgShowChoices;
_VoiceXML.DlgShowDialog += VoiceXML_DlgShowDialog;
_VoiceXML.DlgShowText += VoiceXML_DlgShowText;
}
}
}
Dim _VoiceXMLKit As NVoiceXMLKit = Nothing
Dim WithEvents _VoiceXML As NSAPI5VoiceXML = Nothing
Dim WithEvents _Recognizer As NSAPI5Recognizer = Nothing
Dim WithEvents _Synthesizer As NSAPI5Synthesizer = Nothing
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs)
InitializeComponent()
' Instantiate VoiceXMLKit object
_VoiceXMLKit = New NVoiceXMLKit()
If (_VoiceXMLKit IsNot Nothing) Then
' Set credentials
_VoiceXMLKit.SetCredentials("Credentials")
' Create VoiceXML
_VoiceXML = _VoiceXMLKit.CreateSAPI5VoiceXML()
' Create recognizer
_Recognizer = _VoiceXMLKit.CreateSAPI5Recognizer()
' Create synthesizer
_Synthesizer = _VoiceXMLKit.CreateSAPI5Synthesizer()
End If
End Sub
These applications require the applicable VoiceXMLKit Speech API library in the same directory as the application .exe.
Speech API | VoiceXMLKit Speech API class | VoiceXMLKit Speech API library |
---|---|---|
Microsoft SAPI 5 | NSAPI5Recognizer or NSAPI5Synthesizer | CVoiceXMLKit.SAPI5.dll or CVoiceXMLKitX64.SAPI5.dll |
Microsoft Speech Platform | NMSPRecognizer or NMSPSynthesizer | CVoiceXMLKit.MSP.dll or CVoiceXMLKitX64.MSP.dll |
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 VoiceXML_Done(object sender, VxmlDoneEventArgs e)
{
if ((e != null) && (e.Variables != null))
{
...
}
}
Public Sub VoiceXML_Done(ByVal sender As System.Object, ByVal e As VxmlDoneEventArgs) Handles _VoiceXML.Done
If ((e IsNot Nothing) And (e.Variables IsNot Nothing)) Then
...
End If
button1.IsEnabled = True
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 applications targeting Microsoft SAPI5 and Micosoft Speech Platform 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.VoiceXMLKit.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 VoiceXMLKit Speech API DLL(s) to the target system and place in the same directory with your application.
- Copy NVoiceXMLKit.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.VoiceXMLKit.Windows" version="7.0.0.0" publicKeyToken="4d55ff7f44d3f866" /> </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.VoiceXMLKit.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 VoiceXMLKit Speech API DLL(s) to the target system and place in the same directory with your application.
- Copy NVoiceXMLKitX64.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.VoiceXMLKit.Windows" version="7.0.0.0" publicKeyToken="4d55ff7f44d3f866" /> </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 Microsoft SAPI5 and Micosoft Speech Platform speech tecnologies:
- Chant\VoiceXMLKit 10\NET\Windows\cs and
- Chant\VoiceXMLKit 10\NET\Windows\vb.