繁体   English   中英

iOS-AVAudioRecorder-使用ADPCM或IMA录制

[英]iOS - AVAudioRecorder - recording with ADPCM or IMA

使用这些录制设置,我可以使AVAudioRecorder正常工作:

    recordSetting = [NSDictionary dictionaryWithObjectsAndKeys:
//                     [NSNumber numberWithFloat:2048.0f],AVSampleRateKey,
//                     [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
//                     [NSNumber numberWithInt:8],AVLinearPCMBitDepthKey,
                     [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
//                     [NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
//                     [NSNumber numberWithBool:0], AVLinearPCMIsBigEndianKey,
//                     [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
//                     [NSNumber numberWithInt:256], AVEncoderBitRateKey,
                     [NSData data], AVChannelLayoutKey, nil];


recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];


if(!recorder){
    NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: [err localizedDescription]
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [alert show];

    return;
}

一旦我更改此:

[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,

对此:

[NSNumber numberWithInt:kAudioFormatAppleIMA4],AVFormatIDKey,

我收到以下错误:

recorder: NSOSStatusErrorDomain 1718449215 {
}

也就是说,不支持音频格式。 kAudioFormatUnsupportedDataFormatError

我需要怎么做才能使ADPCM或IMA与AVAudioRecorder一起使用?

1)请确保您为录制(或)回放(或)两者(即VOIP)正确设置了会话,如下所示:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];

2)使用以下代码,因为这对我来说很好用(由于我有消息传递应用程序,因此压缩为低质量):

NSDictionary *AudioSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                               [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey
                               , [NSNumber numberWithFloat:11025.00], AVSampleRateKey
                               , [NSNumber numberWithInt:1], AVNumberOfChannelsKey
                               , [NSNumber numberWithInt:11025], AVEncoderBitRateKey
                               , [NSNumber numberWithInt:8], AVLinearPCMBitDepthKey
                               , [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey
                               , [NSNumber numberWithInt:1], AVNumberOfChannelsKey
                               , nil
                               ];

问候海德·萨蒂

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM