Git Product home page Git Product logo

google-tts-x'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-x's People

Contributors

zlargon avatar freddiefujiwara avatar dependabot[bot] avatar kmyk avatar

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.