ios - 在 IOS 中使用 AVAudioRecorder 录制声音时音量正在下降

标签 ios volume avaudiorecorder

我正在开发一个应用程序,我在其中使用 .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/

相关文章:

ios - MPMoviePlayer 和 AVAudioRecorder

ios - 调整麦克风输入音量

ios - self.viewController.webView stringByEvaluatingJavaScriptFromString 不起作用

ios - 客户端在收到完整响应 AFNetworking 之前关闭连接

objective-c - Objective-C : Adding Action On Array of Buttons

performance - 如何在AS3中控制声速和音量?

blackberry - 重定向到黑莓手机中的音量设置

c++ - 在 Linux 和 Mac 上处理可移动媒体 USB/CD-ROM 挂载/卸载事件

ios - 锁定设备时记录音频

iPhone 应用程序崩溃且没有日志(仅具有分发配置文件)