Skip to main content

Speech Synthesis Capacitor plugin

Synthesize speech from text with full control over language, voice, pitch, rate, and volume.

Install

bun add @capgo/capacitor-speech-synthesis bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-speech-synthesis
  • pnpm add @capgo/capacitor-speech-synthesis
  • yarn add @capgo/capacitor-speech-synthesis

Guide

How to use Speech Synthesis in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Speech Synthesis plugin preview QR code

Using @capgo/capacitor-speech-synthesis

Speech Synthesis Plugin for synthesizing speech from text.

Install

bun add @capgo/capacitor-speech-synthesis
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

API at a glance

Method Description
speak Speaks the given text with specified options. The utterance is added to the speech queue.
synthesizeToFile Synthesizes speech to an audio file (Android/iOS only). Returns the file path where the audio was saved.
cancel Cancels all queued utterances and stops current speech.
pause Pauses speech immediately.
resume Resumes paused speech.
isSpeaking Checks if speech synthesis is currently speaking.
isAvailable Checks if speech synthesis is available on the device.
getVoices Gets all available voices.
getLanguages Gets all available languages.
isLanguageAvailable Checks if a specific language is available.
isVoiceAvailable Checks if a specific voice is available.
initialize Initializes the speech synthesis engine (iOS optimization). This can reduce latency for the first speech request.
activateAudioSession Activates the audio session with a specific category (iOS only).
deactivateAudioSession Deactivates the audio session (iOS only).

Examples

speak()

Speaks the given text with specified options. The utterance is added to the speech queue.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

const result = await SpeechSynthesis.speak({
  text: 'Hello, world!',
  language: 'en-US',
  rate: 1.0,
  pitch: 1.0,
  volume: 1.0,
  queueStrategy: 'Add'
});
console.log('Utterance ID:', result.utteranceId);

synthesizeToFile()

Synthesizes speech to an audio file (Android/iOS only). Returns the file path where the audio was saved.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

const result = await SpeechSynthesis.synthesizeToFile({
  text: 'Hello, world!',
  language: 'en-US'
});
console.log('Audio file saved at:', result.filePath);

cancel()

Cancels all queued utterances and stops current speech.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

await SpeechSynthesis.cancel();

pause()

Pauses speech immediately.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

await SpeechSynthesis.pause();

resume()

Resumes paused speech.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

await SpeechSynthesis.resume();

isSpeaking()

Checks if speech synthesis is currently speaking.

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

const { isSpeaking } = await SpeechSynthesis.isSpeaking();
console.log('Is speaking:', isSpeaking);

The table above lists the 14 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or SpeechSynthesis.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-speech-synthesis

If you are using Using @capgo/capacitor-speech-synthesis to plan native plugin work, connect it with @capgo/capacitor-speech-synthesis for the implementation detail in @capgo/capacitor-speech-synthesis, Getting Started for the implementation detail in Getting Started, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins.

FAQ

Speech Synthesis plugin FAQ

How do I install the Speech Synthesis plugin in a Capacitor app?

Run "bun add @capgo/capacitor-speech-synthesis" (or "npm install @capgo/capacitor-speech-synthesis"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-speech-synthesis" in your app code.

Does @capgo/capacitor-speech-synthesis work with React, Vue and Angular?

Yes. Speech Synthesis is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-speech-synthesis support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-speech-synthesis free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-speech-synthesis/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Speech Synthesis without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Speech Synthesis changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo