
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
A simple and efficient Google Text-to-Speech (TTS) library for Node.js that converts text to speech using Google's TTS service.
npm install tts-google
This package requires the following dependencies:
npm install multistream async fake-useragent request
const TTS = require('tts-google');
// Create TTS instance
const tts = new TTS('en'); // English
// Convert text to speech and save as file
async function example() {
try {
const filename = await tts.saveToFile('Hello World!', 'output.mp3');
console.log(`Audio saved as: ${filename}`);
} catch (error) {
console.error('Error:', error);
}
}
example();
const tts = new TTS(language)
language (string, optional): Language code (default: 'en')saveToFile(text, filename)Converts text to speech and saves as an audio file.
const filename = await tts.saveToFile('Hello World!', 'hello.mp3');
Parameters:
text (string): Text to convert to speechfilename (string): Output filename (MP3 format)Returns: Promise that resolves to the filename
getAudioBuffer(text)Converts text to speech and returns audio data as a Buffer.
const audioBuffer = await tts.getAudioBuffer('Hello World!');
console.log(`Buffer size: ${audioBuffer.length} bytes`);
Parameters:
text (string): Text to convert to speechReturns: Promise that resolves to a Buffer containing audio data
playAudio(text)Streams audio data (requires additional audio player implementation).
await tts.playAudio('Hello World!');
Note: This method provides a stream but requires an audio player like node-speaker to actually play the audio.
TTS.getAvailableLanguages()Returns an object containing all supported languages.
const languages = TTS.getAvailableLanguages();
console.log(languages);
// Output: { 'en': 'English', 'es': 'Spanish', ... }
The library supports 50+ languages including:
{
'af': 'Afrikaans',
'sq': 'Albanian',
'ar': 'Arabic',
'hy': 'Armenian',
'ca': 'Catalan',
'zh': 'Chinese',
'zh-cn': 'Chinese (Mandarin/China)',
'zh-tw': 'Chinese (Mandarin/Taiwan)',
'zh-yue': 'Chinese (Cantonese)',
'hr': 'Croatian',
'cs': 'Czech',
'da': 'Danish',
'nl': 'Dutch',
'en': 'English',
'en-au': 'English (Australia)',
'en-uk': 'English (United Kingdom)',
'en-us': 'English (United States)',
'eo': 'Esperanto',
'fi': 'Finnish',
'fr': 'French',
'de': 'German',
'el': 'Greek',
'ht': 'Haitian Creole',
'hi': 'Hindi',
'hu': 'Hungarian',
'is': 'Icelandic',
'id': 'Indonesian',
'it': 'Italian',
'ja': 'Japanese',
'ko': 'Korean',
'la': 'Latin',
'lv': 'Latvian',
'mk': 'Macedonian',
'no': 'Norwegian',
'pl': 'Polish',
'pt': 'Portuguese',
'pt-br': 'Portuguese (Brazil)',
'ro': 'Romanian',
'ru': 'Russian',
'sr': 'Serbian',
'si': 'Sinhala (Sinhalese)',
'sk': 'Slovak',
'es': 'Spanish',
'es-es': 'Spanish (Spain)',
'es-us': 'Spanish (United States)',
'sw': 'Swahili',
'sv': 'Swedish',
'ta': 'Tamil',
'th': 'Thai',
'tr': 'Turkish',
'vi': 'Vietnamese',
'cy': 'Welsh'
}
// English TTS
const ttsEn = new TTS('en');
const englishAudio = await ttsEn.getAudioBuffer('Hello World!');
// Spanish TTS
const ttsEs = new TTS('es');
const spanishAudio = await ttsEs.getAudioBuffer('¡Hola Mundo!');
// French TTS
const ttsFr = new TTS('fr');
const frenchAudio = await ttsFr.getAudioBuffer('Bonjour le monde!');
const tts = new TTS('en');
try {
await tts.saveToFile('Your text here', 'output.mp3');
console.log('Success!');
} catch (error) {
if (error.message.includes('Language not supported')) {
console.error('Invalid language code');
} else {
console.error('TTS Error:', error.message);
}
}
const express = require('express');
const TTS = require('tts-google');
const app = express();
const tts = new TTS('en');
app.get('/speak', async (req, res) => {
try {
const text = req.query.text || 'Hello World!';
const audioBuffer = await tts.getAudioBuffer(text);
res.set({
'Content-Type': 'audio/mpeg',
'Content-Length': audioBuffer.length
});
res.send(audioBuffer);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000, () => {
console.log('TTS Server running on port 3000');
});
Run the included tests:
npm test
The test suite includes:
"Language not supported" error
Network errors
File permission errors
If you encounter issues:
Contributions are welcome! Please feel free to submit a Pull Request.
ISC License
K.Prabhasha - Evelocore
Keywords: tts, google, gtts, node, speech, voice, text-to-speech, audio, mp3
FAQs
Google tts for Node.js
The npm package tts-google receives a total of 2 weekly downloads. As such, tts-google popularity was classified as not popular.
We found that tts-google demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.