我目前正在使用 XCode 9.4.1 和 Swift 组装我的第一个应用程序。在我的代码中,我正在处理一个列表,我希望大声说出列表中的每个值。下面是我的代码
// classificationResults is my list
for returnedValue in self.classificationResults{
let utterance = AVSpeechUtterance(string: returnedValue)
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
utterance.rate = 0.5
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
// print(returnedValue)
在模拟器中运行它时,它可以工作,但它只说允许列表中的第一个或两个值(有 7 个)。当我直接在我的设备上运行它时,没有大声说出来。
有什么想法/建议吗?提前致谢
最佳答案
问题可能出在您的播放器生命周期:要记住的最重要的事情是保留您的AVSpeechSynthesizer
实例直到完整的语音完成。
将您的合成器创建移出循环并使其保持事件状态直到演讲结束:这 answer也可能有所帮助。
关于ios - AVSpeechUtterance 和 Swift 中没有语音/语音缺失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51140607/