This file contains 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 | |
# Created: 19-05-2013 19:00h | |
# Last Change: 21-05-2013 10:39h | |
# Author: Sergio Luiz Araujo Silva | |
# Site: http://vivaotux.blogspot.com/ | |
# Twitter: @voyeg3r | |
# this script gets the mp3 version of one given string from google translate | |
# references: | |
# http://stackoverflow.com/questions/9163988/download-mp3-from-google-translate-text-to-speech | |
# http://www.commandlinefu.com/commands/view/8044/google-text-to-speech-in-mp3-format | |
# http://saironiq.blogspot.com.br/2011/03/google-text-to-speech-api.html | |
# http://crunchbang.org/forums/viewtopic.php?id=17034 | |
# http://lifehacker.com/5426797/google-translate-url-generates-instant-text+to+speech-mp3-files | |
# próximo passo tornar esse script mais legível | |
FILENAME="${@:?Usage: $0 give me some words to speech}" | |
FILENAME=`awk '{print tolower($0)}' <<< "$FILENAME"` | |
#[ "${#FILENAME}" -gt 100 ] && echo "Only strings smaller than 100 chars" && exit 1 | |
# FILENAME="${FILENAME// /+}+' '" | |
! ping -n -c 4 -i 0.2 -W1 www.google.com > /dev/null && echo 'Connection error!' || \ | |
wget -q -U Mozilla -O "${FILENAME// /_}.mp3" "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=${FILENAME// /+}+' '" | |
[ -f "${FILENAME// /_}.mp3" -a ! -s "${FILENAME// /_}.mp3" ] && { rm -f "${FILENAME// /_}.mp3" ; exit 1 ; } | |
command -v mpg321 > /dev/null && mpg321 -q "${FILENAME// /_}.mp3" |