rah*_*hul 5 volume avaudiorecorder ios
我正在开发一个应用程序,我用AVAudioRecorder以.CAF格式录制声音,一切都很好,但我的问题是,当我播放录制的声音时,它的播放量非常低.不知何故声音的音量达到最低水平.尝试了这么多解决方案,但没有找到解决方案,如果有人有任何想法那么请告诉我,这对我来说非常重要.以下是代码段的代码
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];
Run Code Online (Sandbox Code Playgroud)
好的,你需要做更多的事情来实现这一目标.首先,进口
#import <AudioToolbox/AudioServices.h>
Run Code Online (Sandbox Code Playgroud)
然后,在viewDidLoad方法中.把这段代码
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),&audioRouteOverride);
Run Code Online (Sandbox Code Playgroud)
小智 6
使用最新的SDK,它将如下所示:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
Run Code Online (Sandbox Code Playgroud)
SWIFT代码:
let recordingSession:AVAudioSession = AVAudioSession.sharedInstance()
try! recordingSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions:.DefaultToSpeaker)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2969 次 |
| 最近记录: |