Comments (19)
The sounddevice
module cannot actually read sound files. Can you please provide the actual code you are using?
from python-sounddevice.
https://github.com/LocutusOfPenguin/picochess/blob/pt-sd/talker/picotalker.py
in class "PicoTalker"
or more general here:
https://github.com/LocutusOfPenguin/picochess/tree/pt2/talker
dub.py => pydub version ; sd.py => sounddevice version
BTW...i need to say "blocking=True" otherwise i get a "segmentation fault" but thats maybe the closed task issue (dont care that now) ... I need to release a new picochess version, and strangely the both ways are cross working in one OS (alone!).
from python-sounddevice.
So you are using the soundfile
module, which is good. The question now is if the error occurs when reading the sound file on RaspPi or if it occurs during playback.
Can you plot the waveform after reading the file?
You are supposed to use either blocking=True
or call sd.wait()
or sd.stop()
before exiting your script/application, otherwise bug #1 will haunt you. If you know a fix for that, please tell me.
BTW, in the abovementioned sd.py
, this is used:
sd.play(data, fs)
status = sd.get_status()
This does not wait and will prematurely check the status! Probably the status of the previous call to play()
...
You should use:
sd.play(data, fs)
status = sd.wait()
if status:
# do something
Alternatively, you can do that:
sd.play(data, fs, blocking=True)
status = sd.get_status()
from python-sounddevice.
Sorry? How to plot the waveform?
.wait() => yes, i saw the closed issue ....this is run in thread anyway...so, i don't care too much , its blocking or not. That's more a problem to shorten the voice files to the absolute minimum, ha.
But thx, for the updated code for "blocking=False" ...Perhaps y should also move that inside yr play_file example :-)
from python-sounddevice.
There are many ways to plot. Do you have matplotlib
?
Do you have a screen connected to your RaspPi?
If yes, you can try this:
import matplotlib.pyplot as plt
plt.plot(data) # where "data" is your audio data from the file
plt.show()
If you don't have a screen, you can save the plot to a file instead of calling plt.show()
:
plt.savefig('my_plot.png')
Note that #1 is not closed, it's still waiting for a fix!
this is run in thread anyway...so, i don't care too much
You probably should care, since if your thread stops before playback is finished, you might run into the same problem.
My example play_file.py already uses the second alternative of what I told you before:
sd.play(data, fs, device=args.device, blocking=True)
status = sd.get_status()
if status:
logging.warning(str(status))
from python-sounddevice.
(A)
i meant this (blocking=false) code:
sd.play(data, fs)
status = sd.wait()
if status....
(B)
The thread runs a while(True) loop (listening for voice events)...but i keep an eye on this. Thanks.
(C)
Thats the file "check.ogg"...looks OK.
from python-sounddevice.
(A)
Well I cannot use both ways, I had to choose one. Do you think I should change the example to use the "non-blocking + wait" idiom instead of "blocking + get_status"?
If yes, why?
(C)
At least it doesn't look like noise. Did you create this plot on the RaspPi?
Does the same data
array, when you play it back, sound like noise?
from python-sounddevice.
I tried another ubuntu 16.04 computer in meantime. And here its working :-( ...For the moment i dont know what is going on. Let me try again (@home) with this problem ubuntu. But both are always up-to-date. Sowas macht mich noch wahnsinnig, ha.
For (A) up to you...i would suggest do both ways in each one file, or use a commented section for the other way (prefered)...or just let it be as it is(!) Its not sooo important (esp i know now, how to do it the other way).
from python-sounddevice.
OK, then I'm looking forward to getting further results ...
(A)
The one obvious way (following the Zen of Python) to decide if you want playback to be blocking or not, is using the blocking
flag. I hope this is indeed obvious. That's why I used it in the example program.
The use case for sd.wait()
is much more specialized, I would only use this if blocking=True
cannot be used for some reason. Since the example application is not such a case, sd.wait()
shouldn't be used (or even mentioned) there.
from python-sounddevice.
OK, im at home (with the troublesome ubuntu)..
If y see here: https://github.com/LocutusOfPenguin/picochess/tree/pt2/talker
i updated sd.py let it run, and the pgn's look different, but the result is still not ok (noise for short time).
I also tried several ways to uninstall this & that, with apt-get & pip3 ...install this & that ...but nothing helped.
for example libav-tools, ffmpeg, sounddevice, pysoundfile, vorbis-tools, ....
from python-sounddevice.
OK, the plots look fine, so the problem seems to occur during playback ...
Was there a warning printed on the console output?
You should try changing a few settings, e.g. blocksize
and latency
, probably that helps.
from python-sounddevice.
i changed some "sd.default.*" blocksize, latency values (no idea what blocksize should be)...but no effect. Nevertheless when i run "sd.py" i get
WARNING:root:output underflow
Perhaps i should change the output from sd.play() to something else for example like in #25 but i admit i don't understand yr comment from 12.May.
from python-sounddevice.
Those warnings are important, you should actually check for them after each invocation of play()
. You should try to find a combination of settings that makes those warnings disappear.
Try setting blocksize
to something like 1024
or 2048
, or even 4096
.
If that doesn't help, try setting latency
to 0.1
or 0.2
, or even slightly higher values.
You can also try setting both blocksize
and latency
at the same time and try different combinations.
If that still doesn't get rid of the warnings, you can try reducing the samplerate
. Which one are you currently using?
from python-sounddevice.
ogginfo 1.ogg (ähnliche Werte bei anderen ogg Files)
Datei »1.ogg« wird verarbeitet...
New logical stream (#1, serial: 3bc3e4ca): type vorbis
Vorbis-Header für Datenstrom 1 werden verarbeitet, Information folgt...
Version: 0
Anbieter: Xiph.Org libVorbis I 20101101 (Schaufenugget)
Kanäle: 1
Rate: 44100
Nominale Bitrate: 128,000000 kbit/s
Obere Bitrate: 128,000000 Kb/s
Untere Bitrate: 128,000000 Kb/s
Benutzerkommentarabschnitt folgt …
creation_time=2016-10-19 14:05:30
language=eng
encoder=Lavc57.48.101 libvorbis
major_brand=M4A
minor_version=0
compatible_brands=M4A mp42isom
ENCODER=TwistedWave Online
Vorbis stream 1:
Total data length: 7487 bytes
Playback length: 0m:00.448s
Average bitrate: 133,451907 kb/s
Logischer Datenstrom 1 beendet
from python-sounddevice.
saying sd.default.blocksize = 2048 seems to work!
I get on my troubesome ubuntu the voices and on Rasp too (with some background noise like [tttsssss] )
Have to test abit more...but it looks good so far.
from python-sounddevice.
Good to know that it works with a blocksize
of 2048.
Does the background noise only appear when using a Python script, or also when playing sounds with other applications (e.g. mplayer, vlc, aplay)?
It may be just the noise level of the DAC?
from python-sounddevice.
i get another problem (after i released it)..already 2 people saying this:
jromang/picochess#219
from python-sounddevice.
@LocutusOfPenguin Is your original problem solved? If yes, please close this issue.
If you have further issues, please open new issues.
from python-sounddevice.
Hi,
sorry!
im busy with issue 219 - and i don't have too much (extra) time left
=> i couldn't even try out what y asked me 6 days ago.
As said, it works with 2048 (even i get abit background noise)
Close. I'll do what y proposed (if i have more)
from python-sounddevice.
Related Issues (20)
- 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
- 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)
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.