Skip to content

fix: write example audio with soundfile - #575

Open
Notaloop763 wants to merge 1 commit into
resemble-ai:masterfrom
Notaloop763:fix/examples-soundfile
Open

Notaloop763 wants to merge 1 commit into
resemble-ai:masterfrom
Notaloop763:fix/examples-soundfile

Conversation

@Notaloop763

Copy link
Copy Markdown

Summary

The five example_*.py scripts and the README snippets now write audio with soundfile.write(..., subtype="FLOAT") instead of torchaudio.save. soundfile is declared directly in pyproject.toml because the examples import it.

Why

On Python 3.14, pyproject.toml selects torch>=2.9. Since torchaudio 2.9, torchaudio.save requires torchcodec; without it the examples raise ImportError and never write a file. Passing backend="soundfile" does not avoid the torchcodec import.

soundfile is already installed as a dependency of librosa==0.11.0, so this removes the extra runtime requirement without adding a new package to the environment. The output format is unchanged: on torch 2.6.0/torchaudio 2.6.0, torchaudio.save and the new sf.write call produce byte-identical WAVs, including a sample above full scale (1.2).

Changes

  • example_for_mac.py, example_tts.py, example_tts_nano.py, example_tts_turbo.py, example_vc.py: import soundfile, write with sf.write(..., wav.squeeze(0).numpy(), model.sr, subtype="FLOAT").
  • README.md: same replacement in the usage snippets.
  • pyproject.toml: add soundfile>=0.12.1 (already required by librosa==0.11.0).

No library code, model loading, or dependency ranges are changed.

Verification

  • python3 -m py_compile example_for_mac.py example_tts.py example_tts_nano.py example_tts_turbo.py example_vc.py — pass.
  • On torch 2.6.0+cu124 / torchaudio 2.6.0+cu124: ta.save and sf.write(..., subtype="FLOAT") produced byte-identical WAVs (same SHA256), readback sample-identical, subtype FLOAT, peak 1.2 preserved.
  • uv pip install --dry-run -e . on Python 3.12 and 3.10 resolves; soundfile is already satisfied.
  • Not run: end-to-end examples on GPU/MPS; the repo has no test suite and CI only checks pip install -e ..

torchaudio 2.9+ requires torchcodec for save(), so the examples and README snippets fail on the Python 3.14 install path where pyproject selects torch>=2.9. soundfile is already a librosa dependency and writes the same FLOAT WAV, including samples above full scale.

Declare soundfile directly because the examples now import it. Verified on torch 2.6.0/torchaudio 2.6.0: torchaudio.save and sf.write produce byte-identical files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant