同时录制和播放音频
我正在尝试同时录制和播放音频。这是代码。它只会录制并稍后播放。我希望它通过扬声器同时播放。任何帮助。我什至不确定我使用的是正确的课程。
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
temporaryRecFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithString:@"VoiceFile"]]];
recorder = [[AVAudioRecorder alloc] initWithURL:temporaryRecFile settings:nil error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
AVAudioPlayer * player = [[AVAudioPlayer alloc] initWithContentsOfURL:temporaryRecFile error:nil];
player.volume = 1;
[player play];
I am trying to make the audio record and play back at the same time. Here is the code. It will only record and play back later. I want it to play back simultaneously over the speakers. Any help. I am not even sure I am using the right classes.
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
temporaryRecFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithString:@"VoiceFile"]]];
recorder = [[AVAudioRecorder alloc] initWithURL:temporaryRecFile settings:nil error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
AVAudioPlayer * player = [[AVAudioPlayer alloc] initWithContentsOfURL:temporaryRecFile error:nil];
player.volume = 1;
[player play];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是用 iPhone 麦克风录音吗?如果您在录制时尝试回放录音,您很可能会收到反馈。麦克风将听到扬声器正在播放的内容并稍有延迟地重新录制。这会像滚雪球一样越滚越大,直到你的录音听起来就像火车失事一样。
Are you recording from the iPhone microphone? Chances are you'll get feedback if you try to play the recording back while recording it. The microphone will hear what the speakers are playing and rerecord it at a slight delay. This would snowball until your recording sounds like a train wreck.
您使用的是正确的类,但我认为您还必须添加 AutioUnits。
苹果有一个示例代码 aurioTouch2 我认为它包含您需要的内容。
You are using correct classes but I think you must add AutioUnits also.
Apple has a sample code aurioTouch2 and I think it contains what you need.