|
|
|
@ -79,6 +79,7 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
private var synthEventAudioCount = 0 |
|
|
|
public var isHeadphones = true |
|
|
|
public var currentRecognitionMode: String = "normal" |
|
|
|
private var previousRecognitionMode: String = "normal" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -415,6 +416,7 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
|
|
|
|
|
|
|
|
public func setPhoneCallMode(mod: String) -> Bool { |
|
|
|
self.previousRecognitionMode = self.currentRecognitionMode |
|
|
|
self.currentRecognitionMode = mod |
|
|
|
self.isHeadphones = detectHeadphonesOutput() |
|
|
|
if isInitialized { |
|
|
|
@ -1359,41 +1361,50 @@ private func applyAudioSessionForTTS() -> Bool { |
|
|
|
let desiredMode: AVAudioSession.Mode |
|
|
|
var desiredOptions: AVAudioSession.CategoryOptions = [] |
|
|
|
|
|
|
|
if self.isTelephonyActive() { |
|
|
|
let isHeadphonesConnected = outputs.contains(where: { $0.portType == .headphones || $0.portType == .headsetMic || $0.portType == .bluetoothA2DP }) |
|
|
|
|
|
|
|
if self.currentRecognitionMode == "phone_call" || self.currentRecognitionMode == "push_to_talk" { |
|
|
|
desiredCategory = .playAndRecord |
|
|
|
if isHeadphonesConnected { |
|
|
|
desiredMode = .voiceChat |
|
|
|
desiredOptions = [.allowBluetooth, .duckOthers] |
|
|
|
} else { |
|
|
|
desiredMode = .videoChat |
|
|
|
desiredOptions = [.allowBluetooth, .defaultToSpeaker] |
|
|
|
} |
|
|
|
} else if self.isTelephonyActive() { |
|
|
|
desiredCategory = .playback |
|
|
|
desiredMode = .default |
|
|
|
desiredOptions.insert(.duckOthers) |
|
|
|
} else if isRecording { |
|
|
|
desiredCategory = .playAndRecord |
|
|
|
if self.currentRecognitionMode == "phone_call" { |
|
|
|
desiredMode = .voiceChat |
|
|
|
desiredOptions.insert(.allowBluetooth) |
|
|
|
} else { |
|
|
|
desiredMode = self.isHeadphones ? .default : .videoChat |
|
|
|
if self.isHeadphones { |
|
|
|
desiredMode = .default |
|
|
|
desiredOptions.insert(.allowBluetooth) |
|
|
|
desiredOptions.insert(.allowBluetoothA2DP) |
|
|
|
} |
|
|
|
if self.isHeadphones { |
|
|
|
if otherAudioPlaying { |
|
|
|
desiredOptions.insert(.duckOthers) |
|
|
|
} |
|
|
|
} else { |
|
|
|
desiredMode = .videoChat |
|
|
|
desiredOptions.insert(.allowBluetooth) |
|
|
|
desiredOptions.insert(.mixWithOthers) |
|
|
|
if !hasHeadphones { |
|
|
|
desiredOptions.insert(.defaultToSpeaker) |
|
|
|
} |
|
|
|
desiredOptions.insert(.defaultToSpeaker) |
|
|
|
} |
|
|
|
} else if hasBluetoothHFP { |
|
|
|
desiredCategory = .playback |
|
|
|
desiredMode = .default |
|
|
|
desiredOptions.insert(.duckOthers) |
|
|
|
} else { |
|
|
|
desiredMode = .voicePrompt |
|
|
|
desiredOptions = [.interruptSpokenAudioAndMixWithOthers, .allowBluetooth] |
|
|
|
} else if hasHeadphones { |
|
|
|
desiredCategory = .playback |
|
|
|
desiredMode = .spokenAudio |
|
|
|
desiredMode = .default |
|
|
|
if otherAudioPlaying { |
|
|
|
desiredOptions.insert(.duckOthers) |
|
|
|
desiredOptions.insert(.interruptSpokenAudioAndMixWithOthers) |
|
|
|
} |
|
|
|
} else { |
|
|
|
desiredCategory = .playback |
|
|
|
desiredMode = .default |
|
|
|
desiredOptions = [.duckOthers] |
|
|
|
} |
|
|
|
|
|
|
|
do { |
|
|
|
@ -1406,7 +1417,7 @@ private func applyAudioSessionForTTS() -> Bool { |
|
|
|
_ = try? audioSession.setPreferredIOBufferDuration(0.02) |
|
|
|
} |
|
|
|
try audioSession.setActive(true) |
|
|
|
if self.currentRecognitionMode == "phone_call", desiredCategory == .playAndRecord, !hasHeadphones { |
|
|
|
if self.currentRecognitionMode == "phone_call", !self.isHeadphones { |
|
|
|
_ = try? audioSession.overrideOutputAudioPort(.speaker) |
|
|
|
} |
|
|
|
break |
|
|
|
|