如何设置设置以在KB中获取记录的音频文件大小



我正在研究音频录制和上传。在上传10秒音频时,我正在获取4GB数据时,我浏览并遵循stackoverflow中的一个答案,更改了设置,如下所示,音频文件格式为.3GP,但数据大小未减少。

-(void) startRecording{
[_recordButton setTitle:@"Stop" forState:UIControlStateNormal];
NSError *error;
// Recording settings
NSLog(@"%f", [[AVAudioSession sharedInstance] sampleRate]);
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings setValue: [NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[settings setValue: [NSNumber numberWithFloat:2000.0] forKey:AVSampleRateKey];
[settings setValue: [NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[settings setValue:  [NSNumber numberWithInt: AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];
[settings setValue:[NSNumber numberWithFloat:12000.0] forKey:AVEncoderBitRateKey];
NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath_ = [searchPaths objectAtIndex: 0];
NSString *pathToSave = [documentPath_ stringByAppendingPathComponent:@"AudioName.3gp"];
// File URL
NSURL *url = [NSURL fileURLWithPath:pathToSave];//FILEPATH];
//Save recording path to preferences
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setURL:url forKey:@"Test1"];
[prefs synchronize];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
// Create recorder
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
recorder.delegate=self;
[recorder recordForDuration:10];
[self startTimerToMoveSlider];
}

任何人都可以指导我

最终解决了音频文件大小问题,这是我的录制30秒音频和获取文件大小的代码,接近60kb-70kb。

-(void) startRecording{
[_recordButton setTitle:@"Stop" forState:UIControlStateNormal];
NSError *error;
NSString *pathToSave = [NSString stringWithFormat:@"%@/MySound.m4a", DOCUMENTS_FOLDER];
// File URL
NSURL *url = [NSURL fileURLWithPath:pathToSave];//FILEPATH];
// Recording settings
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                [NSNumber numberWithFloat:8000.0], AVSampleRateKey,
                                [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,[NSNumber numberWithInt:12000],AVEncoderBitRateKey,
                                nil];
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&error];
//Save recording path to preferences
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setURL:url forKey:@"Test1"];
[prefs synchronize];
// Create recorder
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
recorder.delegate=self;
[recorder prepareToRecord];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[recorder recordForDuration:30];//recording for 30secs
[self startTimerToMoveSlider];//to move slider while recording

}

注意:#define documents_folder [nshomedirectory((stringbyAppendingPathcomponent:@" document"]

最新更新