Last reviewed: 3/23/2024 10:20:28 AM

C++Builder iOS Applications

Develop iOS applications that speak and listen using your favorite version of C++Builder.

The following sections describe the steps for integrating SpeechKit with C++Builder iOS applications.

iOS Development Prerequisites

Verify that you have the necessary iOS development prerequisites and configured them for development per the RAD Studio C++Builder 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

Add the SpeechKit iOS compatible static library to your application project:

  1. Within your C++Builder project, select Project->Add to Project.
  2. Navigate to C:\Program Files\Chant\SpeechKit 13\iOS\lib.
  3. Add libChantSpeechKit.a to the project.

Add static library linking options to your project by selecting Project->Options->Building->C++ Linker->Advanced->Additional Options->Value from "All configurations - iOS Device 64-bit":

-ObjC -bequiet

SpeechKit Units

SpeechKit includes Object Pascal source files iOSapiChantSpeechKit.pas and Chant.SpeechKit.Bridge.pas that serve as a bridge for the C++Builder class to communicate with iOS.

Add the SpeechKit Object Pascal classes to your application project:

  1. Within your C++Builder project, select Project->Add to Project.
  2. Navigate to C:\Program Files\Chant\SpeechKit 13\Delphi\source.
  3. Add iOSapi.ChantSpeechKit.pas and Chant.SpeechKit.Bridge.pas to the project.

SpeechKit Header Files

SpeechKit includes C++ header files comprised of the C++Builder classes that manage speech recognition and speech synthesis.

To access the SpeechKit C++Builder classes within your application, first add a project reference to the C++Builder header include files:

  • Within your C++Builder project, select Project Options.
  • Select the C++Builder compiler options.
  • Add Include path reference to the SpeechKit header files directory: C:\Program Files\Chant\SpeechKit 13\CBuilder\include.

To access the SpeechKit C++Builder classes within your application, add a reference to the Chant shared and SpeechKit header files in your C++Builder application header file. Add event handler declarations and object instance variables to the application declarations.


#include "Chant.Shared.h"
#include "Chant.SpeechKit.h"

private:		// User declarations
	CSpeechKit* _SpeechKit;
	CChantRecognizer* _Recognizer;
	CChantSynthesizer* _Synthesizer;
};
// Event handlers
void Recognition(void* Sender, CRecognitionDictationEventArgs* Args);
void RangeStart(void* Sender, CRangeStartEventArgs* Args);

Add a reference in your C++Builder application source file to access SpeechKit.


#include "Chant.Shared.cpp"
#include "Chant.SpeechKit.cpp"

Object Instantiation

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


// Instantiate SpeechKit object
_SpeechKit = new CSpeechKit();
if (_SpeechKit =! NULL)
{
	// Set credentials
	_SpeechKit->SetCredentials("Credentials");

	// Create recognizer
	_Recognizer = _SpeechKit->CreateChantRecognizer();
	if (_Recognizer != NULL)
	{
		// Register Event Handlers
		_Recognizer->SetRecognitionDictation(Recognition);
	}

	// Create synthesizer
	_Synthesizer = _SpeechKit->CreateChantSynthesizer();
	if (_Synthesizer != NULL)
	{
		// Register Event Handlers
		_Synthesizer->SetRangeStart(RangeStart);
	}
}

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.


void Recognition(void* Sender, CRecognitionDictationEventArgs* Args)
{
	if ((Args != NULL) && (Args->GetText().Length() > 0))
	{
		...
	}
}

void RangeStart(void* Sender, CTTSRangeStartEventArgs* Args)
{
	if (Args != NULL)
	{
		int location = Args->GetLocation();
		int length = Args->GetLength();
		...
	}
}

Development and Deployment Checklist

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

Sample Projects

C++Builder iOS sample projects are installed at the following location:

  • Documents\Chant\SpeechKit 13\CBuilder.