zlargon / google-tts

Google TTS (Text-To-Speech) for node.js
https://www.npmjs.com/package/google-tts-api
MIT License
276 stars 56 forks source link

get key failed from google #28

Closed idoor88 closed 3 years ago

idoor88 commented 4 years ago

I just installed the most recent version 0.0.4 of the library and tested with my react-native sample project, it gave me this exception: get key failed from google, BTW, I can access this site: https://translate.google.com from my region.

So is the key expired? or I need to get my own key? or google changed their API again?

Thanks

solyarisoftware commented 3 years ago

Hi @idoor

I currently (November 2020) see that the error happens randomly. I guess is Google-inside. See: https://github.com/zlargon/google-tts/issues/33

BTW, sorry @zlargon I hadn't noticed this open issue and I opened #33.

moonstar-x commented 3 years ago

If it's of any help:

You get different HTML bodies when you visit "https://translate.google.com". It seems to be random whether you get one that contains a match for tkk:'\d+.\d+'.

When it comes to accessing the translate site through another TLD: I've been getting consistent HTML bodies that do not contain the match if visiting from the browser but the random behaviour happens when using a client like curl.

I tried doing multiple requests with various user agents and the results remain random which suggests that user agent has got nothing to do with this.

A solution may be to expose the key and api functions so that we can reuse valid keys in multiple requests, though I don't know for how long and for how many calls each key remains valid.

zlargon commented 3 years ago

@moonstar-x The "get key failed" issue was temporarily fixed in the latest version 0.0.5 by add try mechanism.

If you are looking for reusing the token key, you might want to try this example. https://github.com/zlargon/google-tts/blob/master/example/reuse-api-key.js