녹음

2011-10-29 4 views
-1

가능한 중복 시작하기 전에 3 초 지연을 보여주는 avaudiorecorder :
Delay in Recording using avaudiorecorder녹음

내가 iOS5를를 사용 Xcode4에 응용 프로그램을 실행하고를하고, 문제에 직면하는 것은 3의 지연이있다 초를 눌러 실제 녹음을 시작하십시오. 나는 모든 것을 찾고 havent는 나를 위해 좋은 해결책을 찾았다.

여기에 코드

-(void) recordBtnClick:(UIButton *)sender 

    {  

     if (!recordBtn && !playBtn) 
     { 
      NSLog(@"recording pressed"); 

      [recordButton setBackgroundImage:[UIImage imageNamed:@"stop.png"]    forState:UIControlStateNormal]; 

      recordBtn=YES; 

     //startRecording; 

     // 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:16000.0] forKey: AVSampleRateKey]; 
     [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]; 
    } 
    else 
    { 
     NSNumber *formatObject; 

     switch (recordEncoding) { 
      case (ENC_AAC): 
       formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC]; 
       break; 
      case (ENC_ALAC): 
       formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless]; 
       break; 
      case (ENC_IMA4): 
       formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4]; 
       break; 
      case (ENC_ILBC): 
       formatObject = [NSNumber numberWithInt: kAudioFormatiLBC]; 
       break; 
      case (ENC_ULAW): 
       formatObject = [NSNumber numberWithInt: kAudioFormatULaw]; 
       break; 
      default: 
       formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4]; 
     } 

     [recordSettings setObject:formatObject forKey: AVFormatIDKey]; 
     [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey]; 
     [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey]; 
     [recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey]; 
     [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; 
     [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey]; 
    } 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *recDir = [paths objectAtIndex:0]; 
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audio%d.wav",recDir,nextCount]]; 

    NSError *error = nil; 
    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error]; 
    audioRecorder.delegate=self; 
    if(!audioRecorder){ 
     NSLog(@"recorder: %@ %d %@", [error domain], [error code], [[error userInfo] description]); 
     UIAlertView *alert = 
     [[UIAlertView alloc] initWithTitle: @"Warning" 
            message: [error localizedDescription] 
            delegate: nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     return; 
    } 

    //prepare to record 
    [audioRecorder prepareToRecord]; 
    //audioRecorder.meteringEnabled = YES; 

    BOOL audioHWAvailable = audioSession.inputIsAvailable; 
    if (! audioHWAvailable) { 
     UIAlertView *cantRecordAlert = 
     [[UIAlertView alloc] initWithTitle: @"Warning" 
            message: @"Audio input hardware not available" 
            delegate: nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil]; 
     [cantRecordAlert show]; 
     [cantRecordAlert release]; 
     return; 
    } 
    [audioRecorder recordForDuration:(NSTimeInterval) 25]; 


    NSLog(@"recording"); 
    // ---------------- record code finished ----------------// 
    }else{ 
    [recordButton setBackgroundImage:[UIImage imageNamed:@"record.png"] forState:UIControlStateNormal]; 
    recordBtn=NO; 
    [audioRecorder stop]; 
    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; 


    } 

} 
+0

추가 정보를 입력하지 않고 질문을 다시 게시하지 마십시오. 의견을 처음 들었을 때부터 제기 된 우려 사항을 해결하십시오. –

+0

실제로 귀고리 하나는 닫혔다. 그래서 나는 새로운 질문을하기로 결정한 어떤 도움 양식을 얻지 못했다. –

답변

1

에게 있습니다 수행 기록하고 앱의 녹화 버튼을 표시하기 전에 그 전에 필요한 모든 초기화 준비합니다.

+0

그것의 페이지 기반 애플 리케이션 그래서 나는 모든 페이지에 고유하게 소리를 녹음해야한다, 나는 사용자가 기록 버튼을 터치 할 때마다 초기화 과정을 호출해야한다! –

+1

오디오 세션을 복제하거나 초기화 코드를 기록 할 필요가 없습니다. – hotpaw2

+0

applicationDidFinishLunching 또는 viewDidLoad 메서드에서 레코드 코드를 초기화하는 경우 처음으로 소리를 녹음 할 수 있습니다. –