M Z*_*had 4 iphone ios avspeechsynthesizer ios11
这是我的文字转语音代码.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];
Run Code Online (Sandbox Code Playgroud)
这些是我实现的委托方法.
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"finished");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"Started");
}
Run Code Online (Sandbox Code Playgroud)
有人面对这个问题吗?任何帮助将不胜感激.
我在iOS 11.0.3上使用Xcode 9.0进行测试
你的synthesizer对象必须是一个可以工作的属性:).
制作你的AVSpeechSynthesizer实例,synthesizer就像这样:
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
Run Code Online (Sandbox Code Playgroud)
或者像readwrite一样.
@property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer;
Run Code Online (Sandbox Code Playgroud)
让我知道这个是否奏效.
| 归档时间: |
|
| 查看次数: |
899 次 |
| 最近记录: |