Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write audio file locally recorded from microphone using AudioBuffer in iPhone?
    text
    copied!<p>I am new to Audio framework, anyone help me to write the audio file which is playing by capturing from microphone?</p> <p>below is the code to play mic input through iphone speaker, now i would like to save the audio in iphone for future use.</p> <p>i found the code from here to record audio using microphone <a href="http://www.stefanpopp.de/2011/capture-iphone-microphone/" rel="nofollow">http://www.stefanpopp.de/2011/capture-iphone-microphone/</a></p> <pre><code>/** Code start from here for playing the recorded voice */ static OSStatus playbackCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { /** This is the reference to the object who owns the callback. */ AudioProcessor *audioProcessor = (AudioProcessor*) inRefCon; // iterate over incoming stream an copy to output stream for (int i=0; i &lt; ioData-&gt;mNumberBuffers; i++) { AudioBuffer buffer = ioData-&gt;mBuffers[i]; // find minimum size UInt32 size = min(buffer.mDataByteSize, [audioProcessor audioBuffer].mDataByteSize); // copy buffer to audio buffer which gets played after function return memcpy(buffer.mData, [audioProcessor audioBuffer].mData, size); // set data size buffer.mDataByteSize = size; // get a pointer to the recorder struct variable Recorder recInfo = audioProcessor.audioRecorder; // write the bytes OSStatus audioErr = noErr; if (recInfo.running) { audioErr = AudioFileWriteBytes (recInfo.recordFile, false, recInfo.inStartingByte, &amp;size, &amp;buffer.mData); assert (audioErr == noErr); // increment our byte count recInfo.inStartingByte += (SInt64)size;// size should be number of bytes audioProcessor.audioRecorder = recInfo; } } return noErr; } </code></pre> <p>-(void)prepareAudioFileToRecord{</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *basePath = ([paths count] &gt; 0) ? [paths objectAtIndex:0] : nil; NSTimeInterval time = ([[NSDate date] timeIntervalSince1970]); // returned as a double long digits = (long)time; // this is the first 10 digits int decimalDigits = (int)(fmod(time, 1) * 1000); // this will get the 3 missing digits // long timestamp = (digits * 1000) + decimalDigits; NSString *timeStampValue = [NSString stringWithFormat:@"%ld",digits]; // NSString *timeStampValue = [NSString stringWithFormat:@"%ld.%d",digits ,decimalDigits]; NSString *fileName = [NSString stringWithFormat:@"test%@.caf",timeStampValue]; NSString *filePath = [basePath stringByAppendingPathComponent:fileName]; NSURL *fileURL = [NSURL fileURLWithPath:filePath]; // modify the ASBD (see EDIT: towards the end of this post!) audioFormat.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; // set up the file (bridge cast will differ if using ARC) OSStatus audioErr = noErr; audioErr = AudioFileCreateWithURL((CFURLRef)fileURL, kAudioFileCAFType, &amp;audioFormat, kAudioFileFlags_EraseFile, &amp;audioRecorder.recordFile); assert (audioErr == noErr);// simple error checking audioRecorder.inStartingByte = 0; audioRecorder.running = true; self.audioRecorder = audioRecorder; </code></pre> <p>}</p> <p>thanks in advance bala</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload