ios - Unable to get the audio data through Google TTS Api -
unable response through googletts api.
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *path = [documentsdirectory stringbyappendingpathcomponent:@"file.mp3"];
nsstring *text = @"hello there."; nsstring *urlstring = [nsstring stringwithformat:@"http://www.translate.google.com/translate_tts?tl=en&key=%@&q=%@",google_speech_to_text_key,text]; nsurl *url = [nsurl urlwithstring:[urlstring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nsmutableurlrequest* request = [[nsmutableurlrequest alloc] initwithurl:url] ; [request setvalue:@"mozilla/5.0" forhttpheaderfield:@"user-agent"]; nsurlresponse* response = nil; nserror* error = nil; nsdata* data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; [data writetofile:path atomically:yes]; nsdata *filedata = [nsdata datawithcontentsoffile:path]; _audioplayer = [[avaudioplayer alloc] initwithdata:filedata error:&error]; [_audioplayer preparetoplay];
Comments
Post a Comment