Comments (10)
Hi Matthias,
Sorry for the late reply. I had a go at the new branch and this works for me.
I create a method to query the devices and force the refresh and this works fine:
def query_devices_refresh(device=None):
sd._terminate()
sd._initialize()
return sd.query_devices(device)
There is no problem with disconnecting a device and then executing _terminate()
followed by initialize()
Thanks again for your support
Adrien
from python-sounddevice.
See issue #3.
from python-sounddevice.
HI Matthias
Thanks for your quick reply. I've tried this but _terminate returns an error in Python 2.7:
>>> sd._terminate() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\sounddevice.py", line 2681, in _terminate _atexit.unregister(_lib.Pa_Terminate) AttributeError: 'module' object has no attribute 'unregister'
I have tried executing the ._check(sd._lib.Pa_Terminate(), 'Error terminating PortAudio')
manually instead followed by _initialize()
but this doesn't refresh the list of devices produces by query_devices()
Any ideas? Thanks for your help
Adrien
from python-sounddevice.
Hi Matthias,
I found that commenting out the line with _atexit.unregister(_lib.Pa_Terminate)
solves the problem.
Adrien
from python-sounddevice.
OK, but when you call sd._terminate()
and then close the Python interpreter, you'll get this error:
PortAudioError: Error terminating PortAudio: PortAudio not initialized
Right?
I'll have to find a way to work around the fact that atexit.unregister()
doesn't exist in Python 2.
from python-sounddevice.
HI Matthias,
This is the error I get when closing the Python interpreter:
Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) KeyboardInterrupt Error in sys.exitfunc: Traceback (most recent call last): File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) KeyboardInterrupt
from python-sounddevice.
I've implemented a possible fix in #48, can you please check if that works for you?
Note: If you change the configuration (plug/unplug devices) while PortAudio is initialized, the next call to sd._terminate()
might crash your Python interpreter! At least that happens sometimes when I start/stop jackd
at the wrong time.
Make sure to always use it like this, then it should be safe:
sd._terminate()
- change hardware
sd._initialize()
The behavior should be better now, even for Python 3, because atexit.unregister() has a slightly different behavior than I thought.
Previously, if sd._initialize()
was called multiple times and afterwards sd._terminate()
was called fewer times, the missing "terminate" calls were not done when exiting. This is of course a silly edge case, but now that should work, too.
For those who are curious, here's a discussion about adding atexit.unregister()
to Python: https://mail.python.org/pipermail/python-dev/2005-April/052983.html. The opinions are mostly negative, I wonder why they added it anyway in Python 3 ...
from python-sounddevice.
@jacobanana Thanks, I've merged #48 into master
.
It's good to know that there are no crashes when hot-plugging devices. On which OS did you try that?
from python-sounddevice.
hi matthias,
that was tried on windows 8.1, osx and raspbian
i did get one problem on osx with multiple streams running at once... i know you recommend only having one stream running at a time but it does work quite well on raspbian. I get an occasional crash on OSX and windows ASIO just doesn't allow it at all. This is a separate issue though.
from python-sounddevice.
Thanks. So the only time it reportedly crashed, is when starting/stopping jackd
at the wrong time. That's good to know.
About multiple streams: PortAudio doesn't officially support multiple streams. They might work on some platforms, but if you want your code to be portable, you should only use one stream at a time.
If you think there is something that I could do on the Python side, please open a new issue.
from python-sounddevice.
Related Issues (20)
- Select inport port on sounddevice HOT 1
- Raspberry pi: sounddevice query_devices() does not see usb devices HOT 2
- check_input_settings does not raise exception for some unsupported sample rates on macOS HOT 4
- Cannot get aggregate device to work with sounddevice/rtmixer signal processing.py example HOT 1
- Enhancement Request: Integrate Playback Status Check into Simple `play`/`stop` API in `sounddevice` HOT 4
- Feature request for loopback of output device. HOT 3
- 设备解码错误?utf-8' codec can't decode byte 0xc2 in position 6: invalid continuation byte HOT 4
- Sounddevice + big dict + OOP = Segfault / Bus Error HOT 11
- Update device list by reloading portaudio dll HOT 1
- Won't be able to import sounddevice due to unknown issue with `libportaudio64bit.dll` HOT 5
- Error opening OutputStream: Unanticipated host error', -9999, (2, 0, 'Failed to load ASIO driver
- Use sounddevice with virtual audio device and minimize latency HOT 1
- Achieving stable latency between calls of "playrec" HOT 8
- sounddevice not recognize all devices?
- Issues with playing concurrently with Youtube HOT 1
- Latency 30mSec HOT 9
- Advice on asynchronous playback HOT 7
- docker node minimal image
- Can I continue recording until the volume drops below a threshold? HOT 4
- Simultaneous audio playback datatype issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-sounddevice.