Record audio to NSData

simonbs picture simonbs · Dec 13, 2011 · Viewed 7.3k times · Source

I have set up a TCP connection between two iPhones and I am able to send NSData packages between the two. I would like to talk into the microphone and get the recording as an NSData object and send this to the other iPhone. I have successfulyl used Audio Queue Services to record audio and play it but I have not managed to get the recording as NSData. I posted a question about converting the recording to NSData when using Audio Queue Services but it has not got me any further.

Therefore I would like to hear if there is any other approach I can take to speak into the microphone of an iPhone and have the input as raw data?

Update:

I need to send the packages continuous while recording. E.g. every second while recording I will send the data recorded during that second.

Answer

hotpaw2 picture hotpaw2 · Dec 13, 2011

Both Audio Queues and the RemoteIO Audio Unit will give you buffers of raw audio in real-time with fairly low latency. You can take the buffer pointer and the byte length given in each audio callback to create a new block of NSData. RemoteIO will provide the lowest latency, but may require the network messaging to be done outside the callback thread.