2012-08-07 29 views
0

我正在使用AVAudioRecorder。如果我点击录制按钮,只有在识别出语音后才能录制start/save如何使用iPhone中的AVAudioRecorder识别语音

- (void)viewDidLoad 
{ 
    recording = NO; 
    NSString * filePath = [NSHomeDirectory() 
          stringByAppendingPathComponent:@"Documents/recording.caf"]; 

    NSDictionary *recordSettings = 
    [[NSDictionary alloc] initWithObjectsAndKeys: 
    [NSNumber numberWithFloat: 44100.0],AVSampleRateKey, 
    [NSNumber numberWithInt: kAudioFormatAppleLossless],  
    AVFormatIDKey, 
    [NSNumber numberWithInt: 1],       
    AVNumberOfChannelsKey, 
    [NSNumber numberWithInt: AVAudioQualityMax],   
    AVEncoderAudioQualityKey,nil]; 
    AVAudioRecorder *newRecorder = [[AVAudioRecorder alloc] 
            initWithURL: [NSURL fileURLWithPath:filePath] 
            settings: recordSettings 
            error: nil]; 

    [recordSettings release]; 
    self.soundRecorder = newRecorder; 
    [newRecorder release]; 
    self.soundRecorder.delegate = self; 
    NSLog(@"path is %@",filePath); 
    [super viewDidLoad]; 
} 
- (IBAction) record:(id) sender { 
    if (recording) { 
     [self.soundRecorder stop]; 
     [recordBtn setTitle:@"Record" forState:UIControlStateNormal]; 
     recording = NO;  
    } else { 
     [self.soundRecorder record]; 
     [recordBtn setTitle:@"Stop" forState:UIControlStateNormal]; 
     recording = YES; 

    } 
} 
- (IBAction) play { 
    NSString * filePath = [NSHomeDirectory() 
          stringByAppendingPathComponent:@"Documents/recording.caf"]; 
    AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:filePath] error: nil]; 
    newPlayer.delegate = self; 
    NSLog(@"playing file at url %@ %d",[[newPlayer url] description],[newPlayer play]); 
} 

请帮帮我。

+0

[如何在iPhone中使用AVAudioRecorder检测语音后才能开始/保存录制](http://stackoverflow.com/questions/11825662/how-to-start-save-the-recording-only -after-detecting-voice-using-avaudioreco) – 2015-05-25 05:14:48

回答

1

这是一个具有挑战性的目标。 iOS不包含用于识别语音的智能特性,您将不得不提供一个过滤器或您自己的过滤器来执行此操作。如果您只需要VOX类型支持(即在检测到给定音频水平时开始录制),可以通过使用Audio Toolbox Framework监视音频级别轻松完成。

如果您需要识别语音,您需要专门的识别过滤器来运行您的音频数据。

如果您有这样的过滤器,您可以采取以下两种方法之一:a)只需记录所有内容,然后对所得到的音频数据进行后期处理,以定位识别语音的时间索引,并忽略直至该点的数据(可能将其余数据复制到另一个缓冲区)或b)使用音频工具箱框架实时监控记录的数据。通过语音查找过滤器传递数据,并在过滤器触发时才开始缓冲数据。

实际执行过程相当耗费时间,并且在这里解决的时间太长,但我已经看过书籍和在线的示例代码,您可以从中着手。对不起,我目前没有任何分享链接,但会在不久的将来发布任何内容。

+0

谢谢你的回应... – Valli 2012-09-11 06:00:32