我将API与以下代码一起使用:
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);它只适用于短句(大约少于10个单词)我做错了什么?我如何才能在不降低语音质量的情况下解决这个问题或将其分成几个文本?
发布于 2013-04-19 09:25:30
谷歌TTS限于100个字符的。
所以你应该把你的长句子分成100个字符的小块,然后把它传递给Google TTS方法。
您可以通过执行以下步骤来实现此目的。
H117递归调用该过程,直到到达最后一个字符。H218G219
下面是我为您创建的库:)
发布于 2013-07-28 12:44:24
Google TTS限制为100个字符。
我最近创建了一个库,它对解决这个问题有很大帮助。有一些改进要做,但请免费使用它。GoogleTTSAPI
https://stackoverflow.com/questions/16057961
复制相似问题