【发布时间】:2011-02-02 18:33:28
【问题描述】:
我在这里按照本指南进行后台处理:
只有 1 行代码用于后台处理:
sound = flite_text_to_wave([cleanString UTF8String], voice);
但由于某种原因,我的访问信号不好。
调试它表明它也在该行崩溃。这是我现在在该部分中的代码。请记住,其中大部分只是 sfoster 项目中的默认 Flite 东西,以前没有问题,当它们全部放在一起时,没有分成 3。
-(void)speakText:(NSString *)text //This is called by my app
{
cleanString = [NSMutableString stringWithString:@""];
if([text length] > 1)
{
int x = 0;
while (x < [text length])
{
unichar ch = [text characterAtIndex:x];
[cleanString appendFormat:@"%c", ch];
x++;
}
}
if(cleanString == nil)
{ // string is empty
cleanString = [NSMutableString stringWithString:@""];
}
//The next line i've put in from the link
[self performSelectorInBackground:@selector(backgroundTextToSpeech) withObject:nil];
}
-(void)backgroundTextToSpeech {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
//The following line is the one it crashes on
sound = flite_text_to_wave([cleanString UTF8String], voice);
[self performSelectorOnMainThread:@selector(backToForegroundTextToSpeech) withObject:nil waitUntilDone:YES];
[pool release];
}
-(void)backToForegroundTextToSpeech {
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *recordingDirectory = [filePaths objectAtIndex: 0];
// Pick a file name
tempFilePath = [NSString stringWithFormat: @"%@/%s", recordingDirectory, "temp.wav"];
// save wave to disk
char *path;
path = (char*)[tempFilePath UTF8String];
cst_wave_save_riff(sound, path);
// Play the sound back.
NSError *err;
[audioPlayer stop];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:tempFilePath] error:&err];
[audioPlayer setDelegate:self];
[audioPlayer prepareToPlay];
}
任何想法我做错了什么/我可以做些什么来阻止这种情况发生?
编辑:修改后的调试器图片,下面发布了一些代码:
【问题讨论】:
标签: iphone objective-c xcode background-process