2011-06-17 115 views
0

我想要檢測任何好友的聲音(注意:我不會按任何按鈕只是感應聲音並開始錄製)用戶可以說話,我的應用程序會自動檢測聲音,當用戶停止說話時,該聲音自動播放..我可以做到這一點,我按錄音,按下按鈕錄製,停止和播放..但我怎麼感覺..它對我來說是一個問題... 這裏是代碼...AVAUDIORECORDER檢測中的問題

#import "recordViewController.h" 

@implementation recordViewController 
@synthesize playButton, stopButton, recordButton; 

-(void) recordAudio 
{ 
    if (!audioRecorder.recording) 
    { 
      playButton.enabled = NO; 
      stopButton.enabled = YES; 
      [audioRecorder record]; 
    } 
} 
-(void)stop 
{ 
    stopButton.enabled = NO; 
    playButton.enabled = YES; 
    recordButton.enabled = YES; 

    if (audioRecorder.recording) 
    { 
      [audioRecorder stop]; 
    } else if (audioPlayer.playing) { 
      [audioPlayer stop]; 
    } 
} 
-(void) playAudio 
{ 
    if (!audioRecorder.recording) 
    { 
     stopButton.enabled = YES; 
     recordButton.enabled = NO; 

     if (audioPlayer) 
       [audioPlayer release]; 
     NSError *error; 

     audioPlayer = [[AVAudioPlayer alloc] 
     initWithContentsOfURL:audioRecorder.url          
     error:&error]; 

     audioPlayer.delegate = self; 

     if (error) 
       NSLog(@"Error: %@", 
       [error localizedDescription]); 
     else 
       [audioPlayer play]; 
    } 
} 
. 
. 
. 
@end 

回答