如何在ios 7中获得麦克风音量?

如何在ios 7中获得麦克风音量?,第1张

概述有一个观点来获得ios 7中的麦克风音量? NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat: 4410 有一个观点来获得ios 7中的麦克风音量
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:                          [NSNumber numberWithfloat: 44100.0],AVSampleRateKey,[NSNumber numberWithInt: kAudioFormatAppleLossless],AVFormatIDKey,[NSNumber numberWithInt: 0],AVNumberOfChannelsKey,[NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil];NSError *error;recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];if (recorder) {    //recorder.delegate = self;    [recorder preparetoRecord];    recorder.meteringEnabled = TRUE;    [recorder record];    levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];} else {    NSLog(@"");// mic error message}- (voID)levelTimerCallback:(NSTimer *)timer {    [recorder updateMeters];    const double Alpha = 0.05;    double peakPowerForChannel = pow(10,(Alpha * [recorder averagePowerForChannel:0]));    db = 20* log10(peakPowerForChannel);    db += taraturaDb;    db = db < 0 ? 0 : db;    lowPassResults = Alpha * peakPowerForChannel + (1.0 - Alpha) * lowPassResults;    if (lowPassResults < 0.95) {        NSLog(@"%f",db);}

这在iOS6中有效,在iOS 7中不起作用

谢谢

解决方法 在初始化AVAudioRecorder之前放置这些行:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];[audioSession setActive:YES error:nil];[[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryRecord error:nil];
总结

以上是内存溢出为你收集整理的如何在ios 7中获得麦克风音量?全部内容,希望文章能够帮你解决如何在ios 7中获得麦克风音量?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1105798.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存