I have an iOS app which is producing text to speech (TTS) audio (AVSpeechSynthesizer
). One user is saying that the audio over his car Bluetooth speaker is coming out in "phone mode" (presumably the audio when making or receiving phone calls) as opposed to "music mode" the way that apps like Youtube and the music and maps apps are. This also causes the handling of incoming phone calls not to work properly with the car Bluetooth speaker.
Unfortunately, I am at a loss to understand why, or even that there is a distinction between "phone" and "music" mode. When using the phone's speakers, there is no such problem with handling incoming phone calls. The issue is only with Bluetooth.
The AVAudioSession
initialization code is as follows.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
do {
let session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSession.Category.playAndRecord, options: [.defaultToSpeaker, .allowBluetooth, .allowBluetoothA2DP])
try session.overrideOutputAudioPort(AVAudioSession.PortOverride.none)
try session.setActive(true, options: .notifyOthersOnDeactivation)
} catch let error {
print("audioSession properties weren't set. Error: \(error.localizedDescription)")
}
return true
}
Also, the AVSpeechSynthesizer
code is as follows
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: newText)
synthesizer.speak(utterance)
Is there anything else this code should be doing, or perhaps is doing wrong?
Thanks in advance.