简体   繁体   English

使用AVAudioRecorder记录AVAudioPlayer输出

[英]Record AVAudioPlayer output using AVAudioRecorder

In my app the user plays a sound by pressing a button. 在我的应用程序中,用户可以通过按下按钮来播放声音。 There are several buttons which can be played simultaneously. 有几个按钮可以同时播放。 The sounds are played using AVAudioPlayer instances. 使用AVAudioPlayer实例播放声音。 I want to record the output of these instances using AVAudioRecorder. 我想使用AVAudioRecorder记录这些实例的输出。 I have set it all up and a file is created and records but when I play it back it does not play any sound. 我已经全部设置好了,并且创建并记录了一个文件,但是当我播放它时不会播放任何声音。 It is just a silent file the length of the recording. 这只是录音长度的静音文件。 Does anyone know if there is a setting I am missing with AVAudioPlayer or AVAudioRecorder? 有人知道AVAudioPlayer或AVAudioRecorder是否缺少我的设置吗? Thanks 谢谢

It is not possible to record AVAudioPlayer output as input to AVAudioRecorder for recording. 无法将AVAudioPlayer输出记录为输入到AVAudioRecorder进行记录。 You can use audio buffer to store played files and save it to a file. 您可以使用音频缓冲区存储播放的文件并将其保存到文件中。

It would probably be easier to help if we saw your code. 如果我们看到了您的代码,可能会更容易提供帮助。

You should also check out the following link to see if you have your AVAudioRecorder setup correctly: How do I record audio on iPhone with AVAudioRecorder? 您还应该查看以下链接,以查看是否正确设置了AVAudioRecorder: 如何使用AVAudioRecorder在iPhone上录制音频?

Although that link shows how to setup a recording from the mic, it might still be helpful to you. 尽管该链接显示了如何通过麦克风设置录音,但它可能仍然对您有所帮助。

Was facing the same problem. 面临着同样的问题。 Solved the problem by setting the AVAudioSession category to AVAudioSessionCategoryPlayback mode. 通过将AVAudioSession类别设置为AVAudioSessionCategoryPlayback模式解决了该问题。 This is my working code: 这是我的工作代码:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
audioSession.delegate = self;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive: YES error: nil];

Also make sure that the audio recording has been finished successfully by implementing: 通过执行以下操作,还确保音频录制已成功完成:

   -(void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
    NSLog(@"Recording success:%@",flag ? @"YES" : @"NO");
}

And check that you have added <AVAudioSessionDelegate,AVAudioRecorderDelegate,AVAudioPlayerDelegate> 并检查是否已添加<AVAudioSessionDelegate,AVAudioRecorderDelegate,AVAudioPlayerDelegate>

in your interface declaration. 在您的接口声明中。

Hope it helps, at least to look for something else. 希望对您有所帮助,至少寻找其他东西。

I'm having the same issue here, I'm trying to record a mix of different sounds played at different times with a main track playing, what I found is that AVAudioRecorder records only from the mic, so it would work. 我在这里遇到了同样的问题,我试图录制在不同时间播放的不同声音和主音轨的混合音,我发现AVAudioRecorder仅从麦克风录制,因此可以正常工作。

What I found, still have to read doc and test it, is the Audio Converter Services, I think that may work, but I have just read a few lines. 我发现,仍然需要阅读文档并对其进行测试,是Audio Converter Services,我认为这可能有效,但是我只读了几行。

Once again, sorry to tell you, but you're looking the wrong way, I hope my answer helps 再说一次,很抱歉告诉您,但您的方法有误,希望我的回答对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM