@google-cloud/text-to-speech vs react-native-tts
Cloud vs. Native Text-to-Speech Solutions
@google-cloud/text-to-speechreact-native-ttsSimilar Packages:

Cloud vs. Native Text-to-Speech Solutions

@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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@google-cloud/text-to-speech03,2091.87 MB6528 days agoApache-2.0
react-native-tts0697162 kB1382 years agoMIT

Cloud API vs. Native Device Text-to-Speech

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.

πŸ” Initialization & Authentication

@google-cloud/text-to-speech requires secure credentials to access Google Cloud services.

  • You must set up a service account and download a JSON key file.
  • The client initializes with this key to authenticate every request.
// @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.

  • You simply import the module in your React Native component.
  • It connects directly to the device OS without setup.
// react-native-tts: Client-side init
import Tts from 'react-native-tts';

// No credentials needed
// Ready to use immediately after import

πŸ—£οΈ Speaking Text

@google-cloud/text-to-speech sends text to the cloud and receives audio data back.

  • You build a request object with input text and configuration.
  • The response contains audio content as a buffer or base64 string.
// @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.

  • You call the speak function with a string.
  • The device plays audio directly through speakers without saving files.
// react-native-tts: Speak command
Tts.speak('Hello world');

// Optional: Handle finish event
Tts.addListener('tts-finish', () => {
  console.log('Speech completed');
});

πŸŽ›οΈ Voice Selection & Control

@google-cloud/text-to-speech offers hundreds of specific cloud voices.

  • You select voices by language code and gender or specific name.
  • Supports WaveNet and Neural2 voices for higher quality.
// @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.

  • You can set language and pitch, but voice names vary by device.
  • Limited to what the user has installed on their phone.
// 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');
});

πŸ“¦ Audio Output Handling

@google-cloud/text-to-speech returns raw audio data for you to manage.

  • You receive a buffer that you can save to disk or stream.
  • Gives full control over file storage and playback timing.
// @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.

  • No file is created unless you record the output externally.
  • Playback happens instantly as part of the UI thread.
// react-native-tts: Direct playback
// No file handling needed
Tts.speak('Instant playback');

// Stop if needed
Tts.stop();

🌐 Offline Capability

@google-cloud/text-to-speech requires an active internet connection.

  • Every request goes to Google servers over HTTPS.
  • Fails if the network is unavailable or slow.
// @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.

  • Uses the device's built-in synthesis engine.
  • Ideal for apps used in areas with poor connectivity.
// react-native-tts: Offline ready
// Works without internet
Tts.speak('Works offline');

// Check if engine is ready
Tts.getInit().then(() => {
  // Ready to speak
});

πŸ“Š Summary: Key Differences

Feature@google-cloud/text-to-speechreact-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

πŸ’‘ The Big Picture

@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.

How to Choose: @google-cloud/text-to-speech vs react-native-tts

  • @google-cloud/text-to-speech:

    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.

  • react-native-tts:

    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.

README for @google-cloud/text-to-speech

Google Cloud Platform logo

Cloud Text-to-Speech API: Nodejs Client

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

npm version

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:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Cloud Text-to-Speech API API.
  4. Set up authentication so you can access the API from your local workstation.

Installing the client library

npm install @google-cloud/text-to-speech

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.

SampleSource Code
list voicessource code
streaming synthesizesource code
synthesize speechsource code
synthesize long audiosource code
list voicessource code
streaming synthesizesource code
synthesize speechsource code
synthesize long audiosource code

Supported Node.js Versions

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:

  • Legacy versions are not tested in continuous integration.
  • Some security patches and features cannot be backported.
  • Dependencies cannot be kept up-to-date.

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.

Versioning

This library follows Semantic Versioning.

More Information: Google Cloud Platform Launch Stages

Contributing

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.

License

Apache Version 2.0

See LICENSE