Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text-to-speech on iPhone [closed]

How difficult would it be to implement something similar to AppleScript's say "words"?
That is to say, is it just a binary link and an import, or something as messy as a libxml implementation?

Edit: My answer solves this.


  • Acapela
    • A serious ripoff
    • €250 for the SDK, and that's not including updates
  • Ivona
    • Site does not present an iOS version with the others
    • Not interested
  • VoiceText
    • Site is ugly and difficult to navigate
    • Not interested
  • OpenEars
    • Open source, a definite plus
    • By far the best offline TTS I've heard of.
  • Flite
    • Super low quality, not worth using
    • Sucks as-is. OE improved on it a lot.
  • Google TTS
    • Good, but requires a network connection
    • Not ideal
like image 458
Thromordyn Avatar asked Jun 14 '11 16:06

Thromordyn


People also ask

Why is my text to speech not working on iPhone?

Make sure dictation is turned on Go to Settings > General > Keyboard. Turn on Enable Dictation.

How do I turn off VoiceOver on my iPhone when its locked?

Turn VoiceOver on or offActivate Siri and say “Turn on VoiceOver” or “Turn off VoiceOver.” If you've set up Accessibility shortcut, triple-click the side button or Home button (depending on your iPhone model). Use Control Center. Go to Settings > Accessibility > VoiceOver, then turn the setting on or off.

How do I turn on text to speech on my iPhone?

Go to Settings > Accessibility > Spoken Content. Adjust any of the following: Speak Selection: To hear text you selected, tap the Speak button. Speak Screen: To hear the entire screen, swipe down with two fingers from the top of the screen.

Why is my voice text not working?

Check the following in your system settings: Look under 'Language & Input'. In some cases it might be under Gboard. Find "Google Voice Typing", make sure it's enabled.


1 Answers

I've looked into this and unfortunately the options are either very expensive or bad quality:

  • Acapela Good quality but expensive.
  • Ivona iOS version and price available on request.
  • VoiceText from NeoSpeech. Price available on request.
  • https://bitbucket.org/sfoster/iphone-tts/ Festival port. Bad quality.

Related to this, here is how you can use Google's online TTS (code taken from iPhone SDK - Google TTS and encoding):

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.mp3"];

NSString *text = @"You are one chromosome away from being a potato.";
NSString *urlString = [NSString stringWithFormat:@"http://www.translate.google.com/translate_tts?tl=en&q=%@",text];
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];
[data writeToFile:path atomically:YES];

AVAudioPlayer  *player;
NSError        *err;
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) 
{    
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:
              [NSURL fileURLWithPath:path] error:&err];
    player.volume = 0.4f;
    [player prepareToPlay];
    [player setNumberOfLoops:0];
    [player play];    
}

The voiceover framework from Apple is private and can only used on for accessibility. At least if you want your application approved. But if you want to use it while you decide on what system to use, here it is:

// Not App Store safe. Only available in real devices.
// See http://arstechnica.com/apple/2010/02/iphone-voiceservices-looking-under-the-hood/

#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];
}
like image 175
Jano Avatar answered Sep 21 '22 16:09

Jano