-
-
Save iamahuman/e9b2694b301a3c4a95e331e8200fd066 to your computer and use it in GitHub Desktop.
Speak Selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PIDFILE=/tmp/.sp.pid | |
on_exit() { | |
code="$?" | |
echo "Killing $pid" | |
kill -TERM "$pid" | |
exit "$code" | |
} | |
[ -r "$PIDFILE" ] && pkill -TERM -F "$PIDFILE" 2> /dev/null || true | |
while pgrep -F "$PIDFILE" 2> /dev/null | |
do | |
sleep .1 | |
done | |
echo $$ > "$PIDFILE" | |
trap on_exit INT TERM | |
xclip -selection primary -o | tr '\n' ' ' | sed 's/\. \+/&\n/g;$a\\n' | { | |
trap '[ -n "$pid" ] && kill $pid; exec <&-; exit' INT TERM | |
while read -r SENTENCE | |
do if [ -n "$SENTENCE" ]; then | |
echo "$$: $SENTENCE" >&2 | |
espeak-ng --stdin -a80 -k20 -b1 -p50 <<<"$SENTENCE" & pid=$! | |
wait | |
fi; done | |
} & pid=$! | |
wait | |
rm -f "$PIDFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment