iOS 录音
来源:互联网 发布:分布式日志 java 编辑:程序博客网 时间:2024/04/29 03:38
这是我在2014念8月份整理的估计现在有点改变:
我是采用的AVAudioRecorder这个框架来进行录音
这个录音跟官方网站上的speakHere有些区别,最大的区别是,这个必须要录制完成才能处理文件,而speakhere示例是可以实现边录制边上传的效果。
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
引入框架,这是使用录音功能的基本配备先说明一点,默认AVAudioRecorder录制后的格式是.caf,而大部分的播放器都是不支持这个格式的,下面一段设置是可以让录制格式是wav的格式
NSDictionary *recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0],AVSampleRateKey, //采样率
[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,//采样位数 默认 16
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,//通道的数目
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,//大端还是小端 是内存的组织方式
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,nil];//采样信号是整数还是浮点数
NSURL *recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory()stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@", [NSDatetimeIntervalSinceReferenceDate] * 1000.0, @"wav"]]]; //文件名的设置
//Setup the recorder to use this file and record to it.
AVAudioRecorder *recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder prepareToRecord];
[recorder record];
下面代码应该是当前.m文件加载时候就设置
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error]; //设置音频类别,这里表示当应用启动,停掉后台其他音频
[audioSession setActive:YES error: &error];//设置当前应用音频活跃性
- IOS录音
- iOS 录音
- iOS录音
- iOS 录音
- iOS 录音
- iOS 录音
- iOS录音
- iOS录音
- iOS 录像录音
- 关于ios下录音
- IOS-录音功能
- Cocos2d-x IOS录音
- iOS - 简单录音:
- ios 录音播放问题
- IOS-录音功能
- IOS-录音功能
- ios下录音
- IOS-录音功能
- 谷歌上的cocoa
- 怎样去走下面的日子
- 计算机网络复习
- 《嵌入式系统设计师》笔记之四——嵌入式软件程序设计
- c++ gdb core dump 入门
- iOS 录音
- C++ vector用法
- 线程
- javascript之window对象详解
- spring bean示例
- 【Unity基础知识②】创建C#脚本、Debug.log输出语句
- ACTIVEX网页控件开发及测试
- Tomcat SEVERE: Error listenerStart
- stm32 Flash读写[库函数]