我想从麦克风正在录制的音频中获取PCM数据值的数组..然后,将其发送到服务器,但我不理解如何获取此数据。我试着在“speakHere”示例中找到一些提示,但对我没有帮助,我不想从音频数据包获取任何信息,只需要PCM数据值。有没有人有想法? 这不是从一个文件,我需要得到来自麦克风的音频,让阵列,并将其发送..如何在录音过程中获得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
但我需要8000 SAMPLERATE 8个bitsPerChannel。
那么..如何转换或压缩它?
感谢您的回答@ hptpaw2 ..我试着理解SpeakHere示例,使用我需要的部分,但我不是那么好的开发人员..我真的不懂代码.. – 2011-05-24 20:59:15
@ hotpaw2:你可以帮我修改speakhere的代码,我想从回调中提取数据,我不想把它们写在文件上,但想保留在内存中,即在一个字节数组中,或者所以。我不知道如何提取缓冲区数据并将这些数据附加到字节数组 – 2012-03-14 05:41:05
本网站上可能已经存在关于如何将结构,整数或字节从一个C数组复制到另一个的问答。如果不是,请将其作为一个新问题(不在评论部分中)。 – hotpaw2 2012-03-14 16:21:02