Last reviewed: 3/23/2024 10:21:15 AM

Delphi iOS Applications

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

The following sections describe the steps for integrating SpeechKit with iOS Delphi applications.

iOS Development Prerequisites

Verify that you have the necessary iOS development prerequisites and configured them for development per the RAD Studio Delphi documentation.

There may be additional iOS frameworks required by the iOS for an application to use Speech Recognition. To verify or add them to your SDK, select Tools->Options->Deployment->SDK Manager->iOS Device 64-bit.

  1. Scroll through the list to verify or add the following Frameworks to your project:
  • Speech
  • AVFoundation
  • CoreMIDI
  • ImageIO
  • MediaToolbox
  • AudioToolbox
  • CoreAudio
  • IOSurface
  1. Click the Update Local File Cache button to bring them from your device into the C++Builder environment.
  2. Click the Save button to save changes to the environment.

The required Frameworks may change over time as iOS changes. The linker displays messages for missing frameworks.

SpeechKit Libraries

SpeechKit includes an iOS compatible static library required by the SpeechKit Object Pascal classes. Copy the libChantSpeechKit.a to your project folder from C:\Program Files\Chant\SpeechKit 13\iOS\lib (do not add it to the project).

Add static library linking options to your project by selecting Project->Options->Building->Delphi Compiler->Linking->Options passed to the LD Linker->Value from "All configurations - iOS Device 64-bit":

-ObjC -bequiet

SpeechKit Units

SpeechKit includes an Object Pascal source file Chant.SpeechKit.pas comprised of the Object Pascal classes that manage speech recognition and speech synthesis. 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 director: 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 RecognitionDictation(Sender: TObject; Args: TRecognitionDictationEventArgs);
    procedure RangeStart(Sender: TObject; Args: TRangeStartEventArgs);
    private
    { Private declarations }
    _Recognizer: TChantRecognizer;
    _Synthesizer: TChantSynthesizer;
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;
    _SpeechKit: TSpeechKit;

Object Instantiation

Instantiate SpeechKit and set the credentials. For speech recognition, verify permissions, instantiate object, and set callback event handler. For speech synthesis, instantiate object, and optionally set callback event handler(s).


// 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 callback for recognizer speech
        _Recognizer.RecognitionDictation := Recognition;   
    end;

     // Create synthesizer
    _Synthesizer := _SpeechKit.CreateChantSynthesizer();
    if (_Synthesizer <> nil) then
    begin
        // Register callback for range start
        _Synthesizer.RangeStart := RangeStart;
    end;
end;

Permissions

Speech recognition requires the user to grant permission for speech recognition and microphone usage. Add the appropriate permission via version string key values by selecting Project->Options->VerionInfo and setting string values for NSSpeechRecognitionUsageDescription and NSMicrophoneUsageDescription.

Event Callbacks

Event callbacks are the mechanism in which the class object sends information back to the application such as speech recognition occurred, audio playback finished, or there was an error.


procedure TForm1.Recognition(Sender: TObject; Args: TRecognitionDictationEventArgs);
begin
    If ((Args <> nil) and (Length(Args.Text) > 0)) then
    begin
        ...
    end;
end;

procedure TForm1.RangeStart(Sender: TObject; Args: TTTSRangeStartEventArgs);
var
    location: Integer;
    length: Integer;
begin
    If (Args <> nil) then
    begin
        location := Args.Location;
        length := Args.Length;
        ...
    end;
end;

Development and Deployment Checklist

When developing and deploying Delphi iOS applications, ensure you have a valid license from Chant. See the section License for more information about licensing Chant software.

Sample Projects

Delphi iOS sample projects are installed at the following location:

  • Documents\Chant\SpeechKit 13\Delphi.