You are not logged in.

#1 2022-12-05 14:26:36

PinyaColada
Member
Registered: 2021-03-09
Posts: 4

Can't play audio with Python

Trying to use any library of python that produces sound give an error.
In this case the code is:
    wave_obj = sa.WaveObject.from_wave_file("start.wav")
    play_obj = wave_obj.play()
and the error is:
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
Traceback (most recent call last):
  File "/home/pinya/PycharmProjects/Flowmodoro/main.py", line 28, in <module>
    play_obj = wave_obj.play()
  File "/home/pinya/PycharmProjects/Flowmodoro/venv/lib/python3.10/site-packages/simpleaudio/shiny.py", line 19, in play
    return play_buffer(self.audio_data, self.num_channels,
  File "/home/pinya/PycharmProjects/Flowmodoro/venv/lib/python3.10/site-packages/simpleaudio/shiny.py", line 60, in play_buffer
    play_id = _sa._play_buffer(audio_data, num_channels, bytes_per_sample,
_simpleaudio.SimpleaudioError: Error opening PCM device. -- CODE: -2 -- MSG: No such file or directory

Then I wanted to use lspci but it says that the command is unfound, but I have installed pciutils.
This is my OS
OS: Arch Linux x86_64
Host: B85-HD3
Kernel: 6.0.11-arch1-1
Uptime: 16 mins
Packages: 1259 (pacman)
Shell: bash 5.1.16
Resolution: 1920x1080
DE: Plasma 5.26.4
WM: KWin
Theme: [Plasma], Breeze [GTK2/3]
Icons: [Plasma], Tela-circle-dark [GTK2/3]
Terminal: yakuake
CPU: Intel i7-4770 (8) @ 3.900GHz
GPU: AMD ATI Radeon RX 5600 OEM/5600 XT / 5700/5700 XT
GPU: Intel HD Graphics
Memory: 4358MiB / 15866MiB

Offline

#2 2022-12-05 14:42:00

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,480
Website

Re: Can't play audio with Python

That doesn't look like it has anything to do with python, but is just an asla configuration issue.  Can you play the wav file with `aplay`?  Does `speaker-test` generate sound or produce errors?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2022-12-05 15:31:30

PinyaColada
Member
Registered: 2021-03-09
Posts: 4

Re: Can't play audio with Python

Hi! It seems that. I can't do any of those things these are the errors.
- aplay start.wav
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
aplay: main:831: audio open error: No such file or directory
speakers-test
speaker-test 1.2.8

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
Playback open error: -2,No such file or directory

It''s weird because I don't have any problems with audio, I have 3 main sources of output which are the HDMI, Digital output (not connected to anything) and a headsets via bluetooth.

Offline

#4 2022-12-05 15:59:53

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,261

Re: Can't play audio with Python

Chances are you need to install pipewire-alsa or pulseaudio-alsa respectively and remove whatever/etc/asound.conf you might have

Offline

#5 2022-12-05 16:28:15

PinyaColada
Member
Registered: 2021-03-09
Posts: 4

Re: Can't play audio with Python

Downloading pulseaudio-alsa worked! Thank you Trilby and V1del smile

Offline

Board footer

Powered by FluxBB