ios,在麦克风录制音频时获取浮动电平麦克风 updateMesters
Posted
技术标签:
【中文标题】ios,在麦克风录制音频时获取浮动电平麦克风 updateMesters【英文标题】:ios , get float level mic updateMesters when mic is recording audio 【发布时间】:2013-02-17 17:06:25 【问题描述】:这是我现在录制的代码如何通过示例 UIlable 浮点数获取麦克风中输入的电平声音
我想我会使用这个功能,但我如何在 rec.h 和 rec.m 文件中使用它
(void)updateMeters
AVAudiosession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
recordedTmpName = [[NSString alloc] initWithFormat:@"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"aac"];
temporaryRecFile= [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:recordedTmpName]];
recorder = [[ AVAudioRecorder alloc] initWithURL:temporaryRecFile settings:recordSetting error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
【问题讨论】:
【参考方案1】:在录制过程中,您必须定期调用 updateMeters,并通过以下方式获取平均功率 - (float)averagePowerForChannel:(NSUInteger)channelNumber
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];
- (void) handleTimer
[recorder updateMeters];
label.text = [NSString stringWithFormat:@"lf",[recorder averagePowerForChannel:0]];
要查看更多信息,您可以访问AVAudioRecorder Class Reference
【讨论】:
以上是关于ios,在麦克风录制音频时获取浮动电平麦克风 updateMesters的主要内容,如果未能解决你的问题,请参考以下文章