2011-06-17 69 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 

回答