Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogg files arent played on Ubuntu 16.04 but on RaspberryPi with Jessie #46

Closed
LocutusOfPenguin opened this issue Oct 27, 2016 · 19 comments
Closed

Comments

@LocutusOfPenguin
Copy link

Hi,
i have a strange problem, but i cant see how to come closer to the cause.

I use two (software) systems: yours and pydub see: https://github.com/jiaaro/pydub
And i have two hardware systems: one is Ubuntu 16.04 and the other a Jessie for RaspPi(3).

If i let sounddevice play a ogg fiel on Rasp, it works. But it fails on ubuntu (i hear noise).
If i do the same with pydub no problem with Ubuntu and on RaspPi , its in worse quality (not useful, but i can guess the voice file - whereas on first, its just noise).

Jürgen

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

The sounddevice module cannot actually read sound files. Can you please provide the actual code you are using?

@LocutusOfPenguin
Copy link
Author

LocutusOfPenguin commented Oct 27, 2016

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!).

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

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()

@LocutusOfPenguin
Copy link
Author

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 :-)

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

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))

@LocutusOfPenguin
Copy link
Author

(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)
my_plot
Thats the file "check.ogg"...looks OK.

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

(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?

@LocutusOfPenguin
Copy link
Author

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).

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

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.

@LocutusOfPenguin
Copy link
Author

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, ....

@mgeier
Copy link
Member

mgeier commented Oct 27, 2016

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.

@LocutusOfPenguin
Copy link
Author

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.

@mgeier
Copy link
Member

mgeier commented Oct 28, 2016

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?

@LocutusOfPenguin
Copy link
Author

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

@LocutusOfPenguin
Copy link
Author

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.

@mgeier
Copy link
Member

mgeier commented Oct 31, 2016

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?

@LocutusOfPenguin
Copy link
Author

i get another problem (after i released it)..already 2 people saying this:
jromang/picochess#219

@mgeier
Copy link
Member

mgeier commented Nov 6, 2016

@LocutusOfPenguin Is your original problem solved? If yes, please close this issue.

If you have further issues, please open new issues.

@LocutusOfPenguin
Copy link
Author

LocutusOfPenguin commented Nov 6, 2016

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants