implementing Queue Services in AV Audio Recorder using Swift

蹲街弑〆低调 提交于 2019-12-11 06:24:59

问题


Is it possible to create a buffer concept similar to AudioQueue services in AVRecorder Framework. In my application , i need to capture the Audio buffer and send it over the Internet. The server connection part is done, but i wanted to know if there is a way to record the voice continuously in the foreground, and pass this audio buffer by buffer at the background to the server using Swift. Comments are appreciated.


回答1:


AVAudioRecorder records to a file, so you can't easily use it to stream audio data out of your app. AVAudioEngine on the other hand can call you back as it captures audio buffers:

var engine = AVAudioEngine()

func startCapturingBuffers() {
    let input = engine.inputNode!
    let bus = 0

    input.installTapOnBus(bus, bufferSize: 512, format: input.inputFormatForBus(bus)) { (buffer, time) -> Void in
        // buffer.floatChannelData contains audio data
    }

    try! engine.start()
}


来源:https://stackoverflow.com/questions/39845026/implementing-queue-services-in-av-audio-recorder-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!