Comments (13)
I'm glad to hear that this method works for you.
I don't think I want to include this into python-sounddevice, but it should be no problem to do this in your own code (see below).
The with
statement is part of Python just like the if
statement and the for
loop.
It should be part of your favorite Python tutorial ...
You can read up on it, e.g.:
http://stackoverflow.com/questions/3012488/what-is-the-python-with-statement-designed-for
https://docs.python.org/3/reference/compound_stmts.html#with
https://www.python.org/dev/peps/pep-0343/
In your case, I would suggest to use the contextlib
module from the standard library: https://docs.python.org/3/library/contextlib.html
import contextlib
import os
import sys
@contextlib.contextmanager
def ignore_stderr():
devnull = os.open(os.devnull, os.O_WRONLY)
old_stderr = os.dup(2)
sys.stderr.flush()
os.dup2(devnull, 2)
os.close(devnull)
try:
yield
finally:
os.dup2(old_stderr, 2)
os.close(old_stderr)
You only need to define this once, then you can use it for all the calls where you want to get rid of the warning message.
You can use it like this:
import sounddevice as sd
with ignore_stderr():
sd.play(mydata, fs)
This makes sure that after the with
statement the old behavior of stderr
is restored.
And the important part is that it is also restored if an exception is raised in sd.play()
(or in whatever you are doing inside of the with
statement).
There are probably some edge cases i'm missing, for more details have a look at: http://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
from python-sounddevice.
This message is caused by the underlying PortAudio library.
Here's an issue and a mailing list discussion about the topic:
https://www.assembla.com/spaces/portaudio/tickets/243-portaudio-support-for-os-x-10-11-el-capitan/details#
https://lists.columbia.edu/pipermail/portaudio/2015-October/000092.html
I think we'll just have to wait for a new PortAudio version, until then you'll have to ignore this message.
from python-sounddevice.
Thank's a lot!
from python-sounddevice.
You should leave this open until it is fixed.
An alternative approach would be #11, what do you think about that?
from python-sounddevice.
I think it would be nice to remove those messages though I am not familiar with that kind of implementation.
On OSX El Capitan I could not compile PortAudio following their instructions (I could in Yosemite) and I get the errors as you showed in the links above. So as you say, the appropriate solution should come from PortAudio. I installed it using brew install portaudio
, and so far sounddevice seems to work as I expect/need.
from python-sounddevice.
I made an attempt at silencing PortAudio in the branch "redirect-stdout", see #12.
Can you please try if this works in your case?
from python-sounddevice.
I still see the warning. Please let me know if I installed it correctly (I'm sort of a begginer):
- I work with virtualenvs, so I created a new one.
- I installed some dependencies with
pip
, but notsounddevice
. - I cloned this repo and checkedout
redirect-stdout
- I executed the command
python setup.py install
- and ran my
HelloSoundDevice.py
from python-sounddevice.
Yes, those are the right steps.
However, you should probably change the installation command (as suggested in the "Contributing" section of the docs) to:
python setup.py develop
... because this way you can change stuff in the code and don't need to re-install the module all the time.
You'll have to close and re-start Python, though, for the changes to take effect.
If you are not sure if the correct code is used, you should try to create an obvious error in sounddevice.py
and check if this error is raised when you run your test script. Just to be sure ...
Since you still see the warning, maybe it is sent to stdout
instead of stderr
...
Can you please try to replace the two occurrences of __stderrp
with __stdoutp
and run it again?
from python-sounddevice.
OK, so I reinstalled as explained and the intentional error is raised!
I see the warning without and with the modification you suggest.
There is something I do not understand in this part of the code (the first occurrence is commented?) Well I though I should do something in OS X about it but do not really what (XD)
from python-sounddevice.
Hmmm ... so it looks like the message doesn't come from the PortAudio library but somehow directly from the OS ... I guess ...
There is no code commented, the only comments are actual comments. The first line is just a hint that the following definitions are taken from the file stdio.h
.
/* from stdio.h */
Since this doesn't seem to work in your case, you could now try my suggestion from #11 (comment).
You can put the first block of code from the above link before you call sd.play()
and the second block of code after it.
If it doesn't work, you should try changing the 2
(which is the file descriptor for stderr
) to 1
(which means stdout
).
If you don't run the second code block (to undo the redirection), you won't see any stdout
/stderr
messages for your remaining Python session!
If this works for you, you should actually use a with
statement to make sure that the redirection is undone even if an error occurs.
from python-sounddevice.
I have followed the instruction on pasting the blocks of code before and after the call to sounddevice
and it indeed hides the warning! It worked with the 2
.
Could you explain me what you mean by using a with
statement?
from python-sounddevice.
Thank's a lot for your help! That solution is good enough for me ;)
from python-sounddevice.
Just for reference, there is another issue in the PortAudio issue tracker: https://www.assembla.com/spaces/portaudio/tickets/218-pa-coreaudio-uses-some--quot-deprecated-quot--apis----this-is-by-design-but-needs-to-be-monitored
it looks like the warning message will stay for some time ...
from python-sounddevice.
Related Issues (20)
- 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
- Does sd.wait() block all other threads? HOT 1
- OSERROR portaudio library not found
- Advice on detecting when Sounddevice has stopped playing audio (and using multiple OutputStreams)
- Inconsistent order of channels 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.