【发布时间】:2012-09-08 06:39:51
【问题描述】:
我正在实施录音。它适用于 caf 和 wave 格式。但问题是文件大小太大。
那么,谁能帮我录制格式在窗口中播放且文件大小很小的音频。
我试过的代码如下:
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"sound.wave"];
NSLog(@"%@",soundFilePath);
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:8000.0], AVSampleRateKey,
[NSNumber numberWithInt:8], AVLinearPCMBitDepthKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[audioRecorder prepareToRecord];
}
【问题讨论】:
-
以 m4a (MPEG-4 AAC) 格式录制。详情请见stackoverflow.com/questions/4279311/…。
标签: iphone objective-c ios xcode audio-recording