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
pcm.!default {
type pulse
fallback "sysdefault"
hint {
show on
description "Default ALSA Output (currently PulseAudio Sound Server)"
}
}
ctl.!default {
type pulse
fallback "sysdefault"
}
Configuring PulseAudio
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
unload-module module-suspend-on-idle
load-module module-role-ducking
load-module module-combine-sink sink_name=OpenVoiceOS
set-default-sink 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
.ifexists module-udev-detect.so
load-module module-udev-detect tsched=0
.else
### Use the static hardware detection module (for systems that lack udev/hal support)
load-module module-detect
.endif
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.
Configuring Mycroft
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;
"tts": {
"module": "mimic2",
"mimic2": {
"lang": "en-us",
"url": "https://mimic-api.mycroft.ai/synthesize?text=",
"preloaded_cache": "/home/mycroft/.cache/mycroft/preloaded_cache/Mimic2"
},
"pulse_duck": true
},
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âŚ