温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ios录音功能

发布时间:2020-07-12 14:49:01 来源:网络 阅读:360 作者:guoleiappleapp 栏目:移动开发

      在iOS的基础类库中, 提供了AVFoundation FrameWork,即Audio/Video基础类库,通过使用这个类库,可以非常容易的在应用程序录制,播放视频,音频等。

在录制前要初始化   AVAudioRecorder *recorder;

//录音设置

   NSMutableDictionary *recordSetting = [[[NSMutableDictionaryalloc]init] autorelease];

//设置录音格式  AVFormatIDKey==kAudioFormatLinearPCM

   [recordSetting setValue:[NSNumbernumberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];

//设置录音采样率(Hz) 如:AVSampleRateKey==8000/44100/96000(影响音频的质量)

   [recordSetting setValue:[NSNumbernumberWithFloat:44100] forKey:AVSampleRateKey];

//录音通道数  1 2

   [recordSetting setValue:[NSNumbernumberWithInt:1] forKey:AVNumberOfChannelsKey];

//线性采样位数  8162432

   [recordSetting setValue:[NSNumbernumberWithInt:16] forKey:AVLinearPCMBitDepthKey];

//录音的质量

   [recordSetting setValue:[NSNumbernumberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];


NSString *strUrl = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

NSURL *url = [NSURLfileURLWithPath:[NSStringstringWithFormat:@"%@/lll.aac", strUrl]];

urlPlay = url;


NSError *error;

//初始化

recorder = [[AVAudioRecorderalloc]initWithURL:url settings:recordSetting error:&error];

//开启音量检测

recorder.meteringEnabled = YES;

recorder.delegate = self;


录制完后保存

- (IBAction)btnUp:(id)sender

{

double cTime = recorder.currentTime;

if (cTime > 2) {//如果录制时间<2 不发送

NSLog(@"发出去");

   }else {

//删除记录的文件

       [recorderdeleteRecording];

//删除存储的

   }

   [recorderstop];

   [timerinvalidate];

}




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI