audio - Play sound url on local ios -


i want play sound through url of file on machine. use google's tts api, works text. when change text not work. code. please me. lot.

- (void) playsoundsource: (nsstring * )text and: (nsstring *) codelang  {  nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *path = [documentsdirectory stringbyappendingpathcomponent:@"nhac.mp3"]; nslog(@"%@", path); nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsstring *texts = @"swift powerful , intuitive programming language macos, ios, watchos , tvos. writing swift code interactive , fun,"; //@"you 1 chromosome away being potato."; nsstring *urlstring = [nsstring stringwithformat:@"http://translate.google.com/translate_tts?tl=%@&q=%@&client=tw-ob",codelang, text]; nsurl *url = [nsurl urlwithstring:[urlstring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nslog(@"%@", url); 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];  nslog(@"%@", error); [data writetofile:path atomically:yes];  nsurl *url2 = [nsurl fileurlwithpath:path]; nslog(@"%@", url2);  audioservicescreatesystemsoundid((__bridge cfurlref)url2, &soundid); audioservicesplaysystemsound (soundid);  [filemanager removeitematurl:url2 error:nil]; [filemanager removeitematpath:path error:nil]; 

}


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -