• Stars
    star
    273
  • Rank 149,916 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

lssdp

light weight SSDP library
C
99
star
2

git-tutorial

Git Tutorial Online Book
95
star
3

voc

Download and play English vocabulary's audio via command line.
JavaScript
12
star
4

react-highlight

React component for syntax highlighting.
HTML
10
star
5

lame

mirror of LAME (MP3 Encoder)
C
10
star
6

cmocha

C testing tool in mocha style
C
8
star
7

ios-apns-demo

Objective-C
6
star
8

book118

Book118 Downloader
JavaScript
4
star
9

story-downloader

Instagram Story Downloader
JavaScript
4
star
10

8051-ASM

Jimmy Lee 8051 course in July
Assembly
2
star
11

invoice

A helper for Taiwan Receipt Lottery
JavaScript
2
star
12

one-piece

One Piece Treasure Cruise Damage Calculator
JavaScript
2
star
13

spring-boot-flyway-jooq-postgres-swagger-prettier-java-template

Java
2
star
14

golang-graphql-example

Go
1
star
15

profile

my profile
Shell
1
star
16

spring-boot-flyway-jooq-postgres-swagger-kotlin-template

Kotlin
1
star
17

bash-check-git-version

check git version in bash
Shell
1
star
18

reminder-app

HTML
1
star
19

moment

JavaScript
1
star
20

zlargon

1
star
21

keep-awake

a command line to keep your laptop awake
JavaScript
1
star
22

sm_api

Service Manager HTTP API
C
1
star
23

hunter

An Interactive Film
JavaScript
1
star
24

react-native-awesome-app

JavaScript
1
star
25

network-interface

Get IPv4 addr and netmask
C
1
star
26

db-migration-flyway-groovy

Minimum configuration to run db migration with flyway and groovy (No Maven. No Gradle. No Plugins.)
Groovy
1
star
27

demo-mfe-container

JavaScript
1
star
28

pronunciation

Query English Pronunciation
JavaScript
1
star
29

c-json-parser

using javascript syntax to parse JSON by C programming language
C
1
star
30

photo-app-serverless-frontend

JavaScript
1
star
31

cloudformation.ts

TypeScript
1
star
32

demo-mfe-module

JavaScript
1
star
33

dbdiagram-postgres-schema-cleaner

Clean up non-supported SQL syntax before importing PostgreSQL schema to dbdiagram.io
PLpgSQL
1
star
34

docker-compose-examples

Shell
1
star
35

react-pnpm-cra-vite-eslint-prettier-typescript-template

a template for building a react app
TypeScript
1
star
36

bookstore-flask

Python
1
star
37

hello

HTML
1
star
38

linux-ble

C
1
star
39

ottometric-app

JavaScript
1
star
40

receipt-lottery-taiwan

Getting winning numbers of Taiwan Receipt Lottery (Node.js)
JavaScript
1
star
41

photo-app-serverless-backend

JavaScript
1
star
42

google-lady

Google text-to-speech URL generator (CLI)
JavaScript
1
star
43

ffcall

cvs -z3 -d:pserver:[email protected]:/sources/libffcall co ffcall
C
1
star
44

mysql-csv-docker-example

The example of initializing MySQL docker container with CSV files
1
star
45

react-highlight-example

An example of npm "react-syntax-highlight"
JavaScript
1
star
46

blog

1
star
47

dgm6308-assignment

DGM6308 Assignments
JavaScript
1
star
48

spring-boot-flyway-jooq-postgres-swagger-java-kotlin-template

Kotlin
1
star
49

EventCounter

This is a JavaScript library that helps record (any kind of) incremental events, and query the number of events during the specific spantime.
JavaScript
1
star