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

**URL:** https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009
**Category:** Archive - Mycroft Project
**Created:** [November 4, 2018, 3:58pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009 "2018-11-04T15:58:10Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 4, 2018, 3:58pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/1 "2018-11-04T15:58:10Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Jarbas\_Ai](https://community.openconversational.ai/user_avatar/community.openconversational.ai/jarbas_ai/32/801_2.png) [@Jarbas\_Ai](https://community.openconversational.ai/u/Jarbas_Ai)
#### Post date: [November 4, 2018, 4:35pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/2 "2018-11-04T16:35:15Z")

</div>

the CLI uses it to measure the mic level

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 4, 2018, 4:49pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/3 "2018-11-04T16:49:01Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![andlo](https://community.openconversational.ai/user_avatar/community.openconversational.ai/andlo/32/860_2.png) [@andlo](https://community.openconversational.ai/u/andlo)
#### Post date: [November 4, 2018, 5:18pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/4 "2018-11-04T17:18:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 4, 2018, 5:55pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/5 "2018-11-04T17:55:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![forslund](https://community.openconversational.ai/user_avatar/community.openconversational.ai/forslund/32/172_2.png) [@forslund](https://community.openconversational.ai/u/forslund)
#### Post date: [November 5, 2018, 6:23am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/6 "2018-11-05T06:23:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 5, 2018, 7:31am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/7 "2018-11-05T07:31:44Z")

</div>

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

> <https://github.com/MycroftAI/mycroft-core/blob/dev/mycroft/audio/audioservice.py#L28>

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?)

---

<div class="post-metadata">

### Author: ![forslund](https://community.openconversational.ai/user_avatar/community.openconversational.ai/forslund/32/172_2.png) [@forslund](https://community.openconversational.ai/u/forslund)
#### Post date: [November 5, 2018, 8:04am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/8 "2018-11-05T08:04:37Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 5, 2018, 10:12am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/9 "2018-11-05T10:12:31Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![forslund](https://community.openconversational.ai/user_avatar/community.openconversational.ai/forslund/32/172_2.png) [@forslund](https://community.openconversational.ai/u/forslund)
#### Post date: [November 5, 2018, 10:20am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/10 "2018-11-05T10:20:42Z")

</div>

That should definitely work.

---

<div class="post-metadata">

### Author: ![KathyReid](https://community.openconversational.ai/user_avatar/community.openconversational.ai/kathyreid/32/1949_2.png) [@KathyReid](https://community.openconversational.ai/u/KathyReid)
#### Post date: [November 5, 2018, 10:59am UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/11 "2018-11-05T10:59:29Z")

</div>

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+.

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 5, 2018, 1:39pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/12 "2018-11-05T13:39:26Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![forslund](https://community.openconversational.ai/user_avatar/community.openconversational.ai/forslund/32/172_2.png) [@forslund](https://community.openconversational.ai/u/forslund)
#### Post date: [November 5, 2018, 1:56pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/13 "2018-11-05T13:56:56Z")

</div>

The writing done is in the MutableMic in the speech client [mic.py L281](https://github.com/MycroftAI/mycroft-core/blob/dev/mycroft/client/speech/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?

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 5, 2018, 2:14pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/14 "2018-11-05T14:14:50Z")

</div>

Oh crap! Should not do this on Mondays…🤦‍♂️

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” 😄

---

<div class="post-metadata">

### Author: ![forslund](https://community.openconversational.ai/user_avatar/community.openconversational.ai/forslund/32/172_2.png) [@forslund](https://community.openconversational.ai/u/forslund)
#### Post date: [November 5, 2018, 2:18pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/15 "2018-11-05T14:18:02Z")

</div>

I think linux and sound is a nightmare for everyone… 😉

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

---

<div class="post-metadata">

### Author: ![j1nx](https://community.openconversational.ai/user_avatar/community.openconversational.ai/j1nx/32/1260_2.png) [@j1nx](https://community.openconversational.ai/u/j1nx)
#### Post date: [November 5, 2018, 5:20pm UTC](https://community.openconversational.ai/t/pulseaudio-to-be-or-not-to-be/5009/16 "2018-11-05T17:20:21Z")

</div>

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.
