我有一个视图控制器,在.h中,我有:
{
NSString* textToSpeak;
}
@property (nonatomic, strong) AVSpeechSynthesizer* synthesizer;
在我的视图控制器的.m中,我正在使用合成器播放和暂停我创建的预制脚本。
例如:
-(void)userProfileData:(UserProfileData *)userProfileData didReceiveDict:(NSDictionary *)dict
{
NSDictionary* resultsDict = [dict valueForKey:@"result"];
textToSpeak = [resultsDict objectForKey:@"text"];
UIBarButtonItem* pauseItem = [self.navigationItem.rightBarButtonItems objectAtIndex:0];
[pauseItem setEnabled:YES];
[self startSpeaking];
}
-(void)startSpeaking
{
if (!self.synthesizer) {
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;
}
[self speakNextUtterance];
}
-(void)speakNextUtterance
{
AVSpeechUtterance* nextUtterance = [[AVSpeechUtterance alloc] initWithString:textToSpeak];
nextUtterance.rate = 0.25f;
[self.synthesizer speakUtterance:nextUtterance];
}
在创建此合成器之前,我将导航回到父视图控制器并调用dealloc(我有一条log语句以确保它被调用)。但是,一旦添加此合成器,就不再调用dealloc。我想知道为什么会这样以及如何解决它。任何帮助都将是惊人的,谢谢!
解决了问题.. @ChrisLoonam最终您提供了很大的帮助。我只需要事先停止合成器,然后一切都被释放了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句