Introduction
A few years ago I was looking for some Objective-C framework which would allow to speech text on iOS devices in our project. In that time i did not find any, but only tree plain speech synth libraries written i C -
eSpeak,
Flite and
Festival.
After couple days of research and attempts to integrate those libraries for iOS SDK I choosed eSpeak and Flite as candidates (I was able to successfully customize only eSpeak and Flite in reasonable time, they supports more languages, Google use eSpeek for its translation serviceā¦).
In next couple of lines is described first speech synthesizer wrapper - ESpeakEngine.
Background
The
ESpeakEngine is Objectice-C static library project containing very light wrapper for eSpeak open source speech synthesizer. It does not add any new features to eSpeak, it only exposes its funcionality as Objective-C class methods and combines this functionality with iOS
AVFoundation Framework (to see all available properties of eSpeak synthesizer, please read documentation on its homepage url). It also uses standard delegate pattern by defining
ESpeakEngineDelegate.
In static library project also exists a test target which contains simple iPhone app. This sample app has only a one screen with the UITextView for text input and the UIButton to start speech syntesis of an entered text.
Using the code
Usage of the ESpeakEngine is very easy, You have to only add a standard dependency on the ESpeakEngine static library project to Your project (simply drag and drop library project file from Finder to Project Navigator):
add path to folder eSpeak_1.0/Classes in Target Build Settings: Header Search Paths:
Link ESpeakEngine binary and AVFundation.Framework:
and link also ESpeakEngine data folder espeak-data - simply drag and drop this folder from referenced eSpeak.xcodeproj project to parent project (to its any group, i drop it in example project to group ESpeakTest/Supporting Files):
Then import the ESpeakEngine header in class which is holding engine instance:
#import "ESpeakEngine.h"
In the
init or the
viewDidLoad method create a new instance of the
ESpeakEngine and set all parameters you want (language, volume, genderā¦ etc.):
- (void)viewDidLoad {
[super viewDidLoad];
engine = [[ESpeakEngine alloc] init];
engine.volume = 1;
[engine setLanguage:@"en"];
}
And finally bind any button touch event to code which calls the ESpeakEngine a speak method:
- (IBAction)speech {
NSString * text = self.textView.text;
[engine speak:text];
}
Points of Interest
No documentation is included in this up-to-date version. Anyhow, the source code is self-explanatory and has altogether only a few hundred lines, also test application is good start point to look for more properties.
Any questions will be answered, feel free to contact me.
History