#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)
v
iew plain
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成功创建后,使用他非常直接.它的三个基本方法如下
view plain
-(void) startRecording {
[audioRecorder record];
}
-(void) pauseRecording {
[audioRecorder pause];
recordPauseButton.selected = NO;
}
-(void) stopRecording {
[audioRecorder stop];
}
分享到:
相关推荐
我在git上也上传了一份https://github.com/yuanjunxiao/ios-AVAudioRecorder-.git
AVAudioRecorder 的使用演示
利用AVAudioRecorder录音 利用AVAudioPlayer播放 AVAudioSession录音权限 简单的录音播放demo,类似微信的按下录音,松开录音完成,并播放。
利用AVAudioRecorder录音 利用AVAudioPlayer播放 AVAudioSession录音权限 简单的录音播放demo,类似微信的按下录音,松开录音完成,并播放。
YZSimpleAudioKit 一些用于 AVAudioPlayer 和 AVAudioRecorder 的“包装类”或自定义类。
1 使用AVAudioRecorder录音成wav文件 2 为了避免录音启动耗时0 5秒(因为我录音时会有个mic图片的gif 发现显示gif显示被延时0 5秒) 所以 开启子线程做录音的operation 3 为了让可恶的android也能使用 需要将wav >...
iOS AVFoundation框架下的AVAudioRecorder录音机的实现。
播放本地音频、AVAudioRecorder和Audio Queue录制音频、拍照等功能
-- IOS利用AVFoundation框架实现录音和播放 (AVAudioSession AVAudioRecorder AVAudioPlayer) -- IOS之分析网易新闻存储数据 CoreData的使用 增删改查 -- IOS二维码扫描Demo -- 18个 ios 项目源代码 -- iOS通讯录...
添加AVFoundation Framework 为使用AVAudioRecorder类,我们需要向项目添加AVFoundation framework: 在项目Groups & Files面板上展开Targets 按Control-点击或右击MicBlow 选择Add > Existing Frameworks… 按下...
在AVFoundation框架中有一个AVAudioRecorder类专门处理录音操作,它同样支持多种音频格式。与AVAudioPlayer类似,你完全可以将它看成是一个录音机控制类,下面是常用的属性和方法: 先来了解下AVAudioRecorder的常用...
音频的录制与播放,进行封装后的单例工具组件。 (1)使用AVAudioRecorder进行录音 (2)使用AVAudioPlayer进行音频播放 SYAudio:https://github.com/potato512/SYAudio
二、使用AVAudioRecorder录音; 三、使用AVAudioPlayer播放,并添加播放动画; 四、使用lame将caf音频转化为mp3; 五、将mp3 转化为 base64编码; 六、查看录音文件大小; 七、删除语音文件;
_recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:audioPath] settings:_recordSetting error:&error]; }else { [_recorder release]; _recorder = [[AVAudioRecorder alloc] ...
AudioJz 音频工具箱 0.8 0.7 0.6 深入探索一些 0.5 ...以下是AVAudioPlayer,AVAudioRecorder 0.2 0.1 把Ray Wenderlich的音频教程,从Swift 2更新到Swift 5,并进行适当的修改,调试 PS: 0.2
上一篇中总结了iOS中音效和音频播放的最基本使用方法,其中音频的播放控制是使用AVFoundation.framework框架中的AVAudioPlayer播放器对象来实现的,而这里音频的录制则是使用了同样框架下的一个叫AVAudioRecorder的...
背景 因为我的公司需要设计到app与硬件的通信,所以去年深入...由于App是通过AVAudioRecorder录制音频,默认格式为pcm,文件比较大,所以不适合用于聊天通信的文件格式,所以最优的选择是转换成amr格式 音频格式转换方式
作者potato512,源码SYAudio,音频的录制与播放,进行封装后的单例工具组件。(1)使用AVAudioRecorder进行录音(2)使用AVAudioPlayer进行音频播放
iOS 8 App Development Essentials takes a modular approach to the subject of iOS 8 application development for both the iPhone and iPad, with each chapter covering a self contained topic area ...
AVAudioRecorder *audioRecorder; } @end 在ViewDidLoad中: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(100, 100, 100, 100); ; button.b