【问题标题】:AVSpeechSynthesizer delegates are not calling in iOS 11AVSpeechSynthesizer 代表不在 iOS 11 中调用
【发布时间】:2017-10-13 23:39:20
【问题描述】:

这是我的文字转语音代码。在 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");
}

有人遇到过这个问题吗? 任何帮助将不胜感激。

我正在使用 Xcode 9.0 在 iOS 11.0.3 上进行测试

【问题讨论】:

    标签: ios iphone ios11 avspeechsynthesizer


    【解决方案1】:

    你的synthesizer 对象必须是一个属性才能工作:)。

    要么让您的AVSpeechSynthesizer 实例,即synthesizer,像这样:

    @property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
    

    或者像这样使用读写。

    @property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer;
    

    让我知道这是否有效。

    【讨论】:

    • @MZubairShamshad 在上述两种类型中,哪种类型的属性使用解决了您的问题?
    • @AanchalChaurasia @property (strong, nonatomic) AVSpeechSynthesizer *synthesizer; 确实为我工作
    • @MZubairShamshad 感谢您的回复。
    • 我肯定会支持,一旦我确认它工作正常。
    • 为我工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多