Traductor charrán

Retoque del anterior script traductor para que utilice TTS (text to speech). Si el idioma de destino es distinto del español tendremos sonido con la pronunciación en el idioma elegido; no funciona con todos los idiomas y, en algunos es poco práctico pues "describe" los acentos en lugar de pronunciarlos.
Necesita mplayer para reproducir el streaming.


#!/bin/bash

function translate () {
if [ $# = 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo -e "Traduce texto con el Google Translator."
echo -e " Uso :"
echo -e " $(basename ${0}) idioma_de_origen idioma_de_destino texto "
echo -e " $(basename ${0}) -l para la lista de idiomas"
exit
fi
if [ "$1" = "-l" ]; then
echo -e "        afrikaans af
albanés sq francés fr persa fa
alemán de galés cy polaco pl
árabe ar gallego gl portugués pt
armenio hy georgiano ka rumano ro
azerí az griego el ruso ru
bieloruso be hebreo iw serbio sr
búlgaro bg hindi hi suajili sw
catalán ca holandés nl sueco sv
checo cs húngaro hu tagalo tl
chino zh indonesio id tailandés th
ch_trd zh-TW inglés en turco tr
coreano ko irlandés ga ucraniano uk
creole H. ht islandés is urdu ur
croata hr italiano it vietnamit vi
danés da japonés ja yiddish yi
eslovaco sk letón lv
esloveno sl lituano lt
español es macedonio mk
estonio et malayo ms
euskera eu maltés mt
return
fi
SRC=$1
DST=$2
shift
shift
TEXT="$@"

wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$TEXT&langpair=${SRC}|${DST}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/' > /tmp/voz

texto=`cat /tmp/voz`
echo $texto

if [ "${DST}" != "es" ]; then
mplayer -really-quiet "http://translate.google.com/translate_tts?tl=${DST}&q=$texto" 2> null
fi
}

translate $*


[Editado el 29-10-2011]
The Google Search and Language APIs shown to the right have been officially deprecated. They will continue to work as per our deprecation policy, but the number of requests you may make per day will be limited
.

O sea, que este script deja de funcionar.

No hay comentarios: