Repository navigation
fix: write example audio with soundfile - #575
Open
Notaloop763 wants to merge 1 commit into
Open
Notaloop763 wants to merge 1 commit into
Notaloop763 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The five
example_*.pyscripts and the README snippets now write audio withsoundfile.write(..., subtype="FLOAT")instead oftorchaudio.save.soundfileis declared directly inpyproject.tomlbecause the examples import it.Why
On Python 3.14,
pyproject.tomlselectstorch>=2.9. Since torchaudio 2.9,torchaudio.saverequirestorchcodec; without it the examples raiseImportErrorand never write a file. Passingbackend="soundfile"does not avoid the torchcodec import.soundfileis already installed as a dependency oflibrosa==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.saveand the newsf.writecall 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: importsoundfile, write withsf.write(..., wav.squeeze(0).numpy(), model.sr, subtype="FLOAT").README.md: same replacement in the usage snippets.pyproject.toml: addsoundfile>=0.12.1(already required bylibrosa==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.ta.saveandsf.write(..., subtype="FLOAT")produced byte-identical WAVs (same SHA256), readback sample-identical, subtypeFLOAT, peak 1.2 preserved.uv pip install --dry-run -e .on Python 3.12 and 3.10 resolves;soundfileis already satisfied.pip install -e ..