iphone – iOS:录音文件格式
发布时间:2020-12-14 20:06:24 所属栏目:百科 来源:网络整理
导读:我正在实施录音.它与咖啡波形格式.但问题是文件大小太大. 所以,任何人都可以帮助我录制音频格式,也在窗口文件大小很小. 我试过的代码如下: dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask,YES); docsDir = [dirPat
我正在实施录音.它与咖啡&波形格式.但问题是文件大小太大.
所以,任何人都可以帮助我录制音频格式,也在窗口&文件大小很小. 我试过的代码如下: 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]; } 解决方法
我也试图使用AVAudioRecorder以AAC编码格式录制音频,最好在.m4a文件中.我很快能够得到代码记录到一个内核音频文件(.caf)内的AAC,但是我无法使AVAudioRecorder正确格式化.m4a格式.我刚刚在我的应用程序中使用较低级别的音频单元API重写录制代码,而是将其放在后台,并添加到代码中以处理共享音频会话.一旦建立,我回去试图保存为.m4a,它只是工作.
以下是一些示例代码: NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES); NSString *docsDir = [dirPaths objectAtIndex:0]; NSURL *tmpFileUrl = [NSURL fileURLWithPath:[docsDir stringByAppendingPathComponent:@"tmp.m4a"]]; NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: kAudioFormatMPEG4AAC],AVFormatIDKey,[NSNumber numberWithFloat:16000.0],[NSNumber numberWithInt: 1],nil]; NSError *error = nil; AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:tmpFileUrl settings:recordSettings error:&error]; [recorder prepareToRecord]; AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryRecord error:nil]; [session setActive:YES error:nil]; [recorder record]; 然后结束我使用的录音: [recorder stop]; AVAudioSession *session = [AVAudioSession sharedInstance]; int flags = AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivation; [session setActive:NO withFlags:flags error:nil]; 那么可以使用’tmpFileUrl’中的文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |