2012-04-26 57 views
1

我想在iPhone上做一些演講者驗證(作爲課程項目)。我想知道如何從揚聲器獲得線性PCM。我閱讀關於隊列服務的文檔,似乎它會記錄聲音,然後將其存儲到文件中。有沒有辦法直接從這個線性PCM?文檔中提到了一些有關緩衝區的內容,但我不太明白。也許這是做到這一點的關鍵?如何從iPhone上的錄音中獲取線性PCM?

回答

0
 AVAudioRecorder *audioRecorder = [[AVAudioRecorder alloc] 
        initWithURL:soundFileURL 
        settings:recordSettings 
        error:&error]; 
     audioRecorder.delegate = self; 
     audioRecorder.meteringEnabled = YES; 

然後開始使用的NSTimer如調用定時器拍攝時,你點擊錄音鍵

-(IBAction)record:(id)sender{ 
     NSTimer *recordTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self 
     selector:@selector(recordTimerAction:) userInfo:nil repeats:YES];  
    } 

    -(void)recordTimerAction:(id)sender { 

      [audioRecorder updateMeters]; 
      const double ALPHA = 0.05; 
      double peakPowerForChannel = pow(10, (0.05 * [audioRecorder peakPowerForChannel:0])); 
      lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults; 
      NSLog(@"The Amplitude of the recording Sound is %f",lowPassResults); 
      NSLog(@"The Normal Linear PCM Value is %f",[audioRecorder peakPowerForChannel:0]); 
    } 

//委託方法

-(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder successfully:(BOOL)flag{ 

     [recordTimer invalidate]; 

    } 
+0

的幅度將在範圍從0到1,這可能是有益的 – Bala 2012-04-26 11:32:33

+0

請讓我知道,如果不工作 – Bala 2012-05-01 07:22:34

+0

我發現,蘋果有它的內置INT API這個被稱爲音頻隊列服務。我認爲你的回答是正確的,但內置的API會更好。 – yoyosir 2012-05-04 04:47:35