ios 录音生成.aac录音文件
?ios 錄音并生成.aac文件
-(void)creatRecordSubject
{
? ? NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc]init] ;
? ? //設置錄音格式? AVFormatIDKey==kAudioFormatLinearPCM
? ? [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
? ? //設置錄音采樣率(Hz) 如:AVSampleRateKey==8000/44100/96000(影響音頻的質量)
? ? [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey];
? ? //錄音通道數? 1 或 2
? ? [recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
? ? //線性采樣位數? 8、16、24、32
? ? [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
? ? //錄音的質量
? ? [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey];
?? ?
? ? NSString *strUrl = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
? ? //? ? .wave 只有這種格式 容云才能發出去
? ? NSString *pathStr=[NSString stringWithFormat:@"%@/%@record.aac", strUrl,voiceKey];
? ? playUrl = [NSURL fileURLWithPath:pathStr];
? ? NSError *error;
? ? //初始化
?? ?
? ? //設置外音
? ? [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:&error];
? ? [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
?? ?
?? ?
? ? recorder = [[AVAudioRecorder alloc]initWithURL:playUrl settings:recordSetting error:&error];
?? ?
? ? //? ? ? ? 錄音前的節奏
? ? if(recorder)
? ? {
? ? ? ? [recorder prepareToRecord];
? ? ? ? [recorder record]; ?
? ? ? ? recorder.meteringEnabled=YES;
? ? }
}
關閉錄音
if(recorder)
? ? {
? ? ? ? [recorder stop];
? ? ? ? recorder=nil;
? ? }
? ??
總結
以上是生活随笔為你收集整理的ios 录音生成.aac录音文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言fltk图形库,FLTK编程模型
- 下一篇: 机器学习之数据集