加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 在录制mac os x sdk期间检测静音

发布时间:2020-12-16 07:09:40 所属栏目:百科 来源:网络整理
导读:在录音期间,我一直在努力探测沉默. 我成功录制和播放录制的音频,但不知道静音检测. 录音时,我使用过:https://github.com/darcyliu/CocoaSampleCode/tree/master/AVCaptureToAudioUnitOSX 适用于核心音频api. 任何帮助对我来说都是一个福音. 谢谢 解决方法
在录音期间,我一直在努力探测沉默.

我成功录制和播放录制的音频,但不知道静音检测.

录音时,我使用过:https://github.com/darcyliu/CocoaSampleCode/tree/master/AVCaptureToAudioUnitOSX
适用于核心音频api.

任何帮助对我来说都是一个福音.

谢谢

解决方法

您可以使用AVAudioRecorder,但这不是解决问题的完美方式.

NSDictionary *settings =@{AVSampleRateKey:@(22050.0),AVFormatIDKey:@(kAudioFormatLinearPCM),AVNumberOfChannelsKey:@(1),AVEncoderAudioQualityKey:@(AVAudioQualityMax),AVLinearPCMBitDepthKey:@(32),AVLinearPCMIsBigEndianKey:@(NO),AVLinearPCMIsFloatKey:@(NO)};
AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:@"/dev/null"] settings:setting error:nil];
[recorder prepareToRecord];
[recorder setMeteringEnabled:YES];
[recorder record];
NSTimer *levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.3f target:self selector:@selector(levelTimerCallback:) userInfo:nil repeats:YES];

然后在levelTimerCallback:方法中

[recorder updateMeters];
CGFloat peak = [recorder peakPowerForChannel:0]
CGFloat average = [recorder averagePowerForChannel:0];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读