这是我的文字转语音代码. iOS 11以下的一切工作正常.但是在iOS 11中没有调用委托方法. AVSpeechSynthesizerDelegate准确设置. (因为它在iOS 11下工作) 按下按钮 AVSpeechSynthesizer *synthesizer = [[AVSpee
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进行测试
你的合成器对象必须是一个属性,以便工作:).要么你的AVSpeechSynthesizer实例,这是合成器,如下所示:
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
或者像readwrite一样.
@property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer;
让我知道这个是否奏效.