1

我正在尝试从麦克风录制的音频中获取 PCM 数据值数组。然后,将其发送到服务器,但我不明白如何获取这些数据。我试图在“speakHere”样本上找到一些提示,但这对我没有帮助,我不想要音频数据包中的任何信息,只想要 PCM 数据值。有人知道吗?它不是来自文件,我需要从麦克风获取音频,获取阵列并发送它..

由于 speakHere 太复杂了..我尝试了另一种解决方案..

AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];

[session addInput:audioInput];



AVCaptureAudioDataOutput *audioOutput = [[[AVCaptureAudioDataOutput alloc] init] autorelease];
[session addOutput:audioOutput];

// Configure your output. 
dispatch_queue_t audioQueue = dispatch_queue_create("audioQueue", NULL);
[audioOutput setSampleBufferDelegate:self queue:audioQueue];
dispatch_release(audioQueue);

这个实现调用这个方法:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
   fromConnection:(AVCaptureConnection *)connection

但问题是这个输出是用这个配置生成的:

mSampleRate:44100.000000 mFormatID:'lpcm' mBitsPerChannel:16

但我需要 8 bitsPerChannel 的 8000 采样率。

那么..如何转换或压缩它?

4

1 回答 1

0

给定音频队列记录回调函数的缓冲区可以只是 PCM 数据值的 C 数组。Apple 的 SpeakHere 示例应用程序展示了如何配置音频队列数据格式,以及如何接收缓冲区。然后示例应用程序将此 PCM 数据保存到一个文件中,但您可以对数据执行任何您想做的事情(将其排队以进行播放、DSP 分析、音乐可视化、自定义压缩、网络传输等)

另一种方法是使用 Audio Unit RemoteIO 回调来捕获类似的 PCM 值 C 数组,这些值是从同一个麦克风录制的,但延迟略低,设置复杂度略高。有关示例源代码,请参阅 Apple 的 aurioTouch 示例应用程序。

于 2011-05-09T05:22:22.293 回答