Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

503 Server Error: Service Unavailable #14

Closed
Zerokami opened this issue Dec 2, 2015 · 10 comments
Closed

503 Server Error: Service Unavailable #14

Zerokami opened this issue Dec 2, 2015 · 10 comments

Comments

@Zerokami
Copy link

Zerokami commented Dec 2, 2015

I tried gtts-cli.py "Hello" -l 'en' -o hello.mp3
and I get the following error
503 Server Error: Service Unavailable

@Zerokami
Copy link
Author

Zerokami commented Dec 6, 2015

It looks like Google is blocking my requests.

@pndurette
Copy link
Owner

Sorry for the delay, yes this is one of the main drawbacks of this library: it uses a free unrestricted API. Google will automatically block requests (on the Web, ask for a captcha) for a period of time when overused (in general).

Pierre Nick Durette
Sent from mobile

On Dec 6, 2015, at 10:25 AM, Logmytech notifications@github.com wrote:

It looks like Google is blocking my requests.


Reply to this email directly or view it on GitHub.

@pndurette
Copy link
Owner

Actually, will leave this open so it's easier to find, unless I had it to the README.md.

@pndurette pndurette reopened this Dec 10, 2015
@fruitpunch
Copy link

I believe google added a hash to the request. If the provided hash value in the request does not match the hash value of the content, then they will return an error. Google pretty much sealed the deal on this.

However, you can easily switch from using google TTS to Bing TTS by making a few simple tweeks in the url. Replacing the original save function in tts.py with whats below should work (at least for zh-cn) with the Bing TTS.

def save(self, savefile):

    with open(savefile, 'wb') as f:
        for idx, part in enumerate(self.text_parts):

            while True:
                try:
                    output_percent = math.floor((idx/len(self.text_parts))*100)
                    print (" percent complete: ", output_percent,"%", end="\r")
                    began = 'https://api.microsofttranslator.com/v2/http.svc/speak?appId=TU3ucuxh6T1TaF9wfxA9ugfXziOkGKP-9JGafVLm-ELc*&language=' + self.lang + '&format=audio/mp3&options=MinSize|female&text='

                    part_byte = str(part.encode('utf-8'))
                    part_str = part_byte[2:-1].replace('\\x', '%').replace(' ', '%20')
                    complete_url = began+part_str

                    r = requests.get(complete_url)
                    for chunk in r.iter_content(chunk_size=1024):
                        f.write(chunk)
                    break
                except Exception as e:
                    continue
    print (" percent complete:  100 %")

Also if you want to improve performance on this, you need to pack as much content into a single URL as possible by combining parts together while not exceeding the limit.

However if you insist on using google's TTS, you have to install the google TTS (https://play.google.com/store/apps/details?id=com.google.android.tts&hl=en) onto an android device or AVD, then write an app that uses the API to takes in text and synthesize an audio file to be sent back over wifi.

@pndurette
Copy link
Owner

Thanks @fruitpunch! It was only a matter of time till Google locks this down more... Thanks for the Bing suggestion/TTS call url, that would sure be a good replacement (until Microsoft locks it down as well..). I will take a look! That could be a good substitute.

@pndurette
Copy link
Owner

Fixed in #17, updated gTTS to 1.1.2.

@Boudewijn26
Copy link
Contributor

Even after the fix it may be worth mentioning google will be quicker with its 503s after a couple of 403s then during normal service. However I suppose spamming enough will still get you 503-ed.

@pndurette
Copy link
Owner

Yes, true. I wanted to clarify this in the changelog (wrote it late and in a hurry). The 503s will most likely still happen from time to time, that check/blacklisting happens at different level (upstream) for all Google services AFAIK.

On Jan 13, 2016, at 12:30 PM, Boudewijn van groos notifications@github.com wrote:

Even after the fix it may be worth mentioning google will be quicker with its 503s after a couple of 403s then during normal service. However I suppose spamming enough will still get you 503-ed.


Reply to this email directly or view it on GitHub.

@fruitpunch
Copy link

Did you find the algorithm to calculate the token by looking through the javascript on the google translate page?

@pndurette
Copy link
Owner

@Boudewijn26 did yes. It's all inline (and obfuscated) on translate.google.com

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants