Created
August 29, 2013 06:28
-
-
Save y0unghe/6374799 to your computer and use it in GitHub Desktop.
用google tts api发音
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
q 要发音的中文或英文词语、句子 | |
tl 发音语言 | |
http://translate.google.com/translate_tts?ie=UTF-8&q=你好&tl=zh-CN&total=1&idx=0&textlen=11&prev=input | |
*/ | |
NSString* userAgent = @"Mozilla/5.0"; | |
NSURL *url = [NSURL URLWithString:[@"http://translate.google.com/translate_tts?ie=UTF-8&q=你好&tl=zh-CN&total=1&idx=0&textlen=11&prev=input" | |
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; | |
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url]; | |
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; | |
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { | |
NSError *playerError = nil; | |
AVAudioPlayer * avPlayerObject = [[AVAudioPlayer alloc] initWithData:data error:&playerError]; | |
if(avPlayerObject) | |
{ | |
NSLog(@"%f", avPlayerObject.duration); | |
[avPlayerObject play]; | |
} else | |
{ | |
NSLog(@"cant't play"); | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
谢谢!有google tts 的文档吗?