Skip to content

Instantly share code, notes, and snippets.

@a1higgins-oss
Created May 7, 2019 17:08
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 a1higgins-oss/89bb741968811f2b72bdf0e15b979421 to your computer and use it in GitHub Desktop.
Save a1higgins-oss/89bb741968811f2b72bdf0e15b979421 to your computer and use it in GitHub Desktop.
TTS script using google translate
#!/bin/bash
if [ $1 = "-h" ]
then
echo "Usage: $0 outfile language text"
exit 0
fi
cache_dir="/var/cache/google-translate-tts"
tmpfile=$(mktemp /tmp/google-translate-tts.XXXXXXXX)
filename_md5=$(echo -n $3 | md5sum)
filename=$cache_dir"/"${filename_md5%% *}".wav"
echo $tmpfile
echo $filename
if [ ! -d $cache_dir ]
then
echo $cache_dir" does not exist. Please create with needed permissions."
fi
if [ -s $filename ]
then
echo "Using cached audio file "$filename
else
echo "Caching new audio file "$filename
wget -q -U Mozilla -O $tmpfile "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=$2&q=$3"
mpg123 --quiet --wav $filename $tmpfile
rm -f $tmpfile
fi
cp $filename $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment