gpt4 book ai didi

ios - 如何在 iOS 7 中获取麦克风音量?

转载 作者:可可西里 更新时间:2023-11-01 03:06:56 29 4
gpt4 key购买 nike

在 iOS 7 中有获取麦克风音量的 View 吗?

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 - 如何在 iOS 7 中获取麦克风音量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18853990/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com