Last reviewed: 3/23/2024 10:22:46 AM

Delphi VCL and FireMonkey Applications

Develop Object Pascal applications that speak and listen using your favorite version of Delphi.

The following sections describe the steps for integrating SpeechKit with Delphi VCL and FireMonkey applications.

SpeechKit Unit

SpeechKit includes an Object Pascal source file Chant.SpeechKit.pas comprised of the Object Pascal classes that manage grammars. It also includes an Object Pascal source file Chant.Shared.pas comprised of common Object Pascal classes that all Chant libraries use.

To access the SpeechKit Object Pascal classes within your application, first add a project reference to the SpeechKit Object Pascal source files:

  1. Within your Delphi project, select Project Options.
  2. Select the Delphi compiler options.
  3. Add Search path reference to the SpeechKit unit source file directory: C:\Program Files\Chant\SpeechKit 13\Delphi\source.
  4. Add unit output path reference to the local directory with a period '.' character.

To access the SpeechKit Object Pascal classes within your application, add a reference to the Chant.Shared and Chant.SpeechKit units in your uses clause.


unit Unit1;

interface

uses
  ..., Chant.Shared, Chant.SpeechKit;

Add an event handler declaration and Object instance variable to the application declarations.


  type
  TForm1 = class(TForm)
    ...
    procedure RecognitionCommand(Sender: TObject; Args: TRecognitionCommandEventArgs);
    procedure WordPosition(Sender: TObject; Args: TWordPositionEventArgs);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  var
  Form1: TForm1;
  _SpeechKit: TSpeechKit;
  _Recognizer: TChantRecognizer;
  _Synthesizer: TChantSynthesizer;

Object Instantiation

Instantiate an instance, set the credentials, and set the event handler message.


// Instantiate SpeechKit object
_SpeechKit := TSpeechKit.Create();
if (_SpeechKit <> nil) then
begin
    // Set credentials
    _SpeechKit.SetCredentials('Credentials');

    // Create recognizer
    _Recognizer := _SpeechKit.CreateChantRecognizer();

    if (_Recognizer <> nil) then
    begin
        // Register Event Handlers
        _Recognizer.RecognitionCommand := RecognitionCommand;
    end;

    // Create synthesizer
    _Synthesizer := _SpeechKit.CreateChantSynthesizer();

    if (_Synthesizer <> nil) then
    begin
        // Register Event Handlers
        _Synthesizer.WordPosition := WordPosition;
    end;
end;

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 TTSTAcaTTSSynthesizerCSpeechKit.AcaTTS.dll or CSpeechKitX64.AcaTTS.dll
Cepstral SwiftTSwiftSynthesizerCSpeechKit.Swift.dll or CSpeechKitX64.Swift.dll
CereProc CereVoiceTCereVoiceSynthesizerCSpeechKit.CereVoice.dll or CSpeechKitX64.CereVoice.dll
Microsoft Azure SpeechTMCSRecognizer or TMCSSynthesizerCSpeechKit.MCS.dll or CSpeechKitX64.MCS.dll
Microsoft SAPI 5TSAPI5Recognizer or TSAPI5SynthesizerCSpeechKit.SAPI5.dll or CSpeechKitX64.SAPI5.dll
Microsoft Speech PlatformTMSPRecognizer or TMSPSynthesizerCSpeechKit.MSP.dll or CSpeechKitX64.MSP.dll
Microsoft WindowsMedia (WinRT C++)TChantRecognizer or TChantSynthesizerCSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll
Microsoft WindowsMedia (WinRT C++)TWindowsMediaRecognizer or TWindowsMediaSynthesizerCSpeechKit.WinRT.dll or CSpeechKitX64.WinRT.dll
Nuance Dragon NaturallySpeakingTDgnRecognizerCSpeechKit.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.


procedure TForm1.RecognitionCommand(Sender: TObject; Args: TRecognitionCommandEventArgs);
begin
    // Get the command properties
    If ((Args <> nil) and (Length(Args.Phrase) > 0)) then
    begin
      ...
    end;
end;

procedure TForm1.WordPosition(Sender: TObject; Args: TWordPositionEventArgs);
var
  startPosition: Integer;
  wordLength: Integer;
begin
    If (Args <> nil) then
    begin
      startPosition := args.Position;
      wordLength := args.Length;
      ...
    end;
end;

Development and Deployment Checklist

When developing and deploying Delphi VCL and FireMonkey 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 Delphi VCL and FireMonkey 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 Delphi VCL and FireMonkey 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

Delphi VCL and FireMonkey sample projects are installed at the following location:

  • Documents\Chant\SpeechKit 13\Delphi.