It is quite a powerful API for text to speech, however it is not very well documented as it is in a private framework. To test out the API follow the following steps:
1. Create the VSSpeechSynthesizer.h file and add it into the project.
Code:#import <foundation/foundation.h> @interface VSSpeechSynthesizer : NSObject { } + (id)availableLanguageCodes; + (BOOL)isSystemSpeaking; - (id)startSpeakingString:(id)string; - (id)startSpeakingString:(id)string toURL:(id)url; - (id)startSpeakingString:(id)string toURL:(id)url withLanguageCode:(id)code; - (float)rate; // default rate: 1 - (id)setRate:(float)rate; - (float)pitch; // default pitch: 0.5 - (id)setPitch:(float)pitch; - (float)volume; // default volume: 0.8 - (id)setVolume:(float)volume; @end |
2. Create and initiate the VSSpeechSynthesizer object in the appropiate area of the code.
Code:VSSpeechSynthesizer *speech = [[NSClassFromString(@"VSSpeechSynthesizer") alloc] init];
3. Adjust the pitch, rate or volume accordingly.
Eg:[speech setRate:(float)1.0];
4. Create the speech in the appropiate area of the code.
Eg:[speech startSpeakingString:@"Hello world, how are you"];
5. Include the private VoiceServices into the frameworks
Eg:Depending on where you install the IPhone SDK, the location of the VoiceServices framework may varies. Usually the VoiceServices framework is in the following directory:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
/System/Library/PrivateFrameworks/VoiceServices.framework/VoiceServices
*Note: The VoiceServies framework only available in the iPhoneOS platform, hence it can only build and run on the actual iPhone device. It can not be run and test on the simulator.
Sample code: