Post

Replies

Boosts

Views

Activity

Why AVSpeechSynthesizer object method speakUtterance only worked when object declared by @property
@interface MineViewController () @property (nonatomic, strong) AVSpeechSynthesizer *speechSynthesizer; @end @implementation MineViewController (void)speak { //version1 self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init]; self.speechSynthesizer.delegate = self; AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"12345678"]; AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]; [utterance setVoice:voice]; //(worked speakUtterance successed) [self.speechSynthesizer speakUtterance:utterance]; //version2 AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init]; speechSynthesizer.delegate = self; AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"12345678"]; AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]; [utterance setVoice:voice]; //(not worked speakUtterance no response) [speechSynthesizer speakUtterance:utterance]; } @end
1
0
528
Apr ’22