Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions mannaggia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# --nds <n> : numero di santi da invocare (di default continua all'infinito)
# --shutdown : se nds > 0 e si e` root al termine delle invocazioni spegne
# --off : se si e` root invoca un solo santo e spegne (equivale a --nds 1 --shutdown)
audioflag=false
audiosrc=espeak
spm=1
spmflag=false
nds=-1
Expand All @@ -43,6 +43,46 @@ if [ $(uname) = "Darwin" ]
shufCmd=shuf
fi

espeak_best_voice() {
v=$(espeak --voices=it | tail -n +2 | awk '{ print $4 }' | grep -v mbrola | head -n1)
if [ -n "$v" ]; then
# shellcheck disable=SC2039
echo "-v $v -k10 -g1 -p 30"
return
fi
v=$(espeak --voices=it | tail -n +2 | awk '{ print $4 }' | head -n1)
if [ -n "$v" ]; then
# shellcheck disable=SC2039
echo "-v $v"
return
fi
echo " "
}
ESPEAK="espeak $(espeak_best_voice)"

vocalizza() {
if [ "$audioflag" = true ]
then
if [ "$audiosrc" = espeak ]
then
tmpwav=$(mktemp mannaggia-XXXXXXXX.wav)
trap 'rm -f "$tmpwav"' EXIT
$ESPEAK "$1" --stdout > "$tmpwav" 2> /dev/null
$PLAYER "$tmpwav"
rm -f "$tmpwav"
else
if [ "$audiosrc" = ispeech ]
then
MANNAGGIAURL="http://www.ispeech.org/p/generic/getaudio?text=$1%2C&voice=euritalianmale&speed=0&action=convert"
else
MANNAGGIAURL="http://translate.google.com/translate_tts?tl=it&q=$1"
fi

$PLAYER "$MANNAGGIAURL" 2>/dev/null
fi
fi
}

# lettura parametri da riga comando
for parm in "$@"
do
Expand All @@ -56,6 +96,15 @@ for parm in "$@"
}
audioflag=true
fi
if [ "$parm" = "--google" ]; then
audiosrc=google
fi
if [ "$parm" = "--espeak" ]; then
audiosrc=espeak
fi
if [ "$parm" = "--ispeech" ]; then
audiosrc=ispeech
fi

# leggi dai parametri se c'e' da mandare i commenti su wall
if [ "$parm" = "--wall" ]
Expand Down Expand Up @@ -123,7 +172,6 @@ while [ "$nds" != 0 ]
do
# shellcheck disable=SC2019
MANNAGGIA="Mannaggia $(curl -s "www.santiebeati.it/$(</dev/urandom tr -dc A-Z|head -c1)/"|grep -a tit|cut -d'>' -f 4-9|$shufCmd -n1 |awk -F "$DELSTRING1" '{print$1$2}'|awk -F "$DELSTRING2" '{print$1}' | iconv -f ISO-8859-1)"
MANNAGGIAURL="http://www.ispeech.org/p/generic/getaudio?text=$MANNAGGIA%2C&voice=euritalianmale&speed=0&action=convert"

if [ "$wallflag" = true ]
then
Expand All @@ -139,11 +187,7 @@ while [ "$nds" != 0 ]
echo "$MANNAGGIA" > /dev/stdout
fi

if [ "$audioflag" = true ]
then
$PLAYER "$MANNAGGIAURL" 2>/dev/null
fi

vocalizza "$MANNAGGIA"
sleep "$spm"
nds=$((nds - 1))
done
Expand Down