Who is doing what? Using which userspace sound system?
Linux and sound is and has always been a pain in the @$$ if you ask me personally. Sound control within the Mycroft software stack is no exception, although A LOT has been improved lately. However at the moment there are some inconsistencies in who is doing what and by using which userland system.
I would like to open a dialog about this, your ideas and figure out the best way forward.
Information
At this moment we can force mycroft-core to use PulseAudio by changing;
"play_wav_cmdline": "aplay -Dhw:0,0 %1"
"play_mp3_cmdline": "mpg123 -a hw:0,0 %1"
to;
"play_wav_cmdline": "aplay %1"
"play_mp3_cmdline": "mpg123 %1"
This all works fine, and WAV and MP3 are played using the default sink of PulseAudio. However the volume control of mycroft itself is handled by this skill (hence the reason I open the dialog here), BUT is forced to use ALSA and its mixers or nothing at all.
Looking at the code of the skill, there are a couple things that jump out;
https://github.com/MycroftAI/skill-volume/blob/19.08/__init__.py#L26
It it using the enclosure - platform config parameter to push it towards using ALSA or not. However if it not pushed into the ALSA_PLATFORM array, there is no fallback other than telling the mycroft.messagebus about it. This should then be picked up by something else. I believe the enclosure code should listen to the messagebus and do the volume stuff as stated here;
https://github.com/MycroftAI/skill-volume/blob/19.08/__init__.py#L132
The strange thing is, there aren't many enclosures at the moment. You have the mark-1 enclosure, but that one is forced to use ALSA here in the skill. There was no picroft enclosure, although a dialog has been started about it and a initial enclosure has been created with two simple controls for shut down and reboot;
https://github.com/MycroftAI/enclosure-picroft/blob/09488ffa30872b032a4e29cb5ef5355ef1d46400/home/pi/enclosure/PicroftEnclosure.py
But again nothing about the volume and again, it is being pushed into using ALSA within the skill.
The mark-2 has its own enclosure code I believe, however volume control of it is being handled by a skill instead of the enclosure code;
https://github.com/MycroftAI/skill-mark-2-pi/blob/master/__init__.py#L185
I don't know why volume for the mark-2 is handled by directly communication with the I2S bus instead of using ALSA or PulseAudio. Probably because volume control via PulseAudio is not supported.
My idea / opinion
I strongly believe this volume skill should support both ALSA and PulseAudio.
How this could be done in a sane matter is a bit unclear though;
- Create a PULSE_PLATFORM setting and extend the IF, THEN, ELSE structure with pulsectl functions?
- Look at the "play_wav_cmdline" and "play_mp3_cmdline" parameters and figure it out from there itself?
- ...??
Background
Perhaps a bit of backgrounud information about how I come to this topic.
For MycroftOS I am setting up the system to ONLY use PulseAudio. This to have better control about the sinks and sources using the UDEV modules and let PulseAudio kook up straight into the kernel without the need of the ALSA userland system.
This is preperation for other plugins such as resampling and/or AEC Webrtc of PulseAudio.
For MycroftOS I have set the enclosure config parameter to "MycroftOS" and with that parameter set, this volume skill was not doing anything anymore.
Patched this skill to include my enclosure tag into the ALSA_PLATFORM string
For now I am forcing ALL ALSA requests to pulseaudio using the alsa-plugins, which works just fine.
https://github.com/j1nx/MycroftOS/blob/develop/buildroot-external/rootfs-overlay/etc/asound.conf