IOS录音发送
2014-05-14 11:16
417 查看
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
//录音设置
NSMutableDictionary *recordSetting = [[NSMutableDictionary
alloc]init];
//设置录音格式 AVFormatIDKey==kAudioFormatLinearPCM
[recordSetting setValue:[NSNumber
numberWithInt:kAudioFormatMPEG4AAC]
forKey:AVFormatIDKey];
//设置录音采样率(Hz)
如:AVSampleRateKey==8000/44100/96000(影响音频的质量)
[recordSetting setValue:[NSNumber
numberWithFloat:44100]
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:AVAudioQualityHigh]
forKey:AVEncoderAudioQualityKey];
NSString *path=[NSHomeDirectory()
stringByAppendingPathComponent:@"tmp/aaa"];
_recorder=[[AVAudioRecorder
alloc]initWithURL:[NSURL
fileURLWithPath:path] settings:recordSetting
error:nil];
[_recorder
prepareToRecord];
_button=[UIButton
buttonWithType:UIButtonTypeRoundedRect];
_button.frame=CGRectMake(100,
100, 100,
40);
[_button
setTitle:@"发送录音" forState:UIControlStateNormal];
[_button
addTarget:self
action:@selector(begin)
forControlEvents:UIControlEventTouchDown];
[_button
addTarge
acb1
t:self
action:@selector(end)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:_button];
}
- (void)begin{
[_button
setTitle:@"录音中"
forState:UIControlStateNormal];
[_recorder
record];
}
- (void)end{
[_button
setTitle:@"开始录音" forState:UIControlStateNormal];
[_recorder
stop];
NSString *path=[NSHomeDirectory()
stringByAppendingPathComponent:@"tmp/aaa"];
AVAudioPlayer *play=[[AVAudioPlayer
alloc]initWithContentsOfURL:[NSURL
fileURLWithPath:path] error:nil];
[play
play];
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
//录音设置
NSMutableDictionary *recordSetting = [[NSMutableDictionary
alloc]init];
//设置录音格式 AVFormatIDKey==kAudioFormatLinearPCM
[recordSetting setValue:[NSNumber
numberWithInt:kAudioFormatMPEG4AAC]
forKey:AVFormatIDKey];
//设置录音采样率(Hz)
如:AVSampleRateKey==8000/44100/96000(影响音频的质量)
[recordSetting setValue:[NSNumber
numberWithFloat:44100]
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:AVAudioQualityHigh]
forKey:AVEncoderAudioQualityKey];
NSString *path=[NSHomeDirectory()
stringByAppendingPathComponent:@"tmp/aaa"];
_recorder=[[AVAudioRecorder
alloc]initWithURL:[NSURL
fileURLWithPath:path] settings:recordSetting
error:nil];
[_recorder
prepareToRecord];
_button=[UIButton
buttonWithType:UIButtonTypeRoundedRect];
_button.frame=CGRectMake(100,
100, 100,
40);
[_button
setTitle:@"发送录音" forState:UIControlStateNormal];
[_button
addTarget:self
action:@selector(begin)
forControlEvents:UIControlEventTouchDown];
[_button
addTarge
acb1
t:self
action:@selector(end)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:_button];
}
- (void)begin{
[_button
setTitle:@"录音中"
forState:UIControlStateNormal];
[_recorder
record];
}
- (void)end{
[_button
setTitle:@"开始录音" forState:UIControlStateNormal];
[_recorder
stop];
NSString *path=[NSHomeDirectory()
stringByAppendingPathComponent:@"tmp/aaa"];
AVAudioPlayer *play=[[AVAudioPlayer
alloc]initWithContentsOfURL:[NSURL
fileURLWithPath:path] error:nil];
[play
play];
}
@end
相关文章推荐
- iOS 录音并播放,使用AFN发送文件
- ios录音功能的实现
- 在dahdi通道上通过AMI模拟发送DTMF实现录音功能
- ios发送消息 注册消息
- IOS发送带附件的邮件
- IOS发送邮件的方法和开源库
- ios 发送email
- iPhone消息推送机制(Push)实现及通过.net应用程序发送消息给ios应用程序
- ios 发送http协议请求消息
- iOS开发之邮件发送代码
- iOS 录像录音
- iOS系统发送Email的方法
- iOS开发之邮件发送代码
- iOS 录音功能的实现
- iPhone消息推送机制(Push)实现及通过.net应用程序发送消息给ios应用程序
- iOS开发之邮件发送代码
- Unity3D 游戏引擎之IOS高级界面发送消息与Unity3D消息的接收(九)
- IOS私有API 发送sms
- ios开发 录音内部过程
- iOS-调用系统的短信和发送邮件功能,实现短信分享邮件分享