If you are looking for “muting/ducking while listening”, yes this can be done utilizing PulseAudio. Below information is already here and there on the forums, but let’s all put in in one post for future references.
Sent all sound to PulseAudio
First we make sure we use PA for all sound input and output, by forcing ALSA Userland to forward everything to PulseAudio. For this you need to have the “alsa-plugins” package available / installed.
Replace the content of “/etc/asound.conf” with the below content;
# Use PulseAudio by default
description "Default ALSA Output (currently PulseAudio Sound Server)"
Now we need to (re)configure the PA settings. Below are the settings we currently use for OpenVoiceOS (OVOS).
Open your PulseAudio daemon.conf file and implement the below settings;
# OpenVoiceOS Audio Settings
resample-method = ffmpeg
default-sample-format = s16le
default-sample-rate = 44100
alternate-sample-rate = 48000
avoid-resampling = true
flat-volumes = no
I will explain the above settings a bit, so you can decide if you want them or not, or need to alter them a bit for your system / hardware. Following a bit different order for explaination sake.
avoid-resampling = true : If possible avoid resampling. This means that if the hardware and/or driver supports the below settings, configure the device to use them instead of resampling the stream. This does not mean that resampling will never happen. If the hardware can not be set / configured it still resamples.
default-sample-format = s16le : This sets the default sample format to “bits, signed, little endian” which is a ‘safe’ setting for most hardware.
default-sample-rate = 44100 : This sets the default sample rate to 44.1 kHz which again is a common, widely used ‘safe’ standard.
alternate-sample-rate = 48000 : If 44.1 kHz is not possible, use 48.0 kHz as alternative next commonly used ‘safe’ standard.
resample-method = ffmpeg : This sets to use ‘ffmpg’ as the resample audio library. For the Raspberry Pi with limited resources this is in my opinion the best compromise between speed, resources and quality. Just MAKE SURE you have the ffmpeg package installed on your system.
flat-volumes = no : As the standard mycroft volume skill is controlling the sound using the ALSA Master control (which will work because we push everything to PA anyhow), don’t let PulseAudio individually control the volumes of the different applications. This prevents that the PA makes a mess of the different volumes.
Next we need to configure the modules used by PulseAudio. If you run PA as systemwide deamon alter the ‘system.pa’ file. If you run as a normal user, alter 'default.pa’file. Make sure the settings reflect the below settings;
### OpenVoiceOS Audio Settings
load-module module-combine-sink sink_name=OpenVoiceOS
Again a quick run through.
unload-module module-suspend-on-idle : Make sure we do not suspend the the audio device when being idle for some time. You can also uncoment the loading of it elsewhere, I choose this method so I can just compy & paste that block at the bottom of the file.
load-module module-role-ducking : This module is used by Mycroft to lower the volume of the sound output as soon as it hears the wakeword.
load-module module-combine-sink sink_name=OpenVoiceOS : This takes all sound outputs / sinks and combines them all into a new virtual sink called ‘OpenVoiceOS’ (Call it whatever you want). With this enabled it doesn’t matter where you connected your speaker, be it HDMI-1, -2 3.5 jack or whatever. If will receive the sound.
set-default-sink OpenVoiceOS : Make the above configured sink the default of PA.
Now for the last configuration change we need to scroll up in the file and find the loading part of sound devices based on udev and add the ‘tsched=0’ variable to the loading of the module. Below the code block as being used within OpenVoiceOS;
### Automatically load driver modules depending on the hardware available
load-module module-udev-detect tsched=0
### Use the static hardware detection module (for systems that lack udev/hal support)
As the Raspberry Pi does not have a Real Time Clock (RTC) / hardware clock, we are better of to NOT use time based scheduling of the soundstream. This will decrease the delay of sound output a lot, with the trade off that some heavy / high bitrate streams might have some glitches at the start. For most sound output and the voice output this is not a problem most of the time.
With above settings PA is in shape to tell Mycroft to make use of the mute while speaking. This can be done by adding the
"pulse_duck": true to your mycroft.conf TTS section. As example, below the specific block of code again used within OpenVoiceOS;
Just make sure you properly format as json / minding all the comma’s and brackets here and there.
Now reboot and see if everything works as expected. Enjoy…