[英]AVSpeechSynthesizer - iOS 12.3 Doesn't work (it works fine with iOS 12.2)
我正在测试 AVSpeechSynthesizer 并查看了大量示例和教程。
它们都可以在 iOS 12.2 上正常工作,但在 iOS 12.3(包括 12.3.1)上不起作用。
有没有人通过这个?
编辑:
我试过运行这个应用程序
https://github.com/kharrison/CodeExamples/tree/master/SpeakEasy
这在我的 iOS 12.3 (XR) 设备上不起作用,而在 iOS 12.2 (7+) 上运行良好。 顺便说一句,这在模拟器上非常有效。
谢谢。
这是一个应该可以工作的示例函数。 您需要先使用以下代码导入 AVKit:
import AVKit
这是一个应该可以工作的演示功能:
func saySomething(utterance: String!) {
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: utterance)
let voice = AVSpeechSynthesisVoice(language: "en-US")
synthesizer.speak(utterance)
utterance.voice = voice
}
然后,您可以通过传入您希望它说出的文本,在任何您想要的地方调用此函数:
saySomething(utterance: "Hello I am a robot")
我自己找到了解决方案。
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
try AVAudioSession.sharedInstance().setActive(true)
从 iOS 12.3 开始,应将音频会话设置为活动状态以使合成器工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.