Can we do like this in iOS?
1 – Speak from iOS device microphone & listen to External bluetooth connected device like Bluetooth speaker / Airplay to Macbook Air / Mac mini ETC device without any echo.
Here is my current code for reference I can able to connect to External bluetooth connected device like Bluetooth speaker / Airplay to Macbook Air / Mac mini but with echo so could not listen properly.
class Sound {
private var session: AVAudioSession {
AVAudioSession.sharedInstance()
}
private let engine = AVAudioEngine()
var inputNode: AVAudioInputNode!
init() {
setupAudioSession()
}
func setupAudioSession() {
do {
try session.setCategory(.playAndRecord,options: [.allowBluetoothA2DP,.allowAirPlay,.duckOthers])
try session.setActive(true)
} catch {
print("Could not configure and activate session. (error)")
}
}
func startListening() {
inputNode = engine.inputNode
do {
try session.setCategory(.playAndRecord, mode: .voicePrompt, options: [.allowBluetoothA2DP,.allowAirPlay,.duckOthers]) // For listening self
try session.setActive(true)
try inputNode.setVoiceProcessingEnabled(true)
} catch {
print("Audio session setup error: (error)")
}
let format = inputNode.inputFormat(forBus: 0)
let outputNode = engine.outputNode
print(outputNode.isVoiceProcessingEnabled)
inputNode.isVoiceProcessingBypassed = false
inputNode.isVoiceProcessingInputMuted = false
inputNode.isVoiceProcessingAGCEnabled = true
engine.connect(inputNode, to: outputNode, format: format)
do {
engine.prepare()
try engine.start()
} catch {
print("Audio engine start error: (error)")
}
}
}