问题
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