开发工具:
文件大小: 497kb
下载次数: 0
上传时间: 2013-05-24
详细说明: 简单实现TOM猫学说话 - (void)record { if ([self canRecord]) { NSError *error; NSMutableDictionary *_recordSetting = [[NSMutableDictionary alloc] init]; [_recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; [_recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; [_recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey]; [_recordSetting setValue:[NSNumber numberWithInt:AVAudioQua lityMax] forKey:AVEncoderAudioQualityKey]; //_recorderTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithString:@"recording.caf"]]]; //[_recorderTmpFile retain]; if (_recorder == NULL) { _recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:audioPath] settings:_recordSetting error:&error]; }else { [_recorder release]; _recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:audioPath] settings:_recordSetting error:&error]; } [_recorder setMeteringEnabled:YES]; [_recorder setDelegate:self]; [_recorder prepareToRecord]; // [_recorder record]; // NSLog(@"录制中~~~~~~~~~~~~~!!!!"); [_recordSetting release]; }else { NSLog(@"不能录制!!!!"); } } - (void)updateMeters:(NSTimer *)sender { //NSLog(@"~~~~~~~~~~~~~~~~~监听中!!!~~~~~"); //NSLog(@"AVG = %f;peak = %f", [[SCListener sharedListener] averagePower], [[SCListener sharedListener] peakPower]); if ([[SCListener sharedListener] averagePower] > 0.1) { if (!ISRECORDED) { if (!isRecording) { NSLog(@"1开始录制"); isRecording = YES; ISRECORDED = YES; //记录是否录音过声音 _playTimes = 0; //[self record]; [_recorder prepareToRecord]; [_recorder record]; } }else { if (!isPlaying) { if (!isRecording) { NSLog(@"2开始录制"); isRecording = YES; _playTimes = 0; [_recorder prepareToRecord]; [_recorder record]; //[self record]; } } } } if ([[SCListener sharedListener] averagePower] < 0.1) { _lowTimes++; if (_lowTimes >= 5) { //5 次 0.5s======= _lowTimes = 0; isRecording = NO; if (!isRecording & !isPlaying) { if (ISRECORDED) { if (_playTimes < 1) { _playTimes++; NSLog(@"停止录制内容"); [self stopRecord]; isPlaying = YES; } } } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.