I'm using the API with this code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.mp3"];
NSString *text = textToTranslate; //@"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] ;
[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];
SystemSoundID soundID;
NSURL *url2 = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url2, &soundID);
AudioServicesPlaySystemSound (soundID);
Which works but only on short sentences (less than 10 words approx.) What am I doing wrong? How can I solve that or separate into few texts without reducing the speech quality?
Google TTS is limited to 100 characters.
I recently created a lib that helped a lot with that problem. There are some improvements to be made, but please free to use it. GoogleTTSAPI
Google TTS limited to 100 characters.
So you should split-up your long sentence in to small 100 character chunks and pass it to the Google TTS method.
You can achieve this through implementing below steps.
Here is my Google-TTS-Library-For-iOS library that I created for you :)