aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@users.noreply.github.com>2024-06-08 00:00:00 +0000
committertdro <tdro@users.noreply.github.com>2024-06-08 00:00:00 +0000
commit261369f8a4ddef50841808c293beddd3173a1503 (patch)
treeb940ba56bc71109944163053c6e00e0409b15c80
parent82400ad06ad4bfe2520adeeaced76bb6a781d60b (diff)
downloaddotfiles-261369f8a4ddef50841808c293beddd3173a1503.tar.gz
dotfiles-261369f8a4ddef50841808c293beddd3173a1503.tar.bz2
dotfiles-261369f8a4ddef50841808c293beddd3173a1503.zip
.local/bin/say: Fix this up
-rwxr-xr-x.local/bin/say85
1 files changed, 73 insertions, 12 deletions
diff --git a/.local/bin/say b/.local/bin/say
index 4537669..eb813d5 100755
--- a/.local/bin/say
+++ b/.local/bin/say
@@ -1,23 +1,84 @@
#!/bin/sh -eu
-audio=/tmp/speak-jfgOUcZdWu.wav
-text=${1:-Nothing to say.}
+program=$(basename "$0")
+voices=$HOME/.local/share/piper/voices
-[ "${1-}" = "echo" ] && $0 "${2-}" "${1-}" && exit;
+identifier=jfgOUcZdWu
+audio=/tmp/say-$identifier.wav
+default=${1:-Nothing to say.}
-printf '%s' "$text" |
- piper \
- --model "$HOME/.local/share/piper/voices/en_GB-jenny_dioco-medium.onnx" \
- --output_file $audio
+trap 'rm $audio > /dev/null 2>&1 || true; trap - EXIT; exit' EXIT INT HUP
+
+Help() {
+printf \
+"
+Usage: %s [FLAGS]... [ARGUMENT]...
+
+The program $program shall use TTS (Text to Speech)
+to convert a given text input into speech.
+
+ Command List:
+
+ $program 'text' Say given text.
+ $program echo 'text' Say given text with echo effect.
+ $program check Checks dependencies.
+ $program download Download default voice.
+ $program help -h -help --help Show this help menu.
+
+" "$program";
+}
+
+Check() {
+ mplayer
+ ffmpeg -version
+ wget -version
+ piper --version
+ mkdir --version
+ rm --version
+}
+
+Say() {
+ Piper && mplayer -really-quiet "$audio"
+}
+
+Piper() {
+ [ ! -e "$voices/en_GB-jenny_dioco-medium.onnx" ] && Download
+ printf '%s' "$default" |
+ piper \
+ --model "$voices/en_GB-jenny_dioco-medium.onnx" \
+ --output_file $audio > /dev/null 2>&1
+}
+
+Wget() {
+ wget --progress=bar --quiet --show-progress --directory-prefix "$voices" "$@"
+}
+
+Download() {
+ mkdir --parents "$voices"
+ Wget "https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_GB/jenny_dioco/medium/en_GB-jenny_dioco-medium.onnx.json?download=true.json" \
+ -O "$voices/en_GB-jenny_dioco-medium.onnx.json"
+ Wget "https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_GB/jenny_dioco/medium/en_GB-jenny_dioco-medium.onnx?download=true" \
+ -O "$voices/en_GB-jenny_dioco-medium.onnx"
+}
+
+{ [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]|| [ "${1:-}" = "--help" ] || [ "$#" = 0 ]; } && Help && Say && exit
+
+[ "${1:-}" = "help" ] && Help && Say && exit
+
+[ "${1:-}" = "check" ] && Check && exit
+
+[ "${1:-}" = "download" ] && Download && exit
+
+[ "${1-}" = "echo" ] && $0 "${2-}" "${1-}" && exit
[ "${2-}" = "echo" ] &&
- ffmpeg \
+ Piper && ffmpeg \
-y \
-i "$audio" \
-map 0 \
-c:v copy \
- -af aecho=1:1:50:0.5,atempo=0.85 "$audio.mp3" &&
- mplayer -really-quiet "$audio.mp3" &&
- exit;
+ -af aecho=1:1:50:0.5,atempo=0.85 "$audio.mp3" > /dev/null 2>&1 \
+ && mplayer -really-quiet "$audio.mp3" \
+ && exit
-mplayer -really-quiet "$audio";
+Say