zlargon / google-tts

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

get token key failed from google #36

Closed Triggered0 closed 3 years ago

Triggered0 commented 3 years ago

Error: get token key failed from google

Failure404 commented 3 years ago

Same issue here. Not able to get media file via google-tts:get token key failed from google

chayleaf commented 3 years ago

Google switched to a new API #35

florabtw commented 3 years ago

This is a duplicate of #33

freddiefujiwara commented 3 years ago

let me try to fix on https://github.com/zlargon/google-tts/pull/37

florabtw commented 3 years ago

For anyone looking for an immediate solution, you can check out my comment I left in the other issue: https://github.com/zlargon/google-tts/issues/35#issuecomment-737032391

I created a new package google-translate-tts which uses the new Translate API. Who knows if the new API will stick, but it fixed the immediate problems I was having.

Sophan-Developer commented 3 years ago

IMG_20201204_130826 So tried when I saw this

freddiefujiwara commented 3 years ago

This is my idea of api.js, but let me figure out how to merge it properly into api.js.

const fetch = require('node-fetch');
module.exports = (async (text, lang, speed) => {
  const data =
    JSON.parse(JSON.parse((await (await fetch("https://translate.google.com/_/TranslateWebserverUi/data/batchexecute", {
      method: "POST",
      headers: {
        "content-type": "application/x-www-form-urlencoded"
      },
      body: "f.req=" + encodeURIComponent(JSON.stringify([
        [
          ["jQ1olc", JSON.stringify([text, lang, parseInt(speed) === 1 ? null : true, "null"]), null, "generic"]
        ]
      ]))
    })).text()).replace(/^\)]}'/, ''))[0][2])[0];
  return `data:audio/mpeg;base64,${data}`;
});
freddiefujiwara commented 3 years ago

Let me try to adopt ↑ at https://github.com/zlargon/google-tts/pull/38

zlargon commented 3 years ago

This issue has been fixed in PR https://github.com/zlargon/google-tts/pull/37 by @freddiefujiwara and has been released in version 0.0.6. Thank you all. 🎉