最近升级了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?
网友评论