feat: replace scipy.wavfile with soundfile for WAV handling#22
Open
ksylvan wants to merge 1 commit intottm:masterfrom
Open
feat: replace scipy.wavfile with soundfile for WAV handling#22ksylvan wants to merge 1 commit intottm:masterfrom
ksylvan wants to merge 1 commit intottm:masterfrom
Conversation
### CHANGES - Replace `scipy.io.wavfile` with `soundfile` for WAV file operations. - Update WAV reading logic to handle integer PCM data. - Adjust WAV writing to use `soundfile` library. - Bump version to `1.0.0-b6` in `pyproject.toml`. - Add `soundfile` dependency to project requirements. - Update installation instructions to use `uv sync`. - Restructure example files into `music/examples` directory.
ttm
requested changes
Jul 18, 2025
Owner
ttm
left a comment
There was a problem hiding this comment.
thanks for your contributions. Any thoughts on my comments?
| * [penta_effects](https://github.com/ttm/music/tree/master/music/examples/chromatic_scale.py): writes a pentatonic scale repeated once clean, once with pitch, one with vibrato, one with Doppler, and one with FM, into a WAV stereo file. | ||
| * [noisy](https://github.com/ttm/music/tree/master/music/examples/noisy.py): writes into a WAV file a sequence of different noises. | ||
| * [thirty_notes](https://github.com/ttm/music/tree/master/music/examples/thirty_notes.py) and [thirty_numpy_notes](https://github.com/ttm/music/tree/master/music/examples/thirty_numpy_notes.py) generate a sequence of sounds by using a synth class (in this case the class [`Being`](https://github.com/ttm/music/tree/master/music/legacy/classes.py)). | ||
| * [campanology](https://github.com/ttm/music/tree/master/music/examples/campanology.py) and [geometric_music](https://github.com/ttm/music/tree/master/music/examples/geometric_music.py) both use `Being` as their synth, but this time with permutations. |
Author
There was a problem hiding this comment.
Will double check and fix. Thanks.
|
|
||
| import numpy as np | ||
| from scipy.io import wavfile | ||
| import soundfile as sf |
Owner
There was a problem hiding this comment.
I am not convinced we should move from scipy.io.wavfile to soundfile. I understand it is more flexible, but do we need it? I am open to discuss it here or even in a call.
Author
There was a problem hiding this comment.
Let me get back to you in a day or two. I'm in the middle of a project, but thank you for the response and reviewing this!
Owner
There was a problem hiding this comment.
you would move it to the music folder? So that it will be inside the package itself whenever we import music?
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.
CHANGES
scipy.io.wavfilewithsoundfilefor WAV file operations.soundfilelibrary.1.0.0-b6inpyproject.toml.soundfiledependency to project requirements.uv sync.music/examplesdirectory.Summary
This PR introduces several improvements to the Music package:
scipy.io.wavfiletosoundfile(pysoundfile) for improved compatibility, feature set, and reliability.music/examples/) and configures them to be included as package data.soundfileas an explicit dependency.uv.lockfile.pyproject.tomlto reflect these changes and properly include example scripts in distributions..gitignoreupdate to include.vscode/.Files Changed
Added
uv.lock: Lockfile for uv-based dependency management.Modified
.gitignore: Adds.vscode/to ignored files.README.md:uv.uv.lock.music/core/io.py:scipy.io.wavfileusage withsoundfile(sf).music/singing/perform.py:scipy.io.wavfilewithsoundfilefor reading output from ecantorix.pyproject.toml:1.0.0-b6."MIT"and updates Python requirement to>=3.10.soundfileas a dependency.music/examples/is included as package data.examples/are now undermusic/examples/and set as package data:campanology.py,chromatic_scale.py,geometric_music.py,isynth.py,noisy.py,penta_effects.py,thirty_notes.py,thirty_numpy_notes.py.Removed
Code Changes
music/core/io.py
sf.readinstead ofwavfile.read, always requestsint16PCM, and transposes stereo files to(channels, nsamples)for consistency.sf.writeinstead ofwavfile.write, with a comment clarifying the change.music/singing/perform.py
achant.wavusingsf.readand checks for 44.1kHz sample rate.pyproject.toml
soundfileto dependencies.music/examples/*.README.md
uv.uv.lock..gitignore
.vscode/directory.Example Scripts
music/examples/and included as package data.uv.lock
Reason for Changes
soundfileoffers broader file format support, better handling of non-16bit data, and improved reliability overscipy.io.wavfile. This future-proofs the codebase and aligns with modern Python audio practices.Impact of Changes
uvand a lockfile for consistent dependency management.Test Plan
music/examples/to verify they work as expected.uvand verify that the lockfile ensures reproducible installs.uv.lock).Additional Notes
music/examples/.soundfilemay require users to have the underlyinglibsndfilelibrary installed (typically handled automatically via pip wheels, but may require system packages on some platforms)..vscode/ignore is a convenience for developers using Visual Studio Code and does not affect the package or build process.