implementing audioPlayerDidFinishPlaying:successfully: in Flite engine
I am using Flite text to speech engine in my project stated here. I am getting values from json url and converting them into speech. But, i want to know how to implement audioPlayerDidFinishPlaying:successfully: delegate method and play the next chunk when it's called in Flitetts file. The audio player must play one object after the other and after completion of playing first value it must get next value and convert it into speech. The corresponding images etc must also load...
Here' the code that i have done so far...
SBJSON *json = [[SBJSON alloc]init];
fliteEngine = [[FliteTTS alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sampleurl.txt"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *jsonstring = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
NSArray *asanasList = [json objectWithString:jsonstring error:nil];
NSArray *asanas =[asanasList objectForKey:@"yogagurubackpain"];
for(NSDictionary *test in asanas)
{
UrlValues *myasanas = [[UrlValues alloc]init];
myasanas.asanatitle = [test objectForKey:@"asanatitle"];
myasanas.asanatranscript = [test objectForKey:@"asanatranscript"];
myasanas.asanapicture = [test objectForKey:@"asanapicture"];
[data.yoga addObject:myasanas];
[myasanas release];
}
UrlValues *asana=[[data yoga]objectAtIndex:0];
self.AsanaName.text = [asana asanatitle];
self.AsanaTranscript.text = [asana asanatranscript];
NSString *imageUrl = [asana asanapicture];
NSString* mapUrl = [imageUrl stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapUrl]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
self.AsanaImage.image = image;
NSString *speak = self.AsanaTranscript.text;
[fliteEngine 开发者_运维百科setVoice:@"cmu_us_rms"];
[fliteEngine speakText:speak];
[fliteEngine setPitch:100.0 variance:11.0 speed:0.4];
[imageData release];
[image release];
[jsonstring release];
[json release];
Plz help me with some sample code or a tutorial so that i can get the task done...
The only way you can call the audioPlayerDidFinishPlaying
delegate method is if the text-to-speech engine uses an AVAudioPlayer
object to play the sound. If it doesn't, then obviously the delegate method won't get called. Instead, you will have to disable it from playing the sound directly and use an AVAudioPlayer
object instead.
There is an example of that here:
http://artofsystems.blogspot.com/2009/02/speech-synthesis-on-iphone-with-flite.html
精彩评论