[英]Audio recorded using Audio Queue Services to data
I want to transmit voice from one iPhone to another. 我想将语音从一个iPhone传输到另一个iPhone。 I have established connection between two iPhones using TCP and I have managed to record voice on the iPhone and play it using Audio Queue Services. 我已经使用TCP建立了两个iPhone之间的连接,我已经设法在iPhone上录制语音并使用音频队列服务播放它。 I have also managed to send data between the two iPhones. 我还设法在两个iPhone之间发送数据。 I do this by sending NSData packages. 我这样做是通过发送NSData包。
My next step is to send the audio data to the other iPhone as it is being recorded. 我的下一步是将音频数据发送到正在录制的其他iPhone。 I believe I should do this in the AudioInputCallback
. 我相信我应该在AudioInputCallback
这样做。 My AudioQueueBufferRef
is called inBuffer
and it seems that I want to convert the inBuffer->mAudioData
to NSData and then send the NSData to the other device and then unpack it. 我的AudioQueueBufferRef
被称为inBuffer
,似乎我想将inBuffer->mAudioData
转换为NSData,然后将NSData发送到另一个设备,然后将其解压缩。
Does anyone know if this would be the way to do it and how I can convert my inBuffer->mAudioData
to NSData? 有谁知道这是否可以做到这一点以及如何将我的inBuffer->mAudioData
转换为NSData? Other approaches are also welcome. 其他方法也受到欢迎。
This is my callback method in which I believe I should "grab" the data and send it to the other iPhone: 这是我的回调方法,我相信我应该“抓住”数据并将其发送到其他iPhone:
void AudioInputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions, const AudioStreamPacketDescription *inPacketDescs)
{
RecordState *recordState = (RecordState *)inUserData;
if(!recordState->recording)
return;
OSStatus status = AudioFileWritePackets(recordState->audioFile,
false,
inBuffer->mAudioDataByteSize,
inPacketDescs,
recordState->currentPacket,
&inNumberPacketDescriptions,
inBuffer->mAudioData);
if(status == 0)
{
recordState->currentPacket += inNumberPacketDescriptions;
}
AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
}
您可能需要考虑将音频数据(您的示例显示音频样本指针和字节数)从音频回调保存到另一个队列或FIFO,然后使用单独的网络线程从音频字节创建NSData并发送它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.