我正在使用 AVSpeechSynthesizer() 从我的应用程序中朗读文本,如下所示:
if m_synthesizer.isSpeaking {
self.m_synthesizer.stopSpeaking(at: .immediate)
return
}
let utterance = AVSpeechUtterance(string: "Hello World")
utterance.voice = AVSpeechSynthesisVoice(language: Locale(identifier: language).languageCode)
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
utterance.volume = 1.0
self.m_synthesizer.speak(utterance)
在较旧的设备上,产生语音的响度非常低。你几乎听不到。
有什么方法可以提高音量吗?
我发现在 talk(...) 调用之前添加以下几行可以解决问题:
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback, mode: .spokenAudio, options: [])
try audioSession.setActive(true)
} catch {
print(String(localized: "Could not activate audioSession.") + " " + error.localizedDescription)
}