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

Linux-Debian: getting error while invoking playsound #1

Closed
gansai opened this issue Feb 28, 2016 · 25 comments
Closed

Linux-Debian: getting error while invoking playsound #1

gansai opened this issue Feb 28, 2016 · 25 comments

Comments

@gansai
Copy link

gansai commented Feb 28, 2016

Hi Taylor,

My System Config:

python 3.4.2
Debian 64bit

I got the following error while invoking playsound:

Traceback (most recent call last):
File "/home/gansai/PycharmProjects/python_3.4.2/tryPlaySound.py", line 7, in
playsound('/home/gansai/Music/abc.mp3')
File "/usr/local/lib/python3.4/dist-packages/playsound.py", line 81, in _playsoundNix
from wave import open as waveOpen, AFMT_S16_LE, AFMT_S16_BE
ImportError: cannot import name 'AFMT_S16_LE'

Please let me know how I should configure ossaudiodev.

Thanks.

@TaylorSMarks
Copy link
Owner

Hi,

I don't have any machines running Linux, so I'm not able to help with this. I copied the Linux function for this module from an old Python mailing list.

If you manage to find a solution, please share it and I'll be happy to update the module to include it.

Taylor

@DennisT1
Copy link

Seeing the same issue on Centos 7.2.1511

@Rumbles
Copy link

Rumbles commented May 21, 2016

And the same in pip install on openSUSE

Time to learn some Linux :)

@TaylorSMarks
Copy link
Owner

@Rumbles - I have a lot of servers running RHEL that I can VNC into... But VNC doesn't stream audio, does it?

Need to get something installed on one of my local machines...

@dev-jam
Copy link

dev-jam commented May 27, 2016

Got it working by removing AFMT_S16_LE, AFMT_S16_BE from the import statement. Those names do not exist in the wave package. After this I can play wav's correctly, mp3 does not work.

in function _playsoundNix change:

from wave import open as waveOpen, AFMT_S16_LE, AFMT_S16_BE

to

from wave import open as waveOpen

@TaylorSMarks
Copy link
Owner

Hi,

Yeah, I only expected WAV to work. The problem is, I don't think there's any standard library that comes with any major Linux distribution that decompresses MP3. I've seen pure Python code that decompresses MP3 into WAV, but it runs at around 0.5x real time, meaning it's not capable of decompressing and playing at the same time.

I'm thinking I might try installing Ubuntu on an old laptop I have this weekend. Maybe I'll find a solution for playing MP3s and other formats.

Taylor

Sent from my iPhone

On May 27, 2016, at 18:15, Bob Rosbag notifications@github.com wrote:

Got it working by removing AFMT_S16_LE, AFMT_S16_BE from the import statement. Those methods do not exist in the wave package. After this I can play wav's correctly, mp3 does not work.

in function _playsoundNix change:

from wave import open as waveOpen, AFMT_S16_LE, AFMT_S16_BE

to

from wave import open as waveOpen


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@dev-jam
Copy link

dev-jam commented May 27, 2016

Gstreamer might do the trick. I'll check if I have some time this weekend.

I decompress all formats to wav anyway because I use them in psychological research where I need low latency and minimized background processes. But for normal use this is not preferable of course.

@E2DUf
Copy link

E2DUf commented Jun 7, 2016

I had the same issue as OP, so I followed dev-jam's advice and removed the two names from import, but now I'm getting Wave_read instance has no attribute 'exit' error. I use Python 2.7.11 in Lubuntu 16.04. Does anyone know how to fix this?

@dev-jam
Copy link

dev-jam commented Jun 17, 2016

Had the same problem.
with foo() as bar:
doesnt work in python 2.7, I had to change:

with waveOpen(sound, 'rb') as sound:
    channelCount, sampleWidth, framerate, frameCount, compressionType, compressionName = sound.getparams()
    try:
        from ossaudiodev import AFMT_S16_NE
    except ImportError:
        if 'little' in byteorder.lower():
            AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
        else:
            AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
    data = sound.readframes(frameCount)

to:

sound = waveOpen(sound, 'rb')
channelCount, sampleWidth, framerate, frameCount, compressionType, compressionName = sound.getparams()
try:
    from ossaudiodev import AFMT_S16_NE
except ImportError:
    if 'little' in byteorder.lower():
        AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
    else:
        AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
data = sound.readframes(frameCount)

Then it works.

@E2DUf
Copy link

E2DUf commented Jun 30, 2016

Tried your suggestion, now I'm getting a different error:

_File "/usr/local/lib/python2.7/dist-packages/playsound.py", line 94, in playsoundNix
speaker = ossaudiodev.open('/dev/dsp', 'w')
IOError: [Errno 2] No such file or directory: '/dev/dsp'

@Ivan-Castro
Copy link

playsound don't work for linux, even when I made the aforementioned suggestions. I get all those errno.

@dev-jam
Copy link

dev-jam commented Aug 1, 2016

E2DUf: seems like you have not installed oss4 on your linux. Playsound uses oss4 and not ALSA/pulse/jack etc.

Works perfectly for me on debian jessie with oss4. My goal with playsound was to test/use oss4 with low and reliable latencies. My tests showed Alsa to have lower latency. If I remember correctly: 3.5 ms with stddev 0.9 ms. Oss4 + playsound is more in the range of 10 ms latency.

On my desktop I still use oss4 for assumed better audio quality.

@jl2035
Copy link

jl2035 commented Jan 1, 2017

So no linux solution for this, am I right?

@Akuli
Copy link
Contributor

Akuli commented May 16, 2017

Someone mentioned Gstreamer earlier. I have some experience with Gtk+ so I found this tutorial and I made this thing based on it. It works for me and I would like to know if it works for others too.

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib

Gst.init(None)

playbin = Gst.ElementFactory.make('playbin', 'playbin')
playbin.props.uri = 'file:///path/to/the/file.mp3'
playbin.set_state(Gst.State.PLAYING)

bus = playbin.get_bus()
bus.poll(Gst.MessageType.EOS, Gst.CLOCK_TIME_NONE)
playbin.set_state(Gst.State.NULL)

Edit: Most distributions come with the dependencies installed, so I think this is a good solution if this works.

@jl2035
Copy link

jl2035 commented May 17, 2017

@Akuli it works for me on ElementaryOS Loki.

@Akuli
Copy link
Contributor

Akuli commented May 18, 2017

I'll probably make a pull request about this thing tomorrow. Hopefully @gansai notices it.

@Akuli
Copy link
Contributor

Akuli commented May 19, 2017

Oops, I meant that hopefully @TaylorSMarks notices it, not gansai :)

@Akuli
Copy link
Contributor

Akuli commented May 19, 2017

Here it is.

@TaylorSMarks
Copy link
Owner

I accepted your pull request. The version on PyPI should probably be updated to include this at some point...

@mchenja
Copy link

mchenja commented May 27, 2017

@TaylorSMarks - Just started using your package a week ago, ran into this bug today, and am pleasantly surprised to find out it is fixed! (Thank you, @Akuli!)

But since the version on PyPI hasn't yet been updated, how do I install it from source (i.e., GitHub)?

@TaylorSMarks
Copy link
Owner

TaylorSMarks commented May 28, 2017 via email

@mchenja
Copy link

mchenja commented May 28, 2017

Thanks. Do you have any idea when the version on PyPI will be updated?

@Akuli
Copy link
Contributor

Akuli commented Jun 2, 2017

The pip install git+... command requires having git installed. Use this command if you don't have git:

pip install https://github.com/TaylorSMarks/playsound/archive/master.zip

@TaylorSMarks
Copy link
Owner

Okay, I decided to try going through the effort of uploading a newer version to PyPI today. I'm not sure if I did things properly or not.

I found that I had some local changes that I had never committed. Ran these commands to handle that:

$ git add playsound.py
$ git commit -m "Cleaner error message on macOS."
$ git pull
$ git push

It looks like my small change now shows up on github and it didn't blow away the pull requests that I've accepted, so I think that's all good.

Then to actually upload to Pypi, I updated the version number in setup.py (from 1.2.1 to 1.2.2) then ran:
$ python setup.py bdist_wheel --universal
$ twine upload dist/*

It's not clear to me whether that worked or not. This is the output:
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: TaylorSMarks
Enter your password:
Uploading playsound-1.2.2-py2.py3-none-any.whl
Uploading playsound-1.0.0.tar.gz
HTTPError: 400 Client Error: File already exists. for url: https://upload.pypi.org/legacy/

But on the package's page on pypi, it shows I uploaded something... and pip install --upgrade playsound says it successfully installed 1.2.2... and it imports and plays my test file successfully even when I'm not in the directory with the source code.

So I think I've successfully updated whatever is on Pypi?

@Mahi
Copy link

Mahi commented Jun 30, 2017

I'm not sure if your twine works any similar to how I upload my packages, but to me it sounds like you're going wrong with the github tags. Check the "setup.py" section from the link above. @TaylorSMarks

I.e. did you ever update the download url?

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