ios - AVSpeechUtterance 和 Swift 中没有语音/语音缺失

标签 ios swift xcode avspeechsynthesizer avspeechutterance

我目前正在使用 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/

相关文章:

objective-c - 使用委托(delegate)在 UIPopoverViewController 和 MainViewController 之间进行通信

ios - iOS7 中的 UIAlertView 在关闭时锁定显示

iphone - 在 Bump Api 发送图像方面需要一些帮助

ios - Swift 中的本地通知 ios

swift - SearchController - 我不希望在用户尚未开始输入时显示数据

ios - TableView 不填充对象

xcode - 游戏延迟: Node count on Xcode simulator vs Node count on my iPhone 5S?

swift - NSURLConnection 到 NSURLSession

ios - React-Native 和 xcode 10 - 将 Base SDK 设置为 12.1 但编译为 11

ios - 组织我的第一个 iOS 应用程序的用户界面