我正在开发一个应用程序,我在其中使用 .CAF 格式的 AVAudioRecorder 录制声音,一切都很好,但我的问题是当我播放录制的声音时,它的播放音量非常低。不知何故音量会降到最低。尝试了很多解决方案但没有找到解决方案,如果有人有任何想法请告诉我,这对我来说非常重要。 下面是代码片段
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[session setActive:YES error:nil];
// Define the recorder setting
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
[NSString stringWithFormat:@"%@.caf",@"temp"],
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
recorder = [[AVAudioRecorder alloc]initWithURL:outputFileURL settings:recordSetting error:nil];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder recordForDuration:5];
[recorder prepareToRecord];
[recorder record];
最佳答案
好的,您需要做更多的工作才能实现这一目标。一、导入
#import <AudioToolbox/AudioServices.h>
然后,在您的 viewDidLoad 方法中。放这段代码
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),&audioRouteOverride);
关于ios - 在 IOS 中使用 AVAudioRecorder 录制声音时音量正在下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434944/