#!/usr/bin/env bash
# Given a choice of selecting settings to match pulseaudio if installedor alsa when not, they just install it broken and recommend pulseaudio, nice.

apt install -y speech-dispatcher speech-dispatcher-festival speech-dispatcher-espeak-ng python3-speechd espeak-ng espeak-ng-espeak 

SPEECHD_CONF=/etc/speech-dispatcher/speechd.conf

# Uncommented settings
sed -i 's,^\(LogLevel \).*,\1'4',' ${SPEECHD_CONF}
sed -i 's,^\(LogDir \).*,\1'\"default\"',' ${SPEECHD_CONF}
sed -i 's,^\(DefaultVolume \).*,\1'100',' ${SPEECHD_CONF}
#sed -i 's,^\(DefaultModule \).*,\1'festival',' ${SPEECHD_CONF}
sed -i 's,^\(DefaultModule \).*,\1'espeak-ng',' ${SPEECHD_CONF}
sed -i 's,^\(Include \).*,\1'\"clients\/\*\.conf\"',' ${SPEECHD_CONF}


# Commented - no space
#sed -i '/^#AddModule \"festival\".*/ s/.*/&\nAddModule \"festival\" \"sd_festival\" \"festival.conf\"/'  ${SPEECHD_CONF}
sed -i '/^#AddModule \"espeak-ng\".*/ s/.*/&\nAddModule \"espeak-ng\" \"sd_espeak-ng\" \"espeak-ng.conf\"/' ${SPEECHD_CONF}

#sed -i '/^#LanguageDefaultModule \"en\".*/ s/.*/&\nLanguageDefaultModule \"en\"  \"festival\"/'  ${SPEECHD_CONF}
sed -i '/^#LanguageDefaultModule \"en\".*/ s/.*/&\nLanguageDefaultModule \"en\"  \"espeak\"/'  ${SPEECHD_CONF}

sed -i '/^#AudioALSADevice \"default\".*/ s/.*/&\nAudioALSADevice \"default\"/'  ${SPEECHD_CONF}

# Commented - single space
sed -i '/^# AudioOutputMethod \"pulse\".*/ s/.*/&\nAudioOutputMethod \"alsa\"/'  ${SPEECHD_CONF}
