@google-cloud/text-to-speech is an official client library for Google Cloud's Text-to-Speech API, designed for server-side Node.js environments to generate high-fidelity neural audio files. react-native-tts is a community-maintained module that bridges React Native apps to the native speech synthesis engines built into iOS and Android devices. While the former focuses on cloud-powered quality and consistency, the latter prioritizes offline capability and direct device integration.
Both @google-cloud/text-to-speech and react-native-tts enable JavaScript applications to convert text into spoken audio, but they operate in fundamentally different environments. One relies on powerful cloud servers to generate audio files, while the other uses the built-in speech engine of the user's mobile device. Let's compare how they handle initialization, speech execution, voice selection, and audio output.
@google-cloud/text-to-speech requires secure credentials to access Google Cloud services.
// @google-cloud/text-to-speech: Server-side init
const textToSpeech = require('@google-cloud/text-to-speech');
const client = new textToSpeech.TextToSpeechClient({
keyFilename: './service-account-key.json'
});
react-native-tts requires no authentication or external keys.
// react-native-tts: Client-side init
import Tts from 'react-native-tts';
// No credentials needed
// Ready to use immediately after import
@google-cloud/text-to-speech sends text to the cloud and receives audio data back.
// @google-cloud/text-to-speech: Synthesize request
const request = {
input: { text: 'Hello world' },
voice: { languageCode: 'en-US', ssmlGender: 'NEUTRAL' },
audioConfig: { audioEncoding: 'MP3' }
};
const [response] = await client.synthesizeSpeech(request);
const audioContent = response.audioContent;
react-native-tts commands the device to speak immediately.
// react-native-tts: Speak command
Tts.speak('Hello world');
// Optional: Handle finish event
Tts.addListener('tts-finish', () => {
console.log('Speech completed');
});
@google-cloud/text-to-speech offers hundreds of specific cloud voices.
// @google-cloud/text-to-speech: Specific voice
const request = {
input: { text: 'Premium voice' },
voice: {
languageCode: 'en-US',
name: 'en-US-Neural2-F'
},
audioConfig: { audioEncoding: 'MP3' }
};
react-native-tts uses whatever voices the device OS provides.
// react-native-tts: Set language and rate
Tts.setDefaultLanguage('en-US');
Tts.setDefaultRate(0.5); // Slow
Tts.setDefaultPitch(1.0); // Normal
// Get available voices (varies by OS)
Tts.getInit().then(() => {
Tts.voiceChange('com.apple.voice.compact.en-US.Samantha');
});
@google-cloud/text-to-speech returns raw audio data for you to manage.
// @google-cloud/text-to-speech: Save to file
const fs = require('fs');
fs.writeFileSync('output.mp3', audioContent, 'binary');
console.log('Audio saved to output.mp3');
react-native-tts streams audio directly to the device speaker.
// react-native-tts: Direct playback
// No file handling needed
Tts.speak('Instant playback');
// Stop if needed
Tts.stop();
@google-cloud/text-to-speech requires an active internet connection.
// @google-cloud/text-to-speech: Network dependent
try {
const [response] = await client.synthesizeSpeech(request);
} catch (error) {
// Fails without internet
console.error('Network error:', error);
}
react-native-tts works entirely offline after initial app install.
// react-native-tts: Offline ready
// Works without internet
Tts.speak('Works offline');
// Check if engine is ready
Tts.getInit().then(() => {
// Ready to speak
});
| Feature | @google-cloud/text-to-speech | react-native-tts |
|---|---|---|
| Environment | βοΈ Node.js Server | π± React Native Mobile |
| Voice Quality | ποΈ Neural/WaveNet (High) | π’ Device System (Variable) |
| Cost | π° Pay per character | π Free |
| Offline | β Internet required | β Works offline |
| Output | π Audio Buffer/File | π Direct Speaker Stream |
| Setup | π API Keys & Billing | π οΈ Native Module Linking |
@google-cloud/text-to-speech is like a professional recording studio π§ β you get top-tier quality and consistency, but you pay for the service and need a connection to use it. Best for generating podcasts, audiobooks, or customer service bots where voice quality matters most.
react-native-tts is like a built-in megaphone π£ β it is free, always available, and instant, but the voice quality depends on the user's device. Best for mobile apps needing accessibility features, notifications, or simple read-aloud functions without backend complexity.
Final Thought: Your choice depends on where the speech happens. If you need server-generated audio files with human-like quality, choose the cloud client. If you need instant, offline speech inside a mobile app, choose the native module.
Choose @google-cloud/text-to-speech if your application requires high-quality neural voices that sound human-like and consistent across all platforms. It is ideal for server-side generation where you need to save audio files, support many languages, or use SSML for advanced control. This package is best when you have backend infrastructure to handle API keys and billing securely.
Choose react-native-tts if you are building a React Native mobile app and need immediate speech feedback without internet dependency. It is suitable for features like reading alerts, accessibility support, or simple notifications where device-native voices are acceptable. This package avoids API costs and keeps speech processing entirely on the user's device.
This library is considered to be stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against stable libraries are addressed with the highest priority
Cloud Text-to-Speech API client for Node.js
A comprehensive list of changes in each version may be found in the CHANGELOG.
Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
npm install @google-cloud/text-to-speech
Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.
| Sample | Source Code |
|---|---|
| list voices | source code |
| streaming synthesize | source code |
| synthesize speech | source code |
| synthesize long audio | source code |
| list voices | source code |
| streaming synthesize | source code |
| synthesize speech | source code |
| synthesize long audio | source code |
Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:
Client libraries targeting some end-of-life versions of Node.js are available, and
can be installed through npm dist-tags.
The dist-tags follow the naming convention legacy-(version).
For example, npm install @google-cloud/text-to-speech@legacy-8 installs client libraries
for versions compatible with Node.js 8.
This library follows Semantic Versioning.
More Information: Google Cloud Platform Launch Stages
Contributions welcome! See the Contributing Guide.
Please note that this README.md
and a variety of configuration files in this repository (including .nycrc and tsconfig.json)
are generated from a central template.
Apache Version 2.0
See LICENSE