Pulseaudio: To be or not to be...?

When I first came into contact with Mycroft and started playing with it on a raspbian stretch install, the information at hand told me pulseaudio was needed.

Later in time reading different feedback from the chat and forums showed me, pulseaudio was not needed and alsa audio should work just as fine.

For MycroftOS which is bare minimal, I do not want any packages if they are not really needed. At first I had pulseaudio installed, however removing it works just as good, so want to leave it out. However.

First I stopped pulseaudio and tested everything. All good. Confirmed: Pulseaudio is not needed.

I then rebuild the firmware without pulseaudio and tested it. ERROR in mycroft audio because it found python-pulsectl, loaded it but errored out because pulseaudio was no longer there.

Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/usr/lib/python3.6/site-packages/mycroft/audio/main.py”, line 27, in
from .audioservice import AudioService
File “/usr/lib/python3.6/site-packages/mycroft/audio/audioservice.py”, line 27, in
import pulsectl
File “/usr/lib/python3.6/site-packages/pulsectl/init.py”, line 4, in
from . import _pulsectl
File “/usr/lib/python3.6/site-packages/pulsectl/_pulsectl.py”, line 620, in
pa = LibPulse()
File “/usr/lib/python3.6/site-packages/pulsectl/_pulsectl.py”, line 572, in init
p = CDLL(‘libpulse.so.0’)
File “/usr/lib/python3.6/ctypes/init.py”, line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: File not found

Removed python-pulsectl, rebuild the firmware. All good in mycroft audio, everything looked great.

Started the mycroft-cli-client; ERROR because python-pulsectl was not installed ?!?!

Traceback (most recent call last):
File “/usr/bin/mycroft-cli-client”, line 6, in
from pkg_resources import load_entry_point
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 3147, in
@_call_aside
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 3131, in _call_aside
f(*args, **kwargs)
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 3160, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 666, in _build_master
ws.require(requires)
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 984, in require
needed = self.resolve(parse_requirements(requirements))
File “/usr/lib/python3.6/site-packages/pkg_resources/init.py”, line 870, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The ‘pulsectl==17.7.4’ distribution was not found and is required by mycroft-core

So the question is; Pulseaudio, now do we need it or not?

Secondly, why does the CLI really needs it?

the CLI uses it to measure the mic level

OK, but then it is clear that pulseaudio is a requirement for Mycroft!

But I believe the latest picroft version doens not have pulseaudio installed? Or am I wrong?

The latest picroft dont have pulseaudio. That gave me problems whith Google aiy voicekit, so i installer it.
I think it is nedded in most situations.

That is what I thought, but how come the CLI error does not pop up on there. Will ping @KathyReid to ping the right dev-guy when she wakes up.

If pulse audio is only needed for the mic level why not move it to portaudio alsa bindings or something. Or better, just plain alsa.

Considering all the mic questions lately, this might need some love after the KDE project.

2 Likes

Since the pulsectl is in the setup.py requirements, just removing it will cause an error in all the declared entry-points if it’s uninstalled.

Seems the import exception capture in audio isn’t capturing enough (ImportError only). A change line 28 in audioservice to except Exception: should resolve the issue.

Ok so, in; mycroft-core/audio/audioservice.py

Change line 28 from;
except ImportError:

To:
except Exception:

Should at least start the audio service again if pulsaudio is not there, but python-pulsectl is.

OK, I consider this a workaround for my specific case. I only use the CLI for testing purposes during development. In the end product, a similar CLI type of thing should be webbased anyway.

However, remains the question: If the audio and voice services can run just fine with alsa only. Isn’t there an option to remove pulseaudio from the cli service as well?

(I guess for my workaround I will patch requirements.txt to remove the python-pulsectl instead of the above patch. Rather don’t have the package and a not working mic level indicator in the CLI that i am most likely not going to use anyway. Do you forsee any issues with that up front?)

It’s not actually used in the cli, only the audio process, but as it’s included in the requirements.txt the entrypoints created by the setup.py install script adds it as a runtime requirement. (all the mycroft python script will error if it’s not installed but as it’s not loaded there is no error if it’s installed but pulseadio is actually missing).

Yeah, was looking at the CLI code. It grabs the mic level from IPC. Can’t find the code that writes the mic level to IPC.

What I would like to do;

  • Patch audioservice.py as described above
  • Patch requirements.txt to remove pulsectl
  • No pulseaudio installed

Not at my workstation atm, but will above work? Not sure how the mic level get’s written to IPC. If that again relies on pulsectl then above will not work ofcourse…

That should definitely work.

I can’t give you a definitive answer on why Pulseaudio is needed @j1nx, but I can definitely say that one of the most frequent workarounds we have for audio issues under the Picroft Debian Stretch lite installation is to install Pulseaudio.

I would definitely recommend installing it.

This is one of the things that caught us during the move from Jessie Lite to Stretch Lite and also with the RPi 3 to the RPi 3B+ - a lot of the audio and sound processing was re-architected; what worked under Jessie Lite on an RPi didn’t work “out of the box” with Stretch Lite on an RPi 3B+.

@forslund Ok, great, then I will do just that. Pure out of curiousity / interest, could you point me to the code that writes the MIC level to the IPC system? (Only if you have time for it)

@KathyReid I agree that sound on linux using ALSA is tricky. I believe most of the errors related to sound and ALSA come from the fact that with ALSA only one program can access the hardware. For instance, you need to stop Mycroft service to run mycroft-audio-test otherwise you get one of those annoying resource busy errors. Pulseaudio will act as a proxy.

However for my MycroftOS project, there are no other users, nor other programs or processes. The OS is only made for and to be used by mycroft.

Therefor, I believe (hope) that I can get away with above patches.

The writing done is in the MutableMic in the speech client mic.py L281

Regarding no other processes, you don’t plan to allow media players or skills starting audio and things like that? Or will alsa work as long as the parent process is common?

Oh crap! Should not do this on Mondays…:man_facepalming:

Indeed, there I might run into troubles. Although not sure. Linux and sound has always been a nightmare to me for some reason…

Anyway, thx for the mic.py pointer. One day I will get “there” :smile:

1 Like

I think linux and sound is a nightmare for everyone… :wink:

I’m sure you’ll get there eventually, and I hope I’m more of a help than a hindrance.

1 Like

You are a perfect help. All of you guys and girls for that matter.

Just saw the PR update on github, kind of forgot about that. However, with that and this in mind, will install pulseaudio and pulsectl. Just not systemwide and let is spawn a process when needed.

That should be the way forward.

2 Likes