User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Google Text To Speech

Fri May 10, 2013 5:05 pm

Anyone had Google Text-to-speech working?
I've been using the following code but just end up getting an HTML file instead of an MP3.

Code: Select all

#!/usr/bin/python

import os

text = "speak to me"
tts_text = text.replace(" ","+")
tts_url = "http://translate.google.com/translate_tts?tl=en&q="+tts_text
os.system("wget tts_url -O test.mp3")
os.system("aplay test.mp3")
Any help appreciated.
Dave.
Apple say... Monkey do !!

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Google Text To Speech

Fri May 10, 2013 10:20 pm

I used Google text to speech in my talking Twitter client project.

It's written in python, the code is pretty simple, see this blog post for a how to and the code.

http://www.stuffaboutcode.com/2012/10/r ... itter.html

Mart
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Google Text To Speech

Sat May 11, 2013 10:34 am

Thanks very much, worked a treat. Took out all the Twitter related bits and had to change the subprocess call for an os.system instead. How do you pass parameters to a process using subprocess? I had to use the "-af extrastereo=0" in mplayer to force stereo output as mono won't play through HDMI (glitch at the TV end of things).
Anyway, this is the code I ended up with...

Code: Select all

#!/usr/bin/python

import urllib, pycurl, os

def downloadFile(url, fileName):
    fp = open(fileName, "wb")
    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.WRITEDATA, fp)
    curl.perform()
    curl.close()
    fp.close()

def getGoogleSpeechURL(phrase):
    googleTranslateURL = "http://translate.google.com/translate_tts?tl=en&"
    parameters = {'q': phrase}
    data = urllib.urlencode(parameters)
    googleTranslateURL = "%s%s" % (googleTranslateURL,data)
    return googleTranslateURL

def speakSpeechFromText(phrase):
    googleSpeechURL = getGoogleSpeechURL(phrase)
    downloadFile(googleSpeechURL,"tts.mp3")
    os.system("mplayer tts.mp3 -af extrastereo=0 &")
    
speakSpeechFromText("testing, testing, 1 2 3.")
...if I end up using it in a project you'll get full credit.

Thanks again.
Dave.
Apple say... Monkey do !!

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Google Text To Speech

Tue May 14, 2013 2:34 pm

No worries Dave
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

nemo096
Posts: 26
Joined: Wed Dec 26, 2012 10:54 am

Re: Google Text To Speech

Wed Jul 17, 2013 8:06 pm

This is extremely useful (talking twitter client) as I am planning on using my pi to be the main brains of an AI which I can use on the go by communicating with it via twitter so now people can text me basically using this as i have a perl program that will update your status so thanks very much LHIS

All i need now is to be able to capture audio so i dont need to type using my platronics 400 something

Anyone offer any light on this?

redanb
Posts: 12
Joined: Mon Jan 04, 2016 11:42 am

Re: Google Text To Speech

Mon Jan 04, 2016 2:23 pm

I have created a python file containing:

Code: Select all

#!/usr/bin/python

import urllib, pycurl, os

def downloadFile(url, fileName):
    fp = open(fileName, "wb")
    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.WRITEDATA, fp)
    curl.perform()
    curl.close()
    fp.close()

def getGoogleSpeechURL(phrase):
    googleTranslateURL = "http://translate.google.com/translate_tts?tl=en&"
    parameters = {'q': phrase}
    data = urllib.urlencode(parameters)
    googleTranslateURL = "%s%s" % (googleTranslateURL,data)
    return googleTranslateURL

def speakSpeechFromText(phrase):
    googleSpeechURL = getGoogleSpeechURL(phrase)
    downloadFile(googleSpeechURL,"tts.mp3")
    os.system("mplayer tts.mp3 -af extrastereo=0 &")

speakSpeechFromText("testing, testing, 1 2 3.")

But when i run .py file i get following error:
Playing tts.mp3.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[mp3 @ 0x75cff850]Header missing
[mp3 @ 0x763de0e8]Could not find codec parameters (Audio: mp3, 0 channels, s16)
[mp3 @ 0x763de0e8]Estimating duration from bitrate, this may be inaccurate
LAVF_header: av_find_stream_info() failed


Exiting... (End of file)

sorry for posting the code badly

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Google Text To Speech

Mon Jan 04, 2016 2:44 pm

redanb wrote:sorry for posting the code badly
...I modified your post and used the CODE tags. This will show indentation, etc
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Google Text To Speech

Tue Jan 05, 2016 6:23 pm

This takes me back ;)
Looks like someone else had a similar problem here viewtopic.php?t=44903&p=463672 or at least had the same error message. May be worth a look.

Dave.
Apple say... Monkey do !!

redanb
Posts: 12
Joined: Mon Jan 04, 2016 11:42 am

Re: Google Text To Speech

Tue Jan 05, 2016 6:45 pm

Thanks, i will try.

User avatar
DougieLawson
Posts: 36306
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Google Text To Speech

Tue Jan 05, 2016 7:33 pm

You can't use that Google http://translate.google.com/translate_tts URL because it's been deprecated and protected behind a CAPTCHA. Your code will fail with a HTTP 503 error.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Fri Oct 21, 2016 12:10 pm

Please help me fix this code

Code: Select all

import urllib, pycurl, os

def downloadFile(url, fileName):
    fp = open(fileName, "wb")
    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.WRITEDATA, fp)
    curl.perform()
    curl.close()
    fp.close()

def getGoogleSpeechURL(phrase):
    googleTranslateURL = "http://translate.google.com/translate_tts?tl=en&"
    parameters = {'q': phrase}
    data = urllib.urlencode(parameters)
    googleTranslateURL = "%s%s" % (googleTranslateURL,data)
    return googleTranslateURL

def speakSpeechFromText(phrase):
    googleSpeechURL = getGoogleSpeechURL(phrase)
    downloadFile(googleSpeechURL,"tts.mp3")
    os.system("mplayer tts.mp3 -af extrastereo=0 &")

speakSpeechFromText("testing, testing, 1 2 3.")
when I run on terminal in resin
It show : mplayer: error while loading shared libraries: libbcm_host.so: cannot open shared object file: No such file or director

help me please.
This for 15 Point

User avatar
DougieLawson
Posts: 36306
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Google Text To Speech

Fri Oct 21, 2016 4:21 pm

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Google Text To Speech

Fri Oct 21, 2016 8:25 pm

Sorry if this is an utterly naive question, but what benefits come from using google speech synthesis as opposed to local ones? Is the rendering that much better or something?

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sat Oct 22, 2016 3:20 pm

DougieLawson wrote:viewtopic.php?p=877034#p877034

You can't fix it.
You mean no more google text to speech python function right?

So,Do you have the same or semilar application like this.

Please Help Me. 15 Point significant to escape the (F)

:( :( :(

User avatar
DougieLawson
Posts: 36306
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Google Text To Speech

Sat Oct 22, 2016 3:21 pm

Google have discontinued their TTS web service. So your project is dead in the water.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sat Oct 22, 2016 3:29 pm

tpylkko wrote:Sorry if this is an utterly naive question, but what benefits come from using google speech synthesis as opposed to local ones? Is the rendering that much better or something?
I was assigned to do SMS to Speech by Raspberri pi.
so that I have to use g.oogle speech for convert text(SMS) to audio :?

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sat Oct 22, 2016 3:31 pm

DougieLawson wrote:Google have discontinued their TTS web service. So your project is dead in the water.
ahhh.. sadly T..T

Nevertheless
Thank you so much

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sat Oct 22, 2016 3:35 pm

DougieLawson wrote:Google have discontinued their TTS web service. So your project is dead in the water.
sorry DougieLawson

one more question
Can I adapt this URL :http://translate.google.com/translate_t ... -gb&q=test.
for this project?

User avatar
DougieLawson
Posts: 36306
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Google Text To Speech

Sat Oct 22, 2016 5:20 pm

NO, what part of "discontinued" are you failing to grasp?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Google Text To Speech

Sun Oct 23, 2016 12:24 am

ferzeuz wrote:
tpylkko wrote:Sorry if this is an utterly naive question, but what benefits come from using google speech synthesis as opposed to local ones? Is the rendering that much better or something?
I was assigned to do SMS to Speech by Raspberri pi.
so that I have to use g.oogle speech for convert text(SMS) to audio :?
why can't that be done with a local synthesizer?

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sun Oct 23, 2016 4:27 am

tpylkko wrote:
ferzeuz wrote:
tpylkko wrote:Sorry if this is an utterly naive question, but what benefits come from using google speech synthesis as opposed to local ones? Is the rendering that much better or something?
I was assigned to do SMS to Speech by Raspberri pi.
so that I have to use g.oogle speech for convert text(SMS) to audio :?
why can't that be done with a local synthesizer?
Can u recommend me a local synthesizer that can use with twilio service.

:o :o :o

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Google Text To Speech

Sun Oct 23, 2016 3:18 pm

I would think that any one of them would work. If it is the case that you can handle the sms as plain text, then surely you can pipe it to any of he speech synths in the repo?

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sun Oct 23, 2016 3:50 pm

thank you so much :D :D :D

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Google Text To Speech

Sun Oct 23, 2016 4:21 pm

are you being sarcastic or do mean that you don't know how to use a package manager?

ferzeuz
Posts: 11
Joined: Fri Oct 21, 2016 10:58 am

Re: Google Text To Speech

Sun Oct 23, 2016 5:38 pm

Sorry if u feel that.
I actually dont know how to use package manager.

Return to “Python”