Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Teach" Python other languages (TTS speaking...) HowTo?

So I found this code:

#!/usr/bin/python

import sys      #for cmd line argv
import time     #for delay
import pygst        #for playing mp3 stream
import gst      # " "

#take command line args as the input string
input_string = sys.argv
#remove the program name from the argv list
input_string.pop(0)

#convert to google friendly url (with + replacing spaces)
tts_string = '+'.join(input_string)

print tts_string

#use string in combination with the translate url as the stream to be played
music_stream_uri = 'http://translate.google.com/translate_tts?q=' + tts_string
player = gst.element_factory_make("playbin", "player")
player.set_property('uri', music_stream_uri)
player.set_state(gst.STATE_PLAYING)

#requires a delay, if the py process closes before the mp3 has finished it will be cut off.
time.sleep(12)

Wich is a great example of usage of the Google's "Text to Speech" Feature available in Google Translate using Python, the problem is, it only can "speak" in English! passing a text in spanish (for example) makes the TTS feature to speak "spanglish" while in the browser the TTS Feature (with an identical URL format compared to the one generated in this example) can ACTUALLY speak in spanish or any other language you want... I tried to change the url giving the program a language code using this url:

http://translate.google.com/translate_tts?tl=es_MX&q=

(For spanish recognition)

But the result was the same, Spanglish... Any ideas of Why this is happening and How to make it "speak" in as many languages as the web tool? (or at least in other one plus english), hehe

like image 591
Jmlevick Avatar asked Jan 29 '12 07:01

Jmlevick


People also ask

Can TTS read other languages?

Spanish text-to-speech software, also known as TTS, can read out content written in English and other languages in your language.

How do I add languages to pyttsx3?

For Windows user, head over to the Language setting. You should be able to see the following user interface. Apart from the default language pack (English), I have installed additional languages (such as Chinese and Japanese). Click on the Add button to add a preferred language.


1 Answers

Don't use tl=es_MX, just use tl=es.

Por ejemplo: http://translate.google.com/translate_tts?tl=es&q=que+hora+es

like image 101
sblom Avatar answered Oct 11 '22 21:10

sblom