Voice over Bluetooth in iOS

I have been researching for four days, but I have not found a solution for calling via Bluetooth between two iOS devices at a distance.

I found that audio streaming is possible between two iOS devices using a gateway, but that does not help me. I want to communicate in real time between two devices via Bluetooth.

Is there a CO-DAC for voice over Bluetooth?

My code is:

     var engine = AVAudioEngine()
        var file: AVAudioFile?
        var player = AVAudioPlayerNode()
        var input:AVAudioInputNode?
        var mixer:AVAudioMixerNode?

override func viewDidLoad() {
        super.viewDidLoad()
        mixer = engine.mainMixerNode
        input = engine.inputNode  
        engine.connect(input!, to: mixer!, format: input!.inputFormat(forBus: 0))
}

@IBAction func btnStremeDidClicked(_ sender: UIButton) {
mixer?.installTap(onBus: 0, bufferSize: 2048, format: mixer?.outputFormat(forBus: 0), block: { (buffer: AVAudioPCMBuffer, AVAudioTime) in
            let byteWritten = self.audioBufferToData(audioBuffer: buffer).withUnsafeBytes {
                self.appDelegate.mcManager.outputStream?.write($0, maxLength: self.audioBufferToData(audioBuffer: buffer).count)
            }
            print(byteWritten ?? 0)
            print("Write")
        })
        do {
            try engine.start()
        }catch {
            print(error.localizedDescription)
        }
}

func audioBufferToData(audioBuffer: AVAudioPCMBuffer) -> Data {
        let channelCount = 1
        let bufferLength = (audioBuffer.frameCapacity * audioBuffer.format.streamDescription.pointee.mBytesPerFrame)

        let channels = UnsafeBufferPointer(start: audioBuffer.floatChannelData, count: channelCount)
        let data = Data(bytes: channels[0], count: Int(bufferLength))

        return data
    }

Thanks in Advance :)

0
source share
1 answer

Why doesn't MultipeerConnectivity help you? This is a great way to stream audio via Bluetooth or even Wi-Fi.

When you call this:

audioEngine.installTap(onBus: 0, bufferSize: 17640, format: localInputFormat) {
    (buffer, when) -> Void in

, AVAudioPCMBuffer. NSData outputStream, :

data = someConverstionMethod(buffer)
_ = stream!.write(data.bytes.assumingMemoryBound(to: UInt8.self), maxLength: data.length)

NSData AVAudioPCMBuffer, AVAudioPlayer .

.

+2

All Articles