diff --git a/docs/install_pulseaudio.md b/docs/install_pulseaudio.md index ec8a84f..03ce2d9 100644 --- a/docs/install_pulseaudio.md +++ b/docs/install_pulseaudio.md @@ -73,7 +73,7 @@ systemctl --system start pulseaudio.service ## 10. Ensure pi user is in the `pulse-access` group: - +***If you aren't using the default "pi" user, put your user in here instead of "pi".*** ```sh sudo sed -i '/^pulse-access:/ s/$/root,pi/' /etc/group ``` @@ -97,7 +97,7 @@ pactl set-default-sink alsa_output.platform-soc_sound.stereo-fallback ``` -## 13. Test and make sure you can hear the wav file: +## 13. Test and make sure you can hear the wav file.: ```sh paplay /usr/share/sounds/alsa/Front_Center.wav @@ -106,15 +106,115 @@ paplay /usr/share/sounds/alsa/Front_Center.wav **Note that if you have a Raspbery Pi 3B or 4B, this may or may not seem to work, but it will output on the hat as intended.** -## 14. Modify PulseAudio to duck the music volume when you or the voice assistant are speaking: +## 14. The following modifications are specifically required for LVA's mpv_player.py to work with PA. If you do not have a working PA at this point, do not proceed.: +Backup current PA daemon.conf file. -```sh -sudo sed -i.bak \ - -e '$a### Enable Volume Ducking' \ - -e '$aload-module module-role-ducking trigger_roles=announce,phone,notification,event ducking_roles=any_role volume=25%' \ - /etc/pulse/system.pa +```bash +sudo cp /etc/pulse/daemon.conf{,.bak.$(date +%s)} ``` +Update the PA /etc/pulse/daemon.conf file with required change. Replaces if present (commented or not). + +```bash +sudo sed -i -E \ + -e 's|^[#;[:space:]]*exit-idle-time\s*=.*$|exit-idle-time = -1|' \ + -e 's|^[#;[:space:]]*resample-method\s*=.*$|resample-method = trivial|' \ + -e 's|^[#;[:space:]]*flat-volumes\s*=.*$|flat-volumes = no|' \ + -e 's|^[#;[:space:]]*default-sample-rate\s*=.*$|default-sample-rate = 44100|' \ + -e 's|^[#;[:space:]]*alternate-sample-rate\s*=.*$|alternate-sample-rate = 48000|' \ + -e 's|^[#;[:space:]]*default-fragment-size-msec\s*=.*$|default-fragment-size-msec = 15|' \ + /etc/pulse/daemon.conf +``` + +Just in case the values were missing, may not be needed but shouldn't hurt. + +```bash +for kv in \ + 'exit-idle-time = -1' \ + 'resample-method = trivial' \ + 'flat-volumes = no' \ + 'default-sample-rate = 44100' \ + 'alternate-sample-rate = 48000' \ + 'default-fragment-size-msec = 15'; do + k="${kv%% =*}" + sudo grep -Eq "^[[:space:]]*${k}[[:space:]]*=" /etc/pulse/daemon.conf || echo "$kv" | sudo tee -a /etc/pulse/daemon.conf >/dev/null +done +``` + +Backup current PA system.pa file. + +```bash +sudo cp /etc/pulse/system.pa{,.bak.$(date +%s)} +``` + +Update the PA /etc/pulse/system.pa file with required change. Replaces if present (commented or not). + +```bash +sudo sed -i -E \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-udev-detect)([[:space:]].*)?$|\1 tsched=0|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-native-protocol-unix.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-default-device-restore.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-always-sink.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-position-event-sounds.*)$|\1|' \ + /etc/pulse/system.pa +``` + +Just in case the values were missing, may not be needed but shouldn't hurt. + +```bash +for m in \ + 'load-module module-native-protocol-unix' \ + 'load-module module-default-device-restore' \ + 'load-module module-always-sink' \ + 'load-module module-position-event-sounds'; do + sudo grep -Eq "^[[:space:]]*$m(\s|$)" /etc/pulse/system.pa || echo "$m" | sudo tee -a /etc/pulse/system.pa >/dev/null +done +``` + +Backup current PA default.pa file. + +```bash +sudo cp /etc/pulse/default.pa{,.bak.$(date +%s)} +``` + +Update the PA /etc/pulse/default.pa file with required change. Replaces if present (commented or not). + +sudo sed -i -E \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-udev-detect)([[:space:]].*)?$|\1 tsched=0|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-native-protocol-unix.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-default-device-restore.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-always-sink.*)$|\1|' \ + -e 's|^[#;[:space:]]*(load-module[[:space:]]+module-intended-roles.*)$|\1|' \ + /etc/pulse/default.pa + +Just in case the values were missing, may not be needed but shouldn't hurt. + +```bash +for m in \ + 'load-module module-native-protocol-unix' \ + 'load-module module-default-device-restore' \ + 'load-module module-always-sink' \ + 'load-module module-intended-roles'; do + sudo grep -Eq "^[[:space:]]*$m(\s|$)" /etc/pulse/default.pa || echo "$m" | sudo tee -a /etc/pulse/default.pa >/dev/null +done +``` + +Optional since LVA handles duck/unduck: if you enabled role-ducking explicitly in system.pa, you can comment it out with: + +```bash +sudo sed -i -E 's|^([[:space:]]*)load-module[[:space:]]+module-role-ducking\b|# \0|' /etc/pulse/system.pa +``` +Restart PA and verify + +```bash +sudo systemctl restart pulseaudio.service +``` + +Test mpv can ouput to PA with current configs: + +```bash +mpv --ao=pulse --audio-device=default --audio-samplerate=44100 /usr/share/sounds/alsa/Front_Center.wav +``` ## 15. Reboot your Pi: (see step 4) @@ -126,3 +226,4 @@ sudo sed -i.bak \ +