Python saving audio streamed to node input as speedup and pitchshifted .wav

I am trying to create a ComfyUI node that would take image sequence and audio from respective node inputs (“IMAGE”, “AUDIO”) and saving it to an uncompressed AVI, but for some reason it is speeding-up and pitch shifting the audio.

This is the relevant code that I use for saving temporary wav file:

a_waveform = audio['waveform']    
temp_audio_path = self.get_unique_filename(output_dir, filename_prefix, "wav")
waveform_data = a_waveform.cpu().numpy()
sample_rate = audio['sample_rate']
write(temp_audio_path, sample_rate, waveform_data)