tags:

views:

28

answers:

1

Hi,

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...

+1  A: 

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

iWasRobbed
The Flite engine uses an AVAudioPlayer object and even audioPlayerDidFinishPlaying is getting called after the first string is converted to speech. The only thing i want to know is how to use this to go to next string after completion of the first string.
Rahul Varma
Well, one way would be to put code in `audioPlayerDidFinishPlaying` that would load the next URL and feed it through the Flite engine. So basically: the first time it runs it parses the very first URL, in `audioPlayerDidFinishPlaying` it checks if theres another URL to parse and if so, then it parses and plays it. So in that way, you can use `audioPlayerDidFinishPlaying` as a loop.
iWasRobbed
This might get you pointed in the right direction: http://www.iphonedevsdk.com/forum/iphone-sdk-development/27285-play-sequence-audio-files-avaudioplayer.html
iWasRobbed