您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
#import <AVFoundation/AVFoundation.h> 需要引入
- //获取document目录的路径
- view plain
- - (NSString*) documentsPath {
- if (! _documentsPath) {
- NSArray *searchPaths =
- NSSearchPathForDirectoriesInDomains
- (NSDocumentDirectory, NSUserDomainMask, YES);
- _documentsPath = [searchPaths objectAtIndex: 0];
- [_documentsPath retain];
- }
- return _documentsPath;
- }
- //(document目录的路径)
- NSString *destinationString = [[self documentsPath]
- stringByAppendingPathComponent:filenameField.text];
- NSURL *destinationURL = [NSURL fileURLWithPath: destinationString];
- //初始化AVAudioRecorder
- NSError *recorderSetupError = nil;
- AVAudioRecorder audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationURL
- settings:recordSettings error:&recorderSetupError];
- [recordSettings release];
第二个参数 settings是一个容纳键值对的NSDictionary有四种一般的键
1:一般的音频设置
2:线性PCM设置
3:编码器设置
4:采样率转换设置
NSMutableDictionary 需要加入五个设置值(线性PCM)
- NSMutableDictionary *recordSettings =
- [[NSMutableDictionary alloc] initWithCapacity:10];
- //1 ID号
- [recordSettings setObject:
- [NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
- float sampleRate =
- [pcmSettingsViewController.sampleRateField.text floatValue];
- //2 采样率
- [recordSettings setObject:
- [NSNumber numberWithFloat:sampleRate] forKey: AVSampleRateKey];
-
- //3 通道的数目
- [recordSettings setObject:
- [NSNumber numberWithInt:
- (pcmSettingsViewController.stereoSwitch.on ? 2 : 1)]
- forKey:AVNumberOfChannelsKey];
- int bitDepth =
- [pcmSettingsViewController.sampleDepthField.text intValue];
-
- //4 采样位数 默认 16
- [recordSettings setObject:
- [NSNumber numberWithInt:bitDepth] forKey:AVLinearPCMBitDepthKey];
-
- //5
- [recordSettings setObject:
- [NSNumber numberWithBool:
- pcmSettingsViewController.bigEndianSwitch.on]
- forKey:AVLinearPCMIsBigEndianKey];
-
- //6 采样信号是整数还是浮点数
- [recordSettings setObject:
- [NSNumber numberWithBool:
- pcmSettingsViewController.floatingSamplesSwitch.on]
- forKey:AVLinearPCMIsFloatKey]
-
-
- ;
AVAudioRecorder成功创建后,使用他非常直接.它的三个基本方法如下
- -(void) startRecording {
- [audioRecorder record];
- }
- -(void) pauseRecording {
- [audioRecorder pause];
- recordPauseButton.selected = NO;
- }
- -(void) stopRecording {
- [audioRecorder stop];
- }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。