How do I interact with users for hands-free operation?

Last reviewed: 2/19/2021

HOW Article ID: H012102

The information in this article applies to:

  • Talk&Listen

Summary

Applications interact with end users by talking and listening and offering hands-free operation.

More Information

Chant Developer Workbench 2020 includes Talk&Listen application helper to simplify the process of integrating speech synthesis and speech recognition for hands-free operation.

Sometimes applications need a simple way to synthesize and recognize. Chant Talk & Listen application helper enables applications to synthesize and recognize speech without having to worry about events, properties, and callback handlers.


// Instantiate TalkListen
NTalkListen _TalkListen = new NTalkListen();
if (_TalkListen != null)
{
    // Set license properties
    //_TalkListen.SetLicense("LicenseRegistrationNumber", "LicenseSerialNumber");
    // Else, for evaluation, set only evaluation serial number
    _TalkListen.SetLicense(string.Empty, "EvaluationSerialNumber");
    NSAPI5Synthesizer _Synthesizer = _TalkListen.CreateSAPI5Synthesizer();
    if (_Synthesizer != null)
    {
        _Synthesizer.Talk("This is the easiest way to synthesize.");
    }
    NSAPI5Recognizer _Recognizer = _TalkListen.CreateSAPI5Recognizer();
    if (_Recognizer != null)
    {
        string recognitionResults = _Recognizer.Listen();
    }
}
        

// Instantiate TalkListen object
CTalkListen* _TalkListen = new CTalkListen();
if (_TalkListen =! NULL)
{
    // Set license properties
    //_TalkListen->SetLicense(L"LicenseRegistrationNumber", L"LicenseSerialNumber");
    // Else, for evaluation, set only evaluation serial number
    _TalkListen->SetLicense(L"", L"EvaluationSerialNumber");
    // Create synthesizer
    CSAPI5Synthesizer* _Synthesizer = _TalkListen->CreateSAPI5Synthesizer();
    if (_Synthesizer != NULL)
    {
        _Synthesizer->Talk(L"This is the easiest way to synthesize.");
    }
    // Create recognizer
    CSAPI5Recognizer* _Recognizer = _TalkListen->CreateSAPI5Recognizer();
    if (_Recognizer != NULL)
    {
        wchar_t* pszRecognitionResults = _Recognizer->Listen();
    }
}
                    

// Instantiate TalkListen object
CTalkListen* _TalkListen = new CTalkListen();
if (_TalkListen =! NULL)
{
    // Set license properties
    //_TalkListen->SetLicense("LicenseRegistrationNumber", "LicenseSerialNumber");
    // Else, for evaluation, set only evaluation serial number
    _TalkListen->SetLicense("", "EvaluationSerialNumber");
    // Create synthesizer
    CSAPI5Synthesizer* _Synthesizer = _TalkListen->CreateSAPI5Synthesizer();
    if (_Synthesizer != NULL)
    {
        _Synthesizer->Talk("This is the easiest way to synthesize.");
    }
    // Create recognizer
    CSAPI5Recognizer* _Recognizer = _TalkListen->CreateSAPI5Recognizer();
    if (_Recognizer != NULL)
    {
        String recognitionResults = _Recognizer->Listen();
    }
}
                

var
    _TalkListen: TTalkListen;
    _Recognizer: TSAPI5Recognizer;
    _Synthesizer: TSAPI5Synthesizer;
    recognitionResults: string;
begin
    // Instantiate TalkListen object
    _TalkListen := TTalkListen.Create();
    if (_TalkListen <> nil) then
    begin
        // Set license properties
        //_TalkListen.SetLicense('LicenseRegistrationNumber', 'LicenseSerialNumber');
        // Else, for evaluation, set only evaluation serial number
        _TalkListen.SetLicense('', 'EvaluationSerialNumber');
        // Create synthesizer
        _Synthesizer := _TalkListen.CreateSAPI5Synthesizer();
        if (_Synthesizer <> nil) then
        begin
            _Synthesizer.Talk('This is the easiest way to synthesize.');
        end;
        // Create recognizer
        _Recognizer := _TalkListen.CreateSAPI5Recognizer();
        if (_Recognizer <> nil) then
        begin
            recognitionResults := _Recognizer.Listen();
        end;
    end;
end;
    

// Create TalkListen object
JTalkListen _TalkListen = new JTalkListen();
// Set license properties
//_TalkListen.setLicense("LicenseRegistrationNumber", "LicenseSerialNumber");
// Else, for evaluation, set only evaluation serial number
_TalkListen.setLicense("", "EvaluationSerialNumber");
JSAPI5Synthesizer _Synthesizer = _TalkListen.createSAPI5Synthesizer();
if (_Synthesizer != null)
{
        _Synthesizer.talk("This is the easiest way to synthesize.");
}
JSAPI5Recognizer _Recognizer = _TalkListen.createSAPI5Recognizer();
if (_Recognizer != null)
{
        String recognitionResults = _Recognizer.listen();
}
    

Dim _TalkListen As NTalkListen
Dim _Recognizer As NSAPI5Recognizer
Dim _Synthesizer As NSAPI5Synthesizer
Dim resultsResults As String
    ' Instantiate TalkListen
    _TalkListen = New NTalkListen()
    If (_TalkListen IsNot Nothing) Then
        ' Set license properties
        '_TalkListen.SetLicense("LicenseRegistrationNumber", "LicenseSerialNumber")
        ' Else, for evaluation, set only evaluation serial number
        _TalkListen.SetLicense(String.Empty, "EvaluationSerialNumber")
        _Synthesizer = _TalkListen.CreateSAPI5Synthesizer()
        If (_Synthesizer IsNot Nothing) Then
            _Synthesizer.Talk("This is the easiest way to synthesize.")
        End If
        _Recognizer = _TalkListen.CreateSAPI5Recognizer()
        If (_Recognizer IsNot Nothing) Then
            resultsResults = _Recognizer.Listen()
        End If
    End If
                

Syntax Options

The Talk method has two optional parameters that may be used to control speech synthesis:

  • text - (required) The text to synthesize.
  • name - (optional) The speech synthesizer voice name.
  • async - (optional) True or False for asynchronous synthesis. Note some synthesizers only perform asynchronous synthesis. The default is False.

The Listen method has three optional parameters that may be used to control speech recognition:

  • timeout - (optional) The maximum time to listen in seconds. If the value is 0, listening occurs until speech is recognized.
  • commands - (optional) A comma separated list of phrases to use for recognition.
  • grammar - (optional) The file path of a speech recognition grammar to use for recognition.
  • name - (optional) The speech recognizer name or language.

Development and Deployment

Talk & Listen applications require the Talk & Listen library and the applicable SpeechKit Speech API library:

  • C++Builder, C++, and Delphi applications require the Talk & Listen library (CTalkListen.dll or CTalkListenX64.dll) and the applicable SpeechKit Speech API library in the same directory as the application .exe.
  • Java applications require the talklisten.jar and chant-shared.jar in the target system Java JRE lib directory and/or ensure the classpath includes the path where the talklisten.jar and chant-shared.jar libraries are placed on the target system. The Talk & Listen library (JTalkListen.dll or JTalkListenX64.dll) and the applicable SpeechKit Speech API library must be in the target system Java JRE bin directory.
  • C# and VB .NET applications require the Talk & Listen library (NTalkListen.dll or NTalkListen.dll) to be registered as a COM library on the target system and the applicable SpeechKit Speech API library in the same directory as the application .exe.
  • C# and VB .NET WinRT applications require the assembly libraries (Chant.Shared.WinRT.WindowsMedia.dll and or Chant.TalkListen.WinRT.WindowsMedia.dll) embedded in the application or located in the same directory as the application .exe.

Speech API SpeechKit Speech API class SpeechKit Speech API library
Acapela TTSCAcaTTSSynthesizerCSpeechKit.AcaTTS.dll or CSpeechKitX64.AcaTTS.dll
Cepstral SwiftCSwiftSynthesizerCSpeechKit.Swift.dll or CSpeechKitX64.Swift.dll
CereProc CereVoiceCCereVoiceSynthesizerCSpeechKit.CereVoice.dll or CSpeechKitX64.CereVoice.dll
Microsoft SAPI 5CSAPI5Recognizer or CSAPI5SynthesizerCSpeechKit.SAPI5.dll or CSpeechKitX64.SAPI5.dll
Microsoft Speech PlatformCMSPRecognizer or CMSPSynthesizerCSpeechKit.MSP.dll or CSpeechKitX64.MSP.dll
Microsoft WindowsMediaNWindowsMediaRecognizer or NWindowsMediaSynthesizerNA
Nuance Dragon NaturallySpeakingCDgnRecognizerCSpeechKit.Dgn.dll or CSpeechKitX64.Dgn.dll
Nuance VocalizerCVocalizerSynthesizerCSpeechKit.Vocalizer.dll or CSpeechKitX64.Vocalizer.dll