Skip to content

GoogleTTS

Convert text to speech using Google Cloud Text-to-Speech's Chirp 3, Neural2, Studio, and WaveNet voices via a simple REST API.

Use GoogleTTS when you want Google Cloud Text-to-Speech’s voice catalog — from lightweight Standard and WaveNet voices to Neural2, Studio, and the Chirp 3: HD generation — via a simple REST call. Each synthesize() request returns the complete audio as a Blob; no WebSocket management required.

Prerequisites

  • A Google Cloud API key with the Text-to-Speech API enabled, or a CompositeVoice proxy server
  • No additional dependencies required. GoogleTTS uses native fetch internally.

Basic setup

import { CompositeVoice, NativeSTT, AnthropicLLM, GoogleTTS, BrowserAudioOutput } from 'composite-voice';

const voice = new CompositeVoice({
  providers: [
    new NativeSTT(),
    new AnthropicLLM({
      proxyUrl: '/api/proxy/anthropic',
      model: 'claude-haiku-4-5',
    }),
    new GoogleTTS({
      proxyUrl: '/api/proxy/google-tts',
      languageCode: 'en-US',
      voiceName: 'en-US-Chirp3-HD-Kore',
      audioEncoding: 'MP3',
    }),
    new BrowserAudioOutput(),
  ],
});

await voice.initialize();
await voice.startListening();

Configuration options

OptionTypeDefaultDescription
apiKeystringGoogle Cloud API key (direct mode; sent via X-goog-api-key header)
proxyUrlstringProxy server URL (recommended for production)
languageCodestring'en-US'BCP-47 language/region code for the voice
voiceNamestringGoogle defaultSpecific voice, e.g. en-US-Chirp3-HD-Kore, en-US-Neural2-F
ssmlGenderstringMALE, FEMALE, or NEUTRAL — voice preference when voiceName is omitted
audioEncodingstring'MP3'MP3, OGG_OPUS, LINEAR16, MULAW, ALAW
speakingRatenumber1.0Speaking rate multiplier (0.25 — 4.0)
pitchnumber0Pitch adjustment in semitones (-20 to +20)
volumeGainDbnumber0Volume gain in dB (-96.0 to +16.0)
sampleRateHertznumbervoice nativeOutput sample rate in Hz
effectsProfileIdstring[]Device effects profiles, e.g. ['headphone-class-device']
endpointstringCustom API endpoint URL
maxRetriesnumber3Retry count for failed requests

Available voices

Voice names encode the language, family, and variant. Current families include Chirp 3: HD (latest generation, e.g. en-US-Chirp3-HD-Kore), Neural2 (en-US-Neural2-F), Studio (en-US-Studio-O), WaveNet (en-US-Wavenet-D), Polyglot, News, Casual, and Standard. List everything available for your project with Google’s GET /v1/voices endpoint. (The older Journey voices were retired and folded into Chirp 3: HD.)

Output encodings

EncodingUse case
MP3Good compression, wide browser support (default)
OGG_OPUSGood compression, open format
LINEAR16Uncompressed 16-bit PCM with WAV header, highest quality
MULAW / ALAWG.711 telephony formats (with WAV header)

Complete example

import { CompositeVoice, MicrophoneInput, DeepgramSTT, AnthropicLLM, GoogleTTS, BrowserAudioOutput } from 'composite-voice';

const tts = new GoogleTTS({
  proxyUrl: '/api/proxy/google-tts',
  languageCode: 'en-GB',
  voiceName: 'en-GB-Neural2-A',
  audioEncoding: 'MP3',
  speakingRate: 1.1,
  effectsProfileId: ['headphone-class-device'],
});

const voice = new CompositeVoice({
  providers: [
    new MicrophoneInput(),
    new DeepgramSTT({ proxyUrl: '/api/proxy/deepgram' }),
    new AnthropicLLM({
      proxyUrl: '/api/proxy/anthropic',
      model: 'claude-haiku-4-5',
    }),
    tts,
    new BrowserAudioOutput(),
  ],
});

voice.on('tts.start', () => console.log('Speaking...'));
voice.on('tts.end', () => console.log('Done speaking'));

await voice.initialize();
await voice.startListening();

SSML support

Input that starts with <speak is sent as SSML instead of plain text, giving you control over pauses, pronunciation, and emphasis:

await tts.synthesize('<speak>Hello <break time="300ms"/> world. <say-as interpret-as="characters">SDK</say-as></speak>');

See the Google Cloud SSML reference for the supported tags. Note that some newer voice families (e.g. Chirp 3: HD) have limited SSML support — prefer Neural2/Studio/WaveNet voices for heavy SSML use.

Tips

  • GoogleTTS is REST-based, not streaming. The full audio Blob is returned after the API processes the entire input. For real-time streaming, consider DeepgramTTS.
  • The Google API returns audio base64-encoded (audioContent); GoogleTTS decodes it into a playable Blob for you.
  • Use proxyUrl in production so your API key stays server-side — set googleCloudApiKey in your proxy config. The same key also powers GoogleSTT via the google-stt route.
  • Authentication uses a Google Cloud API key (injected as the X-goog-api-key header; Google also accepts it as a ?key= query parameter). Google’s OAuth2 service-account authentication is out of scope for this SDK — it requires server-side token minting and refresh, which is exactly what the proxy pattern replaces. Restrict your API key to the Text-to-Speech API in the Google Cloud console.

Further reading

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency