spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
1.02k stars 149 forks source link

Add an environ flag to load an ASIO PortAudio binary #556

Closed arkrow closed 8 hours ago

arkrow commented 3 weeks ago

This PR adds the option to load an alternative PortAudio binary with ASIO support, enabled using an environ flag.

Additional PortAudio binaries compiled with ASIO will need to be maintained in the _sounddevice_data repository (e.g. named libportaudio64bit-asio.dll). They will then be bundled like default binary in the built package and can then be used by using the os.environ["SD_ENABLE_ASIO"] flag.

This PR is based on, and is the inverse of #498, since the default is now ASIO-disabled.

Minimal example:

import os

# Set environ key anywhere before importing sounddevice. Value is not important.
os.environ["SD_ENABLE_ASIO"] = "1"

# Since "SD_ENABLE_ASIO" is set, sounddevice will load the ASIO-enabled binary
import sounddevice as sd

print(sd.query_hostapis())
pep8speaks commented 3 weeks ago

Hello @arkrow! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 78:80: E501 line too long (81 > 79 characters)

rob-broadley commented 3 weeks ago

I have given this a test and it works as expected (ASIO support enabled with the SD_ENABLE_ASIO environment variable, no ASIO support without it).

mgeier commented 3 weeks ago

Thanks @arkrow for this PR and thanks @rob-broadley for testing!

This will not work in the conda package, which is no problem (at least not ours), but we should probably still mention that in the docs? (The docs already mention that the conda-forge package doesn't have ASIO support, but maybe it doesn't hurt to also mention it in the context of the environment variable)

It will also not work if a custom portaudio.dll is present in the %PATH%. I think this is also fine, but should maybe also be mentioned in the docs.

@arkrow Would you like to add some documentation?

mgeier commented 8 hours ago

Thanks again! I will add the docs in a separate PR.

mgeier commented 7 hours ago

I have added some documentation in #558.