增加AVSpeechSynthesizer()的响度?

问题描述 投票:0回答:1

我正在使用 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)

在较旧的设备上,产生语音的响度非常低。你几乎听不到。

有什么方法可以提高音量吗?

ios text-to-speech avspeechsynthesizer
1个回答
0
投票

我发现在 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)
}
© www.soinside.com 2019 - 2024. All rights reserved.