【问题标题】:AVAudioRecorder 256 Kbps recording in iOSiOS 中的 AVAudioRecorder 256 Kbps 录音
【发布时间】:2016-11-08 09:43:42
【问题描述】:

我想在 iOS (AVAudioRecorder) 中录制音频,代码运行良好

_fileName = [NSString stringWithFormat:@"Record_%@.m4a",[DateAndTimeUtil stringFromDate:[NSDate date] withFormatterString:@"HH_mm_ss_dd_MM_yyyy"]];NSArray *pathComponents = [NSArray arrayWithObjects:
                               [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                               _fileName,
                               nil];

NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Define the recorder setting
NSMutableDictionary *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];

// Initiate and prepare the recorder
audioRecorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];
audioRecorder.delegate = self;
audioRecorder.meteringEnabled = YES;
[audioRecorder prepareToRecord];`

问题是录制的文件显示比特率为 44 Kbps,但我想录制平均比特率为 256Kbps 的音频,首选 AAC 编解码器,但也兼容 MP3 编解码器和 MP4 音频编解码器。

请帮帮我。

【问题讨论】:

    标签: ios iphone cocoa-touch audio-recording avaudiorecorder


    【解决方案1】:
     _fileName = [NSString stringWithFormat:@"Record_%@.mp4",[DateAndTimeUtil stringFromDate:[NSDate date] withFormatterString:@"HH_mm_ss_dd_MM_yyyy"]];
    NSArray *pathComponents = [NSArray arrayWithObjects:
                               [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                               _fileName,
                               nil];
    
    NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
    
    // Setup audio session
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    
    // Define the recorder setting
    NSMutableDictionary *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];
    [recordSetting setValue:[NSNumber numberWithInteger:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];
    [recordSetting setValue:[NSNumber numberWithInt:32] forKey:AVLinearPCMBitDepthKey];
    [recordSetting setValue:[NSNumber numberWithInt:128000] forKey:AVEncoderBitRatePerChannelKey];
    [recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
    [recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVEncoderBitDepthHintKey];
    
    
    // Initiate and prepare the recorder
    audioRecorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];
    audioRecorder.delegate = self;
    audioRecorder.meteringEnabled = YES;
    [audioRecorder prepareToRecord];
    

    通过使用上面的代码,我得到了一个积极的解决方案,因为它能够记录带有比特率信息的音频。音频的比特率接近 256Kbps。

    【讨论】:

      猜你喜欢
      • 2013-08-23
      • 1970-01-01
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多