使用Swift在AV Audio Recorder中实现队列服务 [英] implementing Queue Services in AV Audio Recorder using Swift

查看:56
本文介绍了使用Swift在AV Audio Recorder中实现队列服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 AVRecorder 框架中创建类似于 AudioQueue 服务的缓冲区概念。在我的应用程序中,我需要捕获音频缓冲区并通过Internet发送它。服务器连接部分已经完成,但是我想知道是否有一种方法可以在前台连续录制语音,并使用 Swift
评论表示赞赏。

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.

推荐答案

AVAudioRecorder 记录到文件,因此您无法轻松地使用它来将音频数据流式传输出您的应用。另一方面, AVAudioEngine 可以在捕获音频缓冲区时回叫您:

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()
}

这篇关于使用Swift在AV Audio Recorder中实现队列服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆