作者:撒药拿拉的唐小妄 | 来源:互联网 | 2023-01-13 11:14
这是我的文字转语音代码.iOS 11以下的一切工作正常.但是在iOS 11中没有调用委托方法.
AVSpeechSynthesizerDelegate
准确设置.(因为它在iOS 11下工作)
按下按钮
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
synthesizer.delegate = self;
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:stringToSpeech];
[utterance setRate:AVSpeechUtteranceDefaultSpeechRate];
[utterance setPitchMultiplier:1];
[utterance setVolume:1];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[synthesizer speakUtterance:utterance];
这些是我实现的委托方法.
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"finished");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"Started");
}
有人面对这个问题吗?任何帮助将不胜感激.
我在iOS 11.0.3上使用Xcode 9.0进行测试
1> Glenn..:
你的synthesizer
对象必须是一个可以工作的属性:).
制作你的AVSpeechSynthesizer
实例,synthesizer
就像这样:
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
或者像readwrite一样.
@property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer;
让我知道这个是否奏效.