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

HunyuanFoley: resample standalone audio output to 44100 Hz

Browse files

48 kHz WAV files can confuse browser audio players and show wrong
duration (e.g. 0:15 instead of 0:51). Resample the audio-only output
to 44100 Hz before saving. The muxed video audio is unaffected.

Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -635,8 +635,11 @@ 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_path = os.path.join(tmp_dir, f"hunyuan_{sample_idx}.wav")
639
- torchaudio.save(audio_path, torch.from_numpy(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))
 
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))