2

What i am trying to achieve is making a sort of a karaoke application that will play music in the background while the user sings. With headphones everything seems to work fine but when i try to record and merge audio files when on speaker, i am facing some syncing issues.

I play an audio file and immediately start recording. After the recording is done, i play both the recorded audio file and original soundtrack back simultaneously and what seems to be happening is that there is a slight delay between the audio of both the files when played via AVAudioPlayer (This problem doesn't appear when using headphones as the recorded audio doesn't have the music playing in the background from the speaker port).

I have tried using SCRecorder to record the file (as i have to merge videos as well) and using just AVAudioRecorder both and there is a slight delay in both the cases. Normally you wouldn't be able to tell but I have to play the recording and original file simultaneously so it appears to have an echo. Since the audio has quite a lot of beats it appears quite out of tune as well.

Also if i merge all the files starting from the 0th second using AVMutableComposition, there is still a delay which leads me to believe that the recording itself has a delay, even though i start the record and play methods simultaneously:

func startRecording(){
    audioPlayer.play()
    videoRecorder?.record()
    delegate?.didStartRecording()
}
//prepareToRecord has been called way before during initialization of the class

Now the problem is solved if i forcefully add a delay of 0.1 seconds for playbacks everywhere but i'd rather really know the reason as to what can be causing this issue and figure out a solution.

Rikh
  • 4,078
  • 3
  • 15
  • 35

0 Answers0