BoxOfColors commited on
Commit
a5f92a7
·
1 Parent(s): 2b4b56f

Fix audio WAV header: ensure contiguous memory layout before torchaudio.save

Browse files

numpy array slicing can produce non-contiguous memory; torch.from_numpy
on a non-contiguous array can write a malformed WAV header causing the
browser audio player to report wrong duration. np.ascontiguousarray()
forces a contiguous copy before saving. Reverts unnecessary 44100 Hz
resample.

Files changed (1) hide show
  1. app.py +1 -4
app.py CHANGED
@@ -635,11 +635,8 @@ def generate_hunyuan(video_file, prompt, negative_prompt, seed_val,
635
  # Trim to exact video duration
636
  full_wav = full_wav[:, : int(round(total_dur_s * sr))]
637
 
638
- audio_tensor = torch.from_numpy(full_wav) # (C, samples) at sr Hz
639
- # Resample to 44100 Hz — 48 kHz WAV headers can confuse browser audio players
640
- audio_44k = torchaudio.functional.resample(audio_tensor, orig_freq=sr, new_freq=44100)
641
  audio_path = os.path.join(tmp_dir, f"hunyuan_{sample_idx}.wav")
642
- torchaudio.save(audio_path, audio_44k, 44100)
643
  video_path = os.path.join(tmp_dir, f"hunyuan_{sample_idx}.mp4")
644
  merge_audio_video(audio_path, video_file, video_path)
645
  outputs.append((video_path, audio_path))
 
635
  # Trim to exact video duration
636
  full_wav = full_wav[:, : int(round(total_dur_s * sr))]
637
 
 
 
 
638
  audio_path = os.path.join(tmp_dir, f"hunyuan_{sample_idx}.wav")
639
+ torchaudio.save(audio_path, torch.from_numpy(np.ascontiguousarray(full_wav)), sr)
640
  video_path = os.path.join(tmp_dir, f"hunyuan_{sample_idx}.mp4")
641
  merge_audio_video(audio_path, video_file, video_path)
642
  outputs.append((video_path, audio_path))