Skip to content

Instantly share code, notes, and snippets.

@janodev
Created April 8, 2013 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janodev/5341598 to your computer and use it in GitHub Desktop.
Save janodev/5341598 to your computer and use it in GitHub Desktop.
Text to speech on iOS with private framework.
// Not App Store safe. Only available in real devices.
#define RTLD_LAZY 0x1
#define RTLD_NOW 0x2
#define RTLD_LOCAL 0x4
#define RTLD_GLOBAL 0x8
NSObject *voiceSynthesizer;
void *voiceServices;
-(void) say:(NSString*)text {
if (!voiceSynthesizer)
{
NSString *vsLocation = @"/System/Library/PrivateFrameworks/VoiceServices.framework/VoiceServices";
voiceServices = dlopen(vsLocation.UTF8String, RTLD_LAZY);
voiceSynthesizer = [NSClassFromString(@"VSSpeechSynthesizer") new];
}
[voiceSynthesizer performSelector:@selector(startSpeakingString:) withObject:text];
}
/*
@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: 1
- (id)setRate:(float)rate;
- (float)pitch; // default: 0.5
- (id)setPitch:(float)pitch;
- (float)volume; // default: 0.8
- (id)setVolume:(float)volume;
@end
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment