[英]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.