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

get key failed from google #33

Closed
solyarisoftware opened this issue Nov 4, 2020 · 9 comments
Closed

get key failed from google #33

solyarisoftware opened this issue Nov 4, 2020 · 9 comments

Comments

@solyarisoftware
Copy link

solyarisoftware commented Nov 4, 2020

Hi
this is not an issue, just a note.

I'm using google-tts (THANKS) in https://github.com/solyarisoftware/jointts, my work in progress package.
I also used google-tts in past an run smoothly.

recently I experiencing some errors like Error: get key failed from google (google-tts-api/lib/key.js:30:32). I presume it's a Google API reject/error. Apparently errors arise random (e.g. not related to API calls rate).

  $ jointts download gt mi chiamo Giorgio --language=it

  sentence       : mi chiamo Giorgio
  language       : it
  speed          : normal

  Error: get key failed from google
      at /home/giorgio/jointts/node_modules/google-tts-api/lib/key.js:30:32
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

Workaround (not rocket-science): because the google API raise error occasionally, I retry until I got success.
In few shots the API return success (I admit, that's dirty):

for (;;) {

  callGoogleAPI(...)

  if success 
    break

  sleep(few hundreds msecs)
}  

Any idea?

Thanks
giorgio

@zlargon
Copy link
Owner

zlargon commented Nov 5, 2020

Google might change the way to store the key. I will take a look. Thanks.

@gavwin
Copy link

gavwin commented Nov 6, 2020

I've also been using this package for a while now and am experiencing the same error.

@zlargon
Copy link
Owner

zlargon commented Nov 8, 2020

The original way the library get the secret token key from the google website cannot 100% guarantee success now.
After doing some testing, I decided to add a retry mechanism into the code. The latest version 0.0.5 should work fine.

I plan to re-write the project to handle this issue in another efficient way: caching the token key so that we don't have to fetch the token key every time. I also plan to add some new features, such as supporting long text input. It will be expected to have some breaking changes.

Thanks.

@horihiro
Copy link

horihiro commented Nov 8, 2020

There are two patterns for Google Translate page URL ( https//translate.google.com ) contents and the contents sometime doesn't contain TKK parameter. This is why Error: get key failed from google happens.

Google might is introducing new process about TTS into Google Translate
# In my short investigation, the pattern which doesn't contain the parameter offers base64 encoded mp3 data, not URL.

But @timothydillan found that we can play TTS mp3 URL without the TKK parameter like a following mp3 URL currently.
https://translate.google.com/translate_tts?ie=UTF-8&client=something&tl=en&q=Hello

horihiro/esp8266-google-tts#10 (comment)

@zlargon
Copy link
Owner

zlargon commented Nov 8, 2020

@horihiro Wow, it's really cool that we can access the URL without a token key! Thank you for your investigation. It's really informative.
I also notice that google translate is changing the website recently, and they are adding some new mechanism to prevent someone from abusing the APIs. Not very sure what will happen next, but we will see, haha.

Our systems have detected unusual traffic from your computer network. Please try your request again later.
Why did this happen?

IP address: xxx.xxx.xxx.xxx
Time: 2020-11-08T09:12:16Z
URL: https://translate.google.com/translate_tts?ie=UTF-8&client=something&tl=en&q=Hello

@horihiro
Copy link

horihiro commented Nov 8, 2020

Please try client=tw-ob in query parameters.
# This API also might be blocked :(

@solyarisoftware
Copy link
Author

@horihiro thanks, even if I fair this is dangerous:
https://stackoverflow.com/questions/32053442/google-translate-tts-api-blocked

This answer no longer works consistently. Your ip address will be blocked by google temporarily if you abuse this too much.

@horihiro
Copy link

horihiro commented Nov 8, 2020

Hmm, In my environment, the following url can be downloaded.
https://translate.google.com/translate_tts?ie=UTF-8&q=mi%20chiamo%20Giorgio&tl=it&client=tw-ob

@zlargon
Copy link
Owner

zlargon commented Dec 9, 2020

The approach #33 (comment) by @horihiro has been implemented in PR #37 by @freddiefujiwara.
It has been released in version 0.0.6.

Thank you all. 🎉

@zlargon zlargon closed this as completed Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants