2012-08-06 87 views
0

我想写处理录音的控制器。麦克风中有声音时应该录音。与麦克风讲话时录制声音

当按下按钮时,我有录制声音的工作代码。

-(IBAction) startRecording 
{ 
    NSLog(@"startRecording"); 
    audioRecorder = nil; 

    // Init audio with record capability 
    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; 

    NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10]; 
    // if(recordEncoding == ENC_PCM) 
    //{ 

     [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey]; 
     [recordSettings setObject:[NSNumber numberWithFloat:500.0] forKey: AVSampleRateKey];//44100.0 
     [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey]; 
     [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; 
     [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; 
     [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; 

    // NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]]; 

    NSURL *url = [NSURL URLWithString:[self copyFile:@"recordTest.caf"]]; 



    NSError *error = nil; 
    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error]; 
    [audioRecorder setDelegate:self]; 

    if ([audioRecorder prepareToRecord] == YES){ 
     [audioRecorder record]; 
     NSLog(@"recording"); 
    }else { 
     int errorCode = CFSwapInt32HostToBig ([error code]); 
     NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode); 

    } 

} 

因此,它是可以记录或监控从麦克风输入的声音,并且当声音以上例如1000赫兹开始记录?

我也很喜欢这方面的文献。

谢谢。

回答

0

希望它西港岛线帮助您Download the link

+0

我有这个为例,但它难以阅读。我想要更简单的例子 – Streetboy 2012-08-06 08:51:40

相关问题