I created a function to read a text and play it with bottom speaker on the iPhone because the bottom volume is higher than phone call speaker, but it plays with phone call speaker with low volume.
@discardableResult
func speechSentence(_ text: String) -> Bool {
var utterance: AVSpeechUtterance!
let synthesizer = AVSpeechSynthesizer()
utterance = AVSpeechUtterance(string: text)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
synthesizer.speak(utterance)
return true
}
there isn't any other code or configuration on the project.
how can I solve this problem?
I found the problem. I must configured
AVAudioSession
as well. and I just add below line on my code and it worked.the final code is: