'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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
