How Tos

Last reviewed: 12/15/2011

Article ID: H071135

HOW: Developing Delphi applications that speak and listen

The information in this article applies to:

  • SpeechKit 7

Summary

You can develop Delphi applications that speak and listen using your favorite version of Delphi.

More Information

SpeechKit includes a Delphi Pascal source file (.pas) comprised of the Delphi classes that manage audio, recognizers, and synthesizers.

To access the SpeechKit Delphi classes within your application, first add a project reference to the SpeechKit Delphi 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 7\Win32\Delphi\source.
  4. Add unit output path reference to the local directory with a period '.' character.

To access the SpeechKit Delphi classes within your application, add a reference to the ChantShared and SpeechKit units in your uses clause:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ChantShared, SpeechKit;

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

type
TForm1 = class(TForm)
...
private
{ Private declarations }
public
{ Public declarations }
procedure OnHasAudioEvent(var msg: TMessage);
    message WM_APP+1;
procedure OnHasSREvent(var msg: TMessage);
    message WM_APP+2;
procedure OnHasTTSEvent(var msg: TMessage);
    message WM_APP+3;
end;

var
Form1: TForm1;
ChantAudio1: TChantAudio;
ChantSR1: TChantSR;
ChantTTS1: TChantTTS;

Object Instantiation

Instantiate an instance, set the license and serial properties, and set the event handler message.

procedure TForm1.FormCreate(Sender: TObject);
begin
ChantAudio1 := TChantAudio.Create();
ChantSR1 := TChantSR.Create();
ChantTTS1 := TChantTTS.Create();
// Set license properties
ChantAudio1.SetStringProperty(CSPLicense,'LicenseRegistrationNumber');
ChantAudio1.SetStringProperty(CSPSerials,'LicenseSerialNumber');
ChantSR1.SetStringProperty(CSPLicense,'LicenseRegistrationNumber');
ChantSR1.SetStringProperty(CSPSerials,'LicenseSerialNumber');
ChantTTS1.SetStringProperty(CSPLicense,'LicenseRegistrationNumber');
ChantTTS1.SetStringProperty(CSPSerials,'LicenseSerialNumber');

// Define the HasEvent callback message
ChantAudio1.SetWindowMessage(Handle, WM_APP+1, 0, 0);
ChantSR1.SetWindowMessage(Handle, WM_APP+2, 0, 0);
ChantTTS1.SetWindowMessage(Handle, WM_APP+3, 0, 0);

end;

Event Callbacks

Event callbacks are the mechanism in which the component library sends information back to the application such as a headset was plugged in, speech recognition occurred, audio playback finished, or there was an error.

procedure TForm1.OnHasAudioEvent(var msg: TMessage);
var
aTChantAudioEvent: TChantAudioEvent;
i: Integer;
begin
numberOfEvents := ChantAudio1.GetResourceCount(CSREvent,0,0);
for i := 0 to numberOfEvents - 1 do
begin
    // Get the event from the event queue
    aTChantAudioEvent := ChantAudio1.GetChantAudioEvent(0);
    case tEvent.ChantCallback of
    CCDDeviceArrival:
    ...

    end;

    ...

    // Remove the event from the event queue
    ChantAudio1.RemoveResource(CSREvent);
    aTChantAudioEvent.Destroy();
end;
end;

procedure TForm1.OnHasSREvent(var msg: TMessage);
var
aTChantSREvent: TChantSREvent;
i: Integer;
begin
numberOfEvents := ChantSR1.GetResourceCount(CSREvent,0,0);
for i := 0 to numberOfEvents - 1 do
begin
    // Get the event from the event queue
    aTChantSREvent := ChantSR1.GetChantSREvent(0);
    case tEvent.ChantCallback of
    CCSRHasCommand:
    ...

    end;

    ...

    // Remove the event from the event queue
    ChantSR1.RemoveResource(CSREvent);
    aTChantSREvent.Destroy();
end;
end;

procedure TForm1.OnHasTTSEvent(var msg: TMessage);
var
aTChantTTSEvent: TChantTTSEvent;
i: Integer;
begin
numberOfEvents := ChantTTS1.GetResourceCount(CSREvent,0,0);
for i := 0 to numberOfEvents - 1 do
begin
    // Get the event from the event queue
    aTChantTTSEvent := ChantTTS1.GetChantTTSEvent(0);
    case tEvent.ChantCallback of
    CCDAudioStop:
    ...

    end;

    ...

    // Remove the event from the event queue
    ChantTTS1.RemoveResource(CSREvent);
    aTChantTTSEvent.Destroy();
end;
end;

Deployment Checklist

When you are ready to deploy your Delphi application, you need to ensure you have a valid license, bundle the correct Chant component library, and configure your installation properly on the target system. Review the following checklist before deploying your applications:

  • You may deploy your Delphi application to any system with a valid license from the Chant.
  • Copy CSpeechKit.dll to the target system and place in the same directory with your application.

Sample Projects

Delphi sample projects are installed at the following location:

  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS 2007,
  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS 2009,
  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS 2010,
  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS XE,
  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS XE2, and
  • My Documents\Chant SpeechKit 7\Win32\Delphi\RS XE3.