Skip to content

Instantly share code, notes, and snippets.

@gwpl
Last active September 15, 2022 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/fbf465c62a11290e129b1167beb5ad2e to your computer and use it in GitHub Desktop.
Save gwpl/fbf465c62a11290e129b1167beb5ad2e to your computer and use it in GitHub Desktop.
Reading aloud content of clipboard. espeak fro clipboard under Linux / X (should work under other unixes , if required change `xclip` to something else )
#!/bin/bash
# e.g. -s 300 to read faster :
# read_clipboard_espeak.sh -s 300
# espeak has other parameters too, check man espeak-ng
#TTSCMD=espeak
TTSCMD=espeak-ng
if [ -z "$1" ]; then
xclip -selection clipboard -o | "$TTSCMD" -ven
elif [ "$1" == "code" ]; then
shift 1
xclip -selection clipboard -o | "$TTSCMD" -ven --punct "$@"
else
xclip -selection clipboard -o | "$TTSCMD" "$@"
fi
#!/bin/bash
# this one checks clipboard in a loop and reads in case of changes. Try to detect URLs and not to read them.
# e.g. -s 300 to read faster :
# read_clipboard_espeak_in_loop.sh -s 300
# espeak has other parameters too, check man espeak-ng
#TTSCMD=espeak
TTSCMD=espeak-ng
TTSargs=("-ven")
if [ "$1" == "code" ]; then
shift 1
TTSargs=("-ven" "--punct")
fi
prev=""
while [ 1 ]; do
curr="$(xclip -selection clipboard -o)"
if [[ "$curr" != "$prev" ]]; then
if [[ ! "$curr" =~ ^http ]]; then
echo READING: "$curr"
#set -x
echo "$curr" | "$TTSCMD" ${TTSargs[*]} "$@"
#set +x
else
echo IGNORING DUE TO "http" prefix: $curr
fi
fi
prev="$curr"
sleep 0.25
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment