Created
May 7, 2019 17:08
-
-
Save a1higgins-oss/89bb741968811f2b72bdf0e15b979421 to your computer and use it in GitHub Desktop.
TTS script using google translate
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 | |
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