-->

Record all sounds generated by my app in a audio f

2019-02-06 16:34发布

问题:

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.

回答1:

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];
}


回答2:

Use a Screen Recorder, like Camtasia or Fraps. When you want, you can stop the record and extract the sound in multiple formats, and there's no need to use microphone... There are some open-source too...