Last active
April 28, 2021 03:12
-
-
Save aminmarashi/e3030b79dfd14c60fa7d488f170b1abb to your computer and use it in GitHub Desktop.
Read whatever is copied to clipboard (text-to-speech or tts) using nothing but cvlc and curl
This file contains hidden or 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 | |
## Needs cvlc and curl installed | |
if ! (which cvlc >/dev/null && which curl >/dev/null); then | |
echo 'Please make sure cvlc and curl are installed and added to the execution path' | |
exit 1; | |
fi | |
say() { | |
echo "$@" | tr . "\n" | tr \; "\n" | tr : "\n" | tr , "\n" | \ | |
split -C200 --filter='tee /dev/stderr | curl -m2 -sG --data-urlencode q@- -A b "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=En-us" | cvlc --rate 1.2 --play-and-exit - &>/dev/null' | |
} | |
prev=$(xclip -o -select clipboard); | |
while :; do | |
sleep 0.5; | |
text=$(xclip -o -select clipboard); | |
if [ "$prev" == "$text" ]; then | |
continue; | |
else | |
prev="$text"; | |
say $text; | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment