简体   繁体   English

iOS-AVAudioRecorder-使用ADPCM或IMA录制

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

USing these recording settings, I am able to get the AVAudioRecorder to work: 使用这些录制设置,我可以使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;
}

As soon as I change this: 一旦我更改此:

[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,

to this: 对此:

[NSNumber numberWithInt:kAudioFormatAppleIMA4],AVFormatIDKey,

I get the following error: 我收到以下错误:

recorder: NSOSStatusErrorDomain 1718449215 {
}

Which is to say, the audio format is not supported. 也就是说,不支持音频格式。 kAudioFormatUnsupportedDataFormatError

What do I need to do to get ADPCM or IMA to work with AVAudioRecorder? 我需要怎么做才能使ADPCM或IMA与AVAudioRecorder一起使用?

1) Please ensure that you set the session correctly for either Recording (or) Playback (or) Both (ie VOIP) as follows: 1)请确保您为录制(或)回放(或)两者(即VOIP)正确设置了会话,如下所示:

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

2) Use the following code, as this works fine for me (I compress to low quality as I have a messaging app): 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
                               ];

Regards Heider Sati 问候海德·萨蒂

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

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