ios - 将我的应用程序生成的所有声音记录在音频文件中(不是来自麦克风)

标签 ios xcode audio avaudiorecorder

我有一个像仪器一样的屏幕。有播放声音文件的按钮。

我想将用户按下按钮时播放的声音记录在一个音频文件中,这样我就可以将该文件另存为 mp4 或其他音频格式。

能否请您指导我如何以简单的方式实现这一目标?

我可以使用带有AVAudioRecorder 的麦克风进行录音

正如我所想,录音方法使用麦克风作为源,但我希望它使用与我的应用程序等效的“音频输出”作为源。

最佳答案

您可以尝试使用 The Amazing Audio Engine 。你可以通过 Cocoapods 安装它

pod 'TheAmazingAudioEngine'

或者通过git克隆

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

借助 this 可以将声音录制到文件中.

因此,如果您想记录应用程序输出,只需使用 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];
}

关于ios - 将我的应用程序生成的所有声音记录在音频文件中(不是来自麦克风),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24430307/

相关文章:

ios - 即使存在,XCode也会显示 “missing recommended icon file”

ios - 使用 Swift 5.1 编译的模块无法被 Swift 5.1.2 编译器导入

iphone - 在 iOS 中删除 html 标签和不需要的字符

c# - 通过音频检测单词

java - 如何在java中重复播放音频文件

ios - swift 3 : How do you wrap content in a tableviewcell with multiple labels?

ios - 将图像添加到推文表 - iOS

ios - 如何使 iPhone 4 应用程序适应所有 iOS 尺寸?

audio - MEDIA_ERR_SRC_NOT_SUPPORTED html5 音频问题

iphone - 有没有一种方法可以在 Interface Builder 中实际*视觉设计*双视​​图(横向 + 纵向)?