Skip to content

GlobalTechInfo/gspeak

gspeak

gspeak

Google Text to Speech for Node.js

A TypeScript rewrite of gtts — drop-in compatible.

License Coverage NPM Version Code Quality Downloads


✨ Features

  • 🔊 Convert any text to speech using Google TTS
  • 🔷 Full TypeScript support
  • 🔗 Drop-in replacement for gtts
  • 🌍 81 languages supported
  • 💾 Save to file or stream directly
  • 🖥️ CLI included

📦 Installation

npm i gspeak

🚀 Quick Start

import { gSpeak } from 'gspeak'

const tts = new gSpeak('Hello world', 'en')
tts.save('/tmp/hello.mp3', (err) => {
  if (err) throw err
  console.log('Saved to /tmp/hello.mp3')
})

📥 Import

import { gSpeak } from 'gspeak'         // ESM ✅

const { gSpeak } = require('gspeak')     // CJS ✅

const gSpeak = require('gspeak').default   // CJS ✅

📖 Usage

Save to file

import { gSpeak } from 'gspeak'

const tts = new gSpeak('Text to speak', 'en')
tts.save('/tmp/output.mp3', (err) => {
  if (err) throw err
  console.log('Done!')
})

Stream (e.g. with Express)

import express from 'express'
import { gSpeak } from 'gspeak'

const app = express()

app.get('/speak', (req, res) => {
  const tts = new gSpeak(req.query.text as string, req.query.lang as string)
  tts.stream().pipe(res)
})

app.listen(3000, () => {
  console.log('http://localhost:3000/speak?lang=en&text=Hello')
})

List all supported languages

import { LANGUAGES } from 'gspeak'

console.log(LANGUAGES)
// { af: 'Afrikaans', sq: 'Albanian', ... }

// or via the static getter
import { gSpeak } from 'gspeak'
console.log(gSpeak.languages)

Debug mode

const tts = new gSpeak('Hello', 'en', true) // 3rd param enables debug logging

🖥️ CLI

npm install -g gspeak
gspeak "Hello Google Text to Speech" -l en -o /tmp/hello.mp3
Flag Alias Description
--language -l Language code (default: en)
--output -o Output file path (required)
--verbose -v Print debug messages

🌍 Supported Languages (81 total)

Code Language
af Afrikaans
sq Albanian
am Amharic
ar Arabic
eu Basque
bn Bengali
bs Bosnian
bg Bulgarian
my Burmese
ca Catalan
zh Chinese
zh-cn Chinese (Simplified)
zh-tw Chinese (Traditional)
zh-yue Chinese (Cantonese)
hr Croatian
cs Czech
da Danish
nl Dutch
en English
en-au English (Australia)
en-ca English (Canada)
en-in English (India)
en-ie English (Ireland)
en-uk English (United Kingdom)
en-us English (United States)
en-za English (South Africa)
et Estonian
fil Filipino
fi Finnish
fr French
fr-ca French (Canada)
fr-fr French (France)
gl Galician
de German
el Greek
gu Gujarati
ha Hausa
iw Hebrew
hi Hindi
hu Hungarian
is Icelandic
id Indonesian
it Italian
ja Japanese
jw Javanese
kn Kannada
km Khmer
ko Korean
la Latin
lv Latvian
lt Lithuanian
ms Malay
ml Malayalam
mr Marathi
ne Nepali
no Norwegian
pl Polish
pt Portuguese
pt-br Portuguese (Brazil)
pt-pt Portuguese (Portugal)
pa Punjabi
ro Romanian
ru Russian
sr Serbian
si Sinhala
sk Slovak
es Spanish
es-es Spanish (Spain)
es-us Spanish (United States)
su Sundanese
sw Swahili
sv Swedish
tl Tagalog
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
vi Vietnamese
cy Welsh

🔄 Migrating from gtts

gspeak is a drop-in replacement. Just change the import:

// before
const gTTS = require('gtts')
const tts = new gTTS('Hello', 'en')

// after
const { gSpeak } = require('gspeak')
const tts = new gSpeak('Hello', 'en')

Same constructor, same .save(), same .stream() — nothing else changes.


📄 License

MIT © Qasim Ali


Made with ❤️ — Thanks for using gspeak!

About

Google Text to Speech for Node.js — modern, typed, zero deprecated dependencies.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors