-
Notifications
You must be signed in to change notification settings - Fork 71
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
'import soundcard' throws an error when run through a systemd service #133
Comments
SoundDevice is a python wrapper for PortAudio, which does not use PulseAudio. Your problem seems to be on these two lines
And seems that it is what you think is the problem is, really is the problem. You are running it too early. |
My bad, I still get those mixed up.
I think I don't I get what "too early" refers to, because the copy-pasted errors are from me trying to manually start the service ( |
I would think that the service somehow does not have access to pulseaudio. Can you check the value of |
Well I learn by trying! I spent maybe 10h trying to get that damn value but finally I got it. After countless tries, I "simply" had to install the soundcard module globally instead of locally, then modify soundcard/pulseaudio.py to get it logging the said value, and make the service run as root instead of pi (because logging would not work otherwise for some reason). Now the result: So if I get it correctly from the pulseaudio documentation, |
Thank you very much for going to such lengths in debugging this issue. This does indeed point to some configuration issue in pulseaudio that prevents the systemd unit from accessing pulseaudio for some reason. I believe pulse communicates over a socket, which is (or can be) exposed through an environment variable. Perhaps checking that variable and/or socket might be a next step in debugging this issue. |
Could you be a bit more specific? Apparently pulseaudio does uses some environment variables, but I don't understand how to get or set any of those. None of those appear in the output of the I also ran |
I'm not very well-versed in pulse, either, sorry. At least you could check whether your systemd unit can read that server socket. Beyond that, I'm not sure either. |
@Teufeuleu: You could try to use pulseaudio's |
@ronny-rentner @Teufeuleu : I have the same issue. It works fine on systemd service in ubuntu 18.04 with pulseaudio version 11.1 Update: After adding 'sound.target' as a dependency and sourcing these 2 env variables, it started working in systemd.
|
I was also having this issue inside a Docker container, and managed to solve it by adding: base.dockerfile:FROM ubuntu:22.04
WORKDIR /app
# (...) Python deps, ffmpeg, etc
RUN apt install -y pulseaudio
RUN adduser root pulse-access
COPY . /app
CMD /bin/bash entry.sh entry.sh:#!/bin/bash
pulseaudio --verbose --exit-idle-time=-1 --system --disallow-exit -D > /dev/null 2>&1
python3 entry.py entry.py:import soundcard
print("Wahoo, no PA_CONTEXT_READY assertion error") My directory of Dockerfiles and scripts for reference. Related sources used [1], I didn't need most of that stuff and dummy sinks and sources 🧐 |
Hey,
I have the following code:
It runs fine with
python test.py
But it does not when I want to run it using a systemd service.
Here's the service definition:
And the error it throws:
I tried with the sounddevice module instead of soundcard and I dont get this error so I guess the problem comes from soundcard and not PulseAudio?
Why all this: I'm making a sound installation, the main python program runs fine on the Raspberry (using multiple sound cards handled by the soundcard module, threading, ...), but I struggle to make it start at boot. It seems to run too early with rc.local or a crontab (because sound cards and/or pulseaudio itself are not initialized yet, I guess), so I tried with systemd but I faced the problem described above.
I'm still learning programming and how linux work so sorry if I missed something obvious and if the problem is actually unrelated to soundcard itself.
The text was updated successfully, but these errors were encountered: