2012-05-28 3 views
0

안녕하세요 저는 iOS에서 새로운 제품입니다. 특정 작업을 수행하기 전에 먼저 AVAudioRecorder에서 소리를 녹음하고 문제없이 녹음하고 재생할 수 있지만,AVAudioRecorder에서 바이트 가져 오기

@interface recordViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate> 
{ 
    AVAudioRecorder *audioRecorder; 
    AVAudioPlayer *audioPlayer; 
    UIButton *playButton; 
    UIButton *recordButton; 
    UIButton *stopButton; 
} 

기록 : :

-(void) recordAudio { 
    if (!audioRecorder.recording) 
    { 
     playButton.enabled = NO; 
     stopButton.enabled = YES; 
     [audioRecorder record]; 
    } 
} 

재생 :

-(void) playAudio { 
    if (!audioRecorder.recording) 
    { 
     stopButton.enabled = YES; 
     recordButton.enabled = NO; 

     NSError *error; 

     audioPlayer = [[AVAudioPlayer alloc] 
         initWithContentsOfURL:audioRecorder.url 
         error:&error]; 

     audioPlayer.delegate = self; 

     if (error) 
      NSLog(@"Error: %@", [error localizedDescription]); 
     else 
      [audioPlayer play]; 
    } 
} 

호 기록은 여기 내 함수입니다 데이터를 기록에 넣을 수 있습니까? iOS 개발자 API를 검색 한 결과 아무 것도 찾을 수 없었습니다. 고맙습니다.

답변

0

나는이 해결책을 시도하지 않았다. 그러나 이것이 도움이 될 수 있습니다. 시도 해봐.

는 오디오를 녹음하려면 :

itsVoiceRecordedURL = [NSURL fileURLWithPath:[NSString stringWithFormat:<Path of the recorded file to be stored>]]; 
    NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init]; 
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey]; 
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; 

    itsAudioRecorder = [[ AVAudioRecorder alloc] initWithURL:itsVoiceRecordedURL settings:recordSetting error:&error]; 
    [recordSetting release]; 
    [itsAudioRecorder setDelegate:self]; 
    //We call this to start the recording process and initialize 
    //the subsstems so that when we actually say "record" it starts right away. 
    [itsAudioRecorder prepareToRecord]; 
    //Start the actual Recording 
    [itsAudioRecorder record]; 

가 바이트 배열에 녹음 된 오디오 파일을 변환을

NSData *data = [NSData dataWithContentsOfFile:AudioFilePath]; 
NSUInteger len = [data length]; 
Byte *byteData = (Byte*)malloc(len); 
관련 문제