gpt4 book ai didi

objective-c - 在 AVAudioRecorder 中获取 channel 的 AveragePower 和 PeakPower

转载 作者:行者123 更新时间:2023-12-02 21:53:16 25 4
gpt4 key购买 nike

我对这段代码很恼火。 我试图在录制音频时获取averagePowerForChannel和peakPowerForChannel,但每次我都将其获取为0.0

下面是我录制音频的代码:

 NSMutableDictionary *recordSetting =[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat: 22050.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:32],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];

recorder1 = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:audioFilePath] settings:recordSetting error:&err];
recorder1.meteringEnabled = YES;
recorder1.delegate=self;
[recorder1 prepareToRecord];
[recorder1 record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.3f target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];

- (void)levelTimerCallback:(NSTimer *)timer {

[recorder1 updateMeters];

NSLog(@"Peak Power : %f , %f", [recorder1 peakPowerForChannel:0], [recorder1 peakPowerForChannel:1]);
NSLog(@"Average Power : %f , %f", [recorder1 averagePowerForChannel:0], [recorder1 averagePowerForChannel:1]);

}

代码中有什么错误???

最佳答案

我认为你必须在prepareToRecord之后使用属性meteringEnabled。只需将 channel 数指定为 1 的部分注释掉即可。让它使用默认值。希望对您有所帮助。

关于objective-c - 在 AVAudioRecorder 中获取 channel 的 AveragePower 和 PeakPower,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2681780/

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