Last reviewed: 7/27/2024 10:23:15 AM
Microsoft Visual C++ Applications
Develop C++ applications that speak and listen using your favorite version of Microsoft Visual C++.
The following sections describe the steps for integrating SpeechKit with Microsoft Visual C++ applications.
SpeechKit Header Files
SpeechKit includes C++ header files comprised of the C++ classes that manage grammars and automatically load and unload the runtime DLL.
To access SpeechKit C++ classes within a Visual C++ 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.SpeechKit.Windows package and press the Install button.
- Select the Chant.Shared.Windows package and press the Install button.


To access the SpeechKit C++ classes within your application, add a reference to the Chant shared and SpeechKit header files in your C++ application header file:
#include "Chant.Shared.Windows.h"
#include "Chant.SpeechKit.Windows.h"
Add a reference in your C++ application source file to the Chant shared and SpeechKit code needed to dynamically load and unload the runtime DLL:
#include "Chant.Shared.Windows.cpp"
#include "Chant.ChantSpeechKit.Windows.cpp"
Object Instantiation
Declare a global variable for the SpeechKit class, instantiate instance, set the credentials, and set the event handler message.
Add the following to your application header file:
protected:
CSpeechKit* _SpeechKit;
CChantRecognizer* _Recognizer;
CChantSynthesizer* _Synthesizer;
};
Add the following to your application source file:
// Instantiate SpeechKit object
_SpeechKit = new CSpeechKit();
if (_SpeechKit =! NULL)
{
// Set credentials
_SpeechKit->SetCredentials(L"Credentials");
// Create recognizer
_Recognizer = _SpeechKit->CreateChantRecognizer();
if (_Recognizer != NULL)
{
// Register Event Handlers
_Recognizer->SetRecognitionCommand(RecognitionCommand);
}
// Create synthesizer
_Synthesizer = _SpeechKit->CreateChantSynthesizer();
if (_Synthesizer != NULL)
{
// Register Event Handlers
_Synthesizer->SetWordPosition(WordPosition);
}
}
Windows applications require the SpeechKit library (CSpeechKit.dll or CSpeechKitX64.dll) and 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 TTS | CAcaTTSSynthesizer | CSpeechKit.AcaTTS.dll or CSpeechKitX64.AcaTTS.dll |
Cepstral Swift | CSwiftSynthesizer | CSpeechKit.Swift.dll or CSpeechKitX64.Swift.dll |
CereProc CereVoice | CCereVoiceSynthesizer | CSpeechKit.CereVoice.dll or CSpeechKitX64.CereVoice.dll |
Microsoft Azure Speech | CMCSRecognizer or CMCSSynthesizer | CSpeechKit.MCS.dll or CSpeechKitX64.MCS.dll |
Microsoft SAPI 5 | CSAPI5Recognizer or CSAPI5Synthesizer | CSpeechKit.SAPI5.dll or CSpeechKitX64.SAPI5.dll |
Microsoft Speech Platform | CMSPRecognizer or CMSPSynthesizer | CSpeechKit.MSP.dll or CSpeechKitX64.MSP.dll |
Microsoft WindowsMedia (WinRT C++) | CChantRecognizer or CChantSynthesizer | CSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll |
Microsoft WindowsMedia (WinRT C++) | CWindowsMediaRecognizer or CWindowsMediaSynthesizer | CSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll |
Nuance Dragon NaturallySpeaking | CDgnRecognizer | CSpeechKit.Dgn.dll or CSpeechKitX64.Dgn.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.
void CALLBACK RecognitionCommand(void* Sender, CRecognitionCommandEventArgs* Args)
{
...
// Get the command properties
if ((Args != NULL) && (wcslen(Args->GetPhrase()) > 0))
{
...
}
}
void CALLBACK WordPosition(void* Sender, CWordPositionEventArgs* Args)
{
if (Args != NULL)
{
int startPosition = Args->GetPosition();
int wordLength = Args->GetLength();
...
}
}
Development and Deployment Checklist
When developing and deploying C++ applications, ensure you have a valid license, bundle the correct Chant class library, and configure your installation properly on the target system. Review the following checklist before developing and deploying your applications:
- Develop and deploy C++ applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy CSpeechKit.dll to the target system and place in the same directory with your application.
- 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.
- Develop and deploy C++ applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
- Copy CSpeechKitX64.dll to the target system and place in the same directory with your application.
- 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.
Sample Projects
Microsoft Visual C++ sample projects that use nuget packages may be found in the following directory of the vssamples.zip download:
- Chant\SpeechKit 13\CDLL.