Open mcclure opened 9 months ago
Soundfile can indeed be used without numpy, if you use the buffer_*
functions.
These were perhaps a bad idea, as almost all people no doubt use soundfile with numpy. But backwards compatibility is a thing, so that's how it is.
Let me try again, I think I have a better repro.
Say I create a brand new fresh venv, and then I install python-soundfile. I then run this ultra-simple script:
import soundfile
soundfile.write("test.wav", [[0,0]], 48000)
This fails with "ModuleNotFoundError: No module named 'numpy'". (So does read().)
Looking in setup.py, I find that there is a "numpy" feature in extras_require, and that it does create a numpy dependency. But you only get this if you (?) install with pip install soundfile[numpy]
, and this is not documented either in the toplevel documentation or the documentation for the functions (such as read
and write
) which require numpy. (It is mentioned in the changelog that read and write require numpy but buffer_read and buffer_write do not, but this is not a very clear place for it.)
So my "expected behavior" would be one of the following changes:
I agree. Let's require numpy for the next version of soundfile. The entire point of the library is to expose a numpy interface to libsndfile.
python-soundfile requires numpy to run. If numpy is not installed in pip, in my testing python-soundfile will immediately crash on any function invocation with
I understand python-soundfile is usually used with numpy, however, the documentation claims it can be used without it.
My expected behavior is that the library should declare all dependencies in setup.py (soundfile does do this for cffi already) so that pip will install them automatically when installing python-soundfile.
Repro
I have a repro but it is not very convenient. You can check out https://github.com/mcclure/analogue-core-template-amaranth and check out revision cd7c72b. You will want to install "pdm" with pip, and then edit src/fpga/amaranth_core/pyproject.toml to include "soundfile" instead of "pysoundfile" and remove the dependency on numpy, then you can run with
(cd src/fpga/amaranth_core && python.exe -m pdm install && python.exe -m pdm capture_wav)
.The part that uses python-soundfile is here.
Note I only tested this installing numpy with pdm, but my understanding is that uses pip.