Git Product home page Git Product logo

google-tts's Introduction

google-tts

Google TTS (Text-To-Speech) for node.js

Installation

$ npm install --save google-tts-api
$ npm install -D typescript @types/node # Only for TypeScript

Change Log

Please see CHANGELOG.

Usage

Method Options (all optional) Return Type Handle Long Text
getAudioUrl lang, slow, host string
getAudioBase64 lang, slow, host, timeout Promise<string>
getAllAudioUrls lang, slow, host, splitPunct { shortText: string; url: string; }[]
getAllAudioBase64 lang, slow, host, timeout, splitPunct Promise<{ shortText: string; base64: string; }[]>

Options (all optional)

Option Type Default Description
lang string en See all avaiable language code at https://cloud.google.com/speech/docs/languages
slow boolean false Use the slow audio speed if set slow to true
host string https://translate.google.com You can change the host if the default host could not work in your region (e.g. https://translate.google.com.cn).
timeout number 10000 (ms) (Only for getAudioBase64 and getAllAudioBase64) Set timeout for the HTTP request.
splitPunct string (Only for getAllAudioUrls and getAllAudioBase64) Set the punctuation to split the long text to short text. (e.g. ",、。")

Examples

1. getAudioUrl(text, [option])

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

// get audio URL
const url = googleTTS.getAudioUrl('Hello World', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
});
console.log(url); // https://translate.google.com/translate_tts?...

2. getAudioBase64(text, [option])

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

// get base64 text
googleTTS
  .getAudioBase64('Hello World', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
  })
  .then(console.log) // base64 text
  .catch(console.error);

3. getAllAudioUrls(text, [option]) (For text longer than 200 characters)

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
  splitPunct: ',.?',
});
console.log(results);
// [
//   { shortText: '...', url: '...' },
//   { shortText: '...', url: '...' },
//   ...
// ];

4. getAllAudioBase64(text, [option]) (For text longer than 200 characters)

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

googleTTS
  .getAllAudioBase64('LONG_TEXT_...', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
    splitPunct: ',.?',
  })
  .then(console.log)
  // [
  //   { shortText: '...', base64: '...' },
  //   { shortText: '...', base64: '...' },
  //   ...
  // ];
  .catch(console.error);

More Examples

License

MIT

google-tts's People

Contributors

dependabot[bot] avatar freddiefujiwara avatar kmyk avatar zlargon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-tts's Issues

Error: get key failed in version 0.04

I am receiving an error with respect to a get key.
I looked at issue #17 but did not understand the context to the notification package which I did not have previously installed.
I tried to install this notification package but I did not see a change of behavior

Link error 403

I can not access link from module with error .
Access to translate.google.com was denied You don't have authorization to view this page.
HTTP ERROR 403

Error: get key failed from google in version 0.0.3

Hello zlargon,

Currently, I'm using google-tts-api in version 0.0.3, and it's no longer working, an "get key failed from google" error appears.
Does it not work in older versions?
Do we need to update to the latest version?

Thank.

Pricing

Hey Leon, I have gone through your npm package “google-tts”. It was very good and useful. I have a doubt. If I use Text to Speech from Google. I had to pay them and get credentials. How it is free in your “google-tts”. Will I get any issues in the future If I use it for a long time?

Occasionally getting a different voice

I'm using a simple script that reads out some text, using en-US as the lang. For an unknown reason the API is playing a different voice every so often.

Error: get key failed from google

Hi, this gave me the error

Error: get key failed from google
at [redacted]\node_modules\google-tts-api\lib\key.js:23:23
at
at process._tickCallback (internal/process/next_tick.js:189:7)

Cors problem

Hi!

I tried to use google-tts in my web app but when I did a request I obtained this error in the console:

Failed to load https://translate.google.com/: Redirect from 'https://translate.google.com/' to 'https://translate.google.com/m/translate' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

get key failed from google

I'm using the exact same code as I have been for the past few months, and recently have been getting a Error: get key failed from google
Any way to fix this?

Firebase

is it possible to migrate this project to firebase?

different speed options?

Hi, @zlargon

I noticed that there is an option regarding tts speed in the getAudioUrl file.
ttsspeed: slow ? 0.24 : 1,

I wonder if there is any way for us to assign different speeds. i.e. slow(0.25), medium(0.5), upper medium(0.75) and normal(1)

Thanks.

Intonation

Is it possible to add intonation like in android?
Expressive, flat

Thanks

1 node-fetch vulnerability found in package-lock.json

Hi Leon

First of all thanks for your package!

recently, when installing I got a node-fetch vulnerability. See:

$ npm install google-tts-api
npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 8 packages from 7 contributors and audited 8 packages in 1.69s
found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
$ npm audit

                       === npm audit security report ===

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Denial of Service                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ node-fetch                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.6.1 <3.0.0-beta.1|| >= 3.0.0-beta.9                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ google-tts-api                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ google-tts-api > isomorphic-fetch > node-fetch               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1556                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 low severity vulnerability in 8 scanned packages
  1 vulnerability requires manual review. See the full report for details.
$ npm audit fix
up to date in 0.188s
fixed 0 of 1 vulnerability in 8 scanned packages
  1 vulnerability required manual review and could not be updated

How can I remove the vulnarability?
Have you to update the package?

see github suggestion:

Remediation
Upgrade node-fetch to version 2.6.1 or later. For example:

"dependencies": {
  "node-fetch": ">=2.6.1"
}
or…
"devDependencies": {
  "node-fetch": ">=2.6.1"
}

Thanks/Cheers
giorgio

Male voice

I was wondering if it would be possible for people to choose between a female and male voice (if there is one)

Does this require any kind of key or billing?

As title is asking, I'm curious to see if this is free forever? I implemented it but have not seen to hit any kind of limit or anything. I'm nervous to use this in my application due to needing a billing key or something from Google.

Randomly stopped working recently.

Nothing much else to say, I don't have any errors or anything; there aren't any.

Google must have changed something as where this was working before, now it isn't.

lang code en-US,en-AU not working with getAudioBase64, getAllAudioBase64

The sample code present in the examples is not working:

// get base64 text
googleTTS.getAudioBase64('Hello World', {
     lang: 'en-US',
     slow: false,
     host: 'https://translate.google.com',
     timeout: 10000,
})
.then(console.log) // base64 text
.catch(console.error);

Error: lang "en-US" might not exist

It successfully returned base64 output for language codes: 'en', 'es'.
en-Us, en-AU are working fine for getAudioUrl,getAllAudioUrls functions though.

Add support for "auto" language

This can be done by sending a request with data:

[[["MkEWBc","[[\"WORD_TO_CHECK\",\"auto\",\"TARGET_LANGUAGE\",true],[null]]",null,"generic"]]]

example result

)]}'

393
[["wrb.fr","MkEWBc","[[null,null,\"en\",[[[0,[[[null,7]\n]\n,[true]\n]\n]\n]\n,7]\n]\n,[[[null,null,null,null,null,[[\"pengujian\",[\"pengujian\"]\n]\n]\n]\n]\n,\"id\",1,\"auto\",[\"testing\",\"auto\",\"id\",true]\n]\n,\"en\",[\"testing\",null,null,[[\"test\"]\n,null,1]\n,null,null,null,null,\"en\",1]\n]\n",null,null,null,"generic"]
,["di",29]
,["af.httprm",28,"-2444905251841777356",28]
]
26
[["e",4,null,null,430]
]

where the detected language seems to be in ...[[null,null,\"en\"...

But this also mean that we need to send 2 requests, first to get the detected language, second to get the base64 data

get key failed from google

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

Not able to use in react-native project

I tried to install it in my react-native project but it is throwing error

\node_modules\google-tts-api\dist\getAudioUrl.js: url could not be found within the project or in these directories: node_modules

var assertInputTypes_1 = __importDefault(require("./assertInputTypes")); var splitLongText_1 = __importDefault(require("./splitLongText")); var url_1 = __importDefault(require("url"));

can you help me why i am getting this error

Translate long texts

  1. Split text to parts of max 200 chars
  2. Add parameters: q=<part>&total=<total parts>&idx=<part index>&textlen=<part length>

tts with join channel

I use it with discord.js v11.6.1
How to fix this with New version 2.0.0?
Why you don't have discord server?

const tts = require("google-tts-api");

 // tts(tts1, `km`, 0.90) old version
  
tts.getAudioUrl("hello world", {
              lang: "en-US",
              slow: false,
              host: "https://translate.google.com"
            })
            .then(function(url) {
              voiceChannel.join().then(connection => {
                voice();

                function voice() {
                  const stream = connection.playStream(url);
                }
              });

.

.

get key failed from google

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

Causes for missing responses

Hi,

I'm on a fairly slow connection behind a VPN, and not always getting replies processed. Is this likely just due to my conditions or can there be other reasons?

Thanks!

Error: get key failed version 0.04

Hi,

I just test google-tts-api and I'm in trouble to use it.
I always get the following error: Error: get key failed from google

Is there a way to avoid that ?

I am in the last version: 0.04.

Thanks by advance

Security concern

Hello 👋

I run a security community that finds and fixes vulnerabilities in OSS. A researcher (@zer0h-bb) has found a potential issue, which I would be eager to share with you.

Could you add a SECURITY.md file with an e-mail address for me to send further details to? GitHub recommends a security policy to ensure issues are responsibly disclosed, and it would help direct researchers in the future.

Looking forward to hearing from you 👍

(cc @huntr-helper)

Change voice Gender

Hi, I was using google TTS API (the real one in google cloud). I saw they have gender params at here. Does this package supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.