0

這裏是我記錄的代碼現在通過示例UIlable浮點數怎樣才能在麥克風水平聲音輸入IOS,得到浮球液位麥克風updateMesters當麥克風被錄製音頻

我想我會使用這個功能,但如何能我用這個在rec.h & rec.m文件

(無效)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]; 

回答

2

在錄製過程中,你必須定期調用updateMeters,和0123得到的平均功率- (浮點)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