Error: Failed to set client format on recorded audio file (-66563) - EZRecorder / EZAudio

702 Views Asked by At

I'm working on an app that uses EZAudio to get audio data from microphone to send it over wifi, then records the received audio data on the 2nd device. Everything works great however when i tried to use EZRecorder from their example file, i get this error: "Error: Failed to set client format on recorded audio file (-66563)". I should mention that the original example code works without an issue on its own but i get an error when i move the code to my project.

Any help is appreciated.

Here's the piece of code that causes this:

-(void)toggleRecording:(id)sender
{
    if (recTest==0)
    {
        [recButton setImage:[UIImage imageNamed:@"rec2.png"] forState:UIControlStateNormal];
        recTest=1;
    }
    else if (recTest==1)
    {
        [recButton setImage:[UIImage imageNamed:@"rec.png"] forState:UIControlStateNormal];
        recTest=0;
    }

    self.playingTextField.text = @"Not Playing";
    if(self.audioPlayer)
    {
        if(self.audioPlayer.playing)
        {
            [self.audioPlayer stop];
        }
        self.audioPlayer = nil;
    }

    if(recTest==1)
    {
        //Create the recorder
        self.recorder = [EZRecorder recorderWithDestinationURL:[self testFilePathURL]
                                                  sourceFormat:self.microphone.audioStreamBasicDescription
                                           destinationFileType:EZRecorderFileTypeM4A];


        self.isRecording = NO;
    }
    else
    {
        [self.recorder closeAudioFile];
        self.isRecording = YES;
    }
    self.recordingTextField.text = self.isRecording ? @"Recording" : @"Not Recording";
}
2

There are 2 best solutions below

0
On

As for my knowledge is concerned you have to delete the previously recorded audio. Here is sample code that I used to delete audio,

  '- (void)toggleRecording:(id)sender
{
 [self.player pause];
   if(!(wil%2))
        {
      [self.recorder closeAudioFile];

      [NSThread sleepForTimeInterval:0.1];
    }

if ([sender isOn])
{
    //
    // Create the recorder
    //
    [self.recordingAudioPlot clear];
    [self.microphone startFetchingAudio];
    self.recorder = [EZRecorder recorderWithURL:[self testFilePathURL]
                                   clientFormat:[self.microphone       audioStreamBasicDescription]
                                       fileType:EZRecorderFileTypeM4A
                                       delegate:self];
    self.playButton.enabled = YES;
}
self.isRecording = (BOOL)[sender isOn];
self.recordingStateLabel.text = self.isRecording ? @"Recording" : @"Not Recording";
wil++;
}'

Hope this may give some idea about your issue.

0
On

Make sure you are initialized the microphone with:

self.microphone = [EZMicrophone microphoneWithDelegate:self];