美文网首页
AVSpeechSynthesizer 在iOS16上面没有声音

AVSpeechSynthesizer 在iOS16上面没有声音

作者: yhl_asp | 来源:发表于2022-09-20 14:36 被阅读0次

     最近升级了iOS16后 发现 文字转语音 相关功能在新系统上面 没有效果,

    代码如下

     let speech = AVSpeechSynthesizer()

     letavVoice =AVSpeechSynthesisVoice.init(language: isManVoice ?"zh-GB":"zh-CN")

    letutterance =AVSpeechUtterance.init(string: voice)

     utterance.voice= avVoice

    speech.speak(utterance)

    查阅文档发现 升级iOS16之后  不能将 speech声明为局部变量了,要放到方法外部去声明

    下面是网上查到的一段官方回复

    Hey ! I notice that you are declaring the AVSpeechSynthesizer as a local variable above. As soon as an AVSpeechSynthesizer goes out of scope and is deallocated, speech output is stopped. Can you try instead storing the synthesizer as an instance or state variable?

    相关文章

      网友评论

          本文标题:AVSpeechSynthesizer 在iOS16上面没有声音

          本文链接:https://www.haomeiwen.com/subject/kxcvortx.html