Skip to content

Instantly share code, notes, and snippets.

@erm3nda
Last active June 20, 2016 14:57
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 erm3nda/3899847f2b6fbec4543a6a5ca2de2fd4 to your computer and use it in GitHub Desktop.
Save erm3nda/3899847f2b6fbec4543a6a5ca2de2fd4 to your computer and use it in GitHub Desktop.
vozme.com online text 2 speech service with bash
#!/bin/bash
# sample url: http://vozme.com/speech/es-fm/5d/5d40a31e1164b793c6200780c5dafb5e.mp3
# set a random filename for wget tmp data (html output)
# used 3:-33 instead 1:-32 to avoid $1 argument clash
tmpfile=/tmp/`< /dev/urandom tr -dc A-Za-z0-9 | head -c${2:-33}`.txt
tmpaudio=/tmp/`< /dev/urandom tr -dc A-Za-z0-9 | head -c${2:-33}`.mp3
# argument checking for $1 ("use quoted text")
if [ -z "$1" ]
then
text="Emisora no conectada!"
else
text=$1
fi
# some hardcoded options
lang="es"
gender="ml" #male, note that spanish lang has no fm (female) voice
# the main function
# that 2> redirection is the only way i've found to read url from a txt without download resources with wget
vozme=`wget --spider -r -l 1 -A mp3 --post-data="text=$text&lang=$lang&gn=$gender" "http://vozme.com/text2voice.php" 2> $tmpfile`
url=`cat $tmpfile | grep -o "http.*.mp3"` # that's what matters
rm -rf vozme.com $tmpfile # wtf folder still being created :/
# the output
echo "Playing $text at $url"
notify-send "Playing: $text at $url"
# play sound online
#~ xdg-open $url # this open the sound on the browser
# xvfb-run -a vlc $url vlc://quit # nice alternative because play command doesn't support remote audio but it's quite slow
# download and play ( used this way to use only terminal stuff and avoid anything related to Xorg )
curl -L $url > $tmpaudio
lame --decode $tmpaudio - | play - # decode to wav then play
rm $tmpaudio # remove tmp file
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment