AVAUDIORECORDER检测中的问题

时间:2011-06-17 13:26:38

标签: iphone audio 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

1 个答案:

答案 0 :(得分:0)