我正在尝试从麦克风录制的音频中获取 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 采样率。
那么..如何转换或压缩它?