Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record all sounds generated by my app in a audio file (not from mic)

I have a screen that is like an instrument. There are buttons that play sound files.

I want to record the sounds played as user presses the buttons in a single audio file so that i can save that file as mp4 or other audio format.

Can you please guide me how to achieve this in a simple way?

I am able to record using the mic with AVAudioRecorder

As I think, the recording method uses the mic as a source, but I would like it to use the "audio out" equivalent of my app to use as a source.

like image 202
Vaibhav Garg Avatar asked Jun 26 '14 12:06

Vaibhav Garg


1 Answers

You could try using The Amazing Audio Engine. You can install it via Cocoapods

pod 'TheAmazingAudioEngine'

or clone via git

git clone --depth=1 https://github.com/TheAmazingAudioEngine/TheAmazingAudioEngine.git

The sound could be recorded to a file with the help of this.

So if you want to record the apps output simply use a Outputreceiver:

@property (nonatomic, strong) AEAudioController *audioController;
@property (nonatomic, strong) AERecorder *recorder;

...

self.audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES];

...

//start the recording
- (void) beginRecording{
   self.recorder = [[AERecorder alloc] initWithAudioController:self.audioController];
   NSString *documentsFolder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

   //the path to record to
   NSString *filePath = [documentsFolder stringByAppendingPathComponent:@"AppOutput.aiff"];

  //start recording
  NSError *error = NULL;
  if ( ![_recorder beginRecordingToFileAtPath:filePath fileType:kAudioFileAIFFType error:&error] ) {
         //an error occured
         return;
  }

   [self.audioController addOutputReceiver:self.recorder];
}

...

//end the recording
- (void)endRecording {
     [self.audioController removeOutputReceiver:self.recorder];
     [self.recorder finishRecording];
}
like image 164
latonz Avatar answered Sep 19 '22 00:09

latonz