synesthesiam/homeassistant-satellite

Pulseaudio throwning an error

Opened this issue · 3 comments

I installed pulseaudio according to the installation instructions. I used the --pulseaudio switch and when I run the script, I get the following:

ERROR:main:Sound error in _playback_proc
Traceback (most recent call last):
File "/home/bubba/homeassistant-satellite/homeassistant_satellite/main.py", line 472, in _playback_proc
with play_ctx as (play, duck):
File "/usr/lib/python3.11/contextlib.py", line 137, in enter
return next(self.gen)
^^^^^^^^^^^^^^
File "/home/bubba/homeassistant-satellite/homeassistant_satellite/snd.py", line 190, in play_pulseaudio
with pulsectl.Pulse(server=server_name) as pactl, _pulseaudio_echo_cancel(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bubba/homeassistant-satellite/.venv/lib/python3.11/site-packages/pulsectl/pulsectl.py", line 380, in init
try: self.connect(autospawn=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bubba/homeassistant-satellite/.venv/lib/python3.11/site-packages/pulsectl/pulsectl.py", line 443, in connect
if self.connected is False: raise PulseError('Failed to connect to pulseaudio server')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulsectl.pulsectl.PulseError: Failed to connect to pulseaudio server
Traceback (most recent call last):
File "/home/bubba/homeassistant-satellite/script/run", line 13, in
subprocess.check_call(
File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/bubba/homeassistant-satellite/.venv/bin/python3', '-m', 'homeassistant_satellite', '--host', '10.250.2.50', '--token-file', 'token.txt', '--mic-device', 'plughw:CARD=S330,DEV=0', '--snd-device', 'plughw:CARD=S330,DEV=0', '--pipeline', 'hey_jarvis', '--awake-sound', 'sounds/how_may_i_assist.mp3', '--vad', 'silero', '--noise-suppression', '2', '--pulseaudio', '--debug']' returned non-zero exit status 255.

Not really sure what this means or how to fix it.

pulseaudio expects your application to be run as user. If you did't configure pulseaudio to run systemwide and followed the installation instructions here this will probably cause your error.

I had the same issue and solved it with creating the homeassistant-satellite service as user service:
systemctl edit --user --force --full homeassistant-satellite.service
(without sudo!)
Then enable the service:
systemctl --user enable --now homeassistant-satellite.service

and control it like this:
systemctl --user restart homeassistant-satellite.service

For me it worked.

If you prefer to run homeassistant-satellite as root (although pulseaudio itself runs as user), it is possible, you just need to pass the pulseaudio socket as a parameter. For instance:

--pulseaudio /var/run/user/1000/pulse/native

It's also possible to run homeassistant-satellite in docker, and either mount the socket inside the container, or enable tcp in pulseaudio and connect as --pulseaudio <host-ip-address>.

I tried the instructions for using pulseaudio with the docker container without success... pulseaudio not installed in the container?

hass-satellite-homeassistant-satellite-1  | CRITICAL:root:Please pip install homeassistant_satellite[pulseaudio]
hass-satellite-homeassistant-satellite-1  | ERROR:__main__:Sound error in _playback_proc
hass-satellite-homeassistant-satellite-1  | Traceback (most recent call last):
hass-satellite-homeassistant-satellite-1  |   File "/usr/src/app/homeassistant_satellite/__main__.py", line 472, in _playback_proc
hass-satellite-homeassistant-satellite-1  |     with play_ctx as (play, duck):
hass-satellite-homeassistant-satellite-1  |   File "/usr/local/lib/python3.11/contextlib.py", line 137, in __enter__
hass-satellite-homeassistant-satellite-1  |     return next(self.gen)
hass-satellite-homeassistant-satellite-1  |            ^^^^^^^^^^^^^^
hass-satellite-homeassistant-satellite-1  |   File "/usr/src/app/homeassistant_satellite/snd.py", line 179, in play_pulseaudio
hass-satellite-homeassistant-satellite-1  |     import pasimple
hass-satellite-homeassistant-satellite-1  | ModuleNotFoundError: No module named 'pasimple'
hass-satellite-homeassistant-satellite-1 exited with code 255

EDIT: just noticed that there is a PR for this... :)