tags:

views:

40

answers:

1

Hi,

I am designing an app that needs text to speech. I am using the library that is posted here to convert text to speech. I have to retrieve text from Json url, and pass the values to text to speech. I am able to retrieve Json data and convert it to text to speech for the ObjectatIndex 0 using the following code...

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];

Now my problem is how can i go to the next object automatically after completion of the playing of first one. The process must continue for all the objects. The corresponding images etc must load on the page after the text to speech is done for the first one... Plz help me...

A: 

Looking at the source of the linked library, it looks like you'll have to hack a method into FliteTTS.m. If you look at the source, it's using an AVAudioPlayer to play back a generated WAV file. It's also setting itself as the audio player's delegate. If you implement the audioPlayerDidFinishPlaying:successfully: delegate method and play the next chunk when it's called, you should be able to have a semi-continuous text-to-speech stream.

icktoofay
Can u plz help me out with a sample coz i am a newbie to iphone dev.... Plzzzz
Rahul Varma