我有一个像仪器一样的屏幕。有播放声音文件的按钮。
我想将用户按下按钮时播放的声音记录在一个音频文件中,这样我就可以将该文件另存为 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/