@capgo/capacitor-speech-synthesis

中文文档
8.0.27发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5万

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

原始使用文档
文档目录27 节
  1. ➡️ Get started for free
  2. Key features
  3. Why Speech Synthesis?
  4. Compatibility
  5. Install
  6. API
  7. speak(...)
  8. synthesizeToFile(...)
  9. cancel()
  10. pause()
  11. resume()
  12. isSpeaking()
  13. isAvailable()
  14. getVoices()
  15. getLanguages()
  16. isLanguageAvailable(...)
  17. isVoiceAvailable(...)
  18. initialize()
  19. activateAudioSession(...)
  20. deactivateAudioSession()
  21. getPluginVersion()
  22. addListener('start', ...)
  23. addListener('end', ...)
  24. addListener('boundary', ...)
  25. addListener('error', ...)
  26. removeAllListeners()
  27. Interfaces

@capgo/capacitor-speech-synthesis

Read text aloud in your Capacitor app with native text-to-speech, and control the language, voice, pitch, rate and volume.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-speech-synthesis in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-speech-synthesis to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-speech-synthesis for Capacitor apps

Key features

  • Speak: speak() with language, voice, pitch, rate, volume and queue strategy.
  • Playback control: pause(), resume(), cancel() and isSpeaking(). Pause and resume are not supported on Android.
  • Voices and languages: getVoices(), getLanguages(), isLanguageAvailable() and isVoiceAvailable().
  • Save to file: synthesizeToFile() writes speech to an audio file on iOS and Android.
  • Events: start, end, boundary and error listeners.
  • Platforms: iOS, Android and Web. iOS uses AVSpeechSynthesizer, Android uses TextToSpeech. Web uses the Web Speech API.

Why Speech Synthesis?

A free, open-source alternative providing complete text-to-speech capabilities:

  • Cross-platform - Works on iOS, Android, and Web with consistent API
  • Full voice control - Choose from system voices, adjust pitch, rate, and volume
  • Event-driven - Listen to speech events (start, end, word boundaries, errors)
  • File export - Save speech to audio files on iOS and Android
  • Modern APIs - Uses AVSpeechSynthesizer (iOS), TextToSpeech (Android), and Web Speech API
  • Production-ready - Complete TypeScript support with comprehensive documentation

Perfect for accessibility features, language learning apps, audiobook players, and any app needing text-to-speech.

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-speech-synthesis` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-speech-synthesis
npx cap sync

API

Speech Synthesis Plugin for synthesizing speech from text.

speak(...)

speak(options: SpeakOptions) => Promise<SpeakResult>

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

ParamTypeDescription
optionsSpeakOptions- The speech options including text and voice settings

Returns: Promise<SpeakResult>

Since: 1.0.0


synthesizeToFile(...)

synthesizeToFile(options: SpeakOptions) => Promise<SynthesizeToFileResult>

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

ParamTypeDescription
optionsSpeakOptions- The speech options including text and voice settings

Returns: Promise<SynthesizeToFileResult>

Since: 1.0.0


cancel()

cancel() => Promise<void>

Cancels all queued utterances and stops current speech.

Since: 1.0.0


pause()

pause() => Promise<void>

Pauses speech immediately.

Since: 1.0.0


resume()

resume() => Promise<void>

Resumes paused speech.

Since: 1.0.0


isSpeaking()

isSpeaking() => Promise<{ isSpeaking: boolean; }>

Checks if speech synthesis is currently speaking.

Returns: Promise<{ isSpeaking: boolean; }>

Since: 1.0.0


isAvailable()

isAvailable() => Promise<{ isAvailable: boolean; }>

Checks if speech synthesis is available on the device.

Returns: Promise<{ isAvailable: boolean; }>

Since: 1.0.0


getVoices()

getVoices() => Promise<{ voices: VoiceInfo[]; }>

Gets all available voices.

Returns: Promise<{ voices: VoiceInfo[]; }>

Since: 1.0.0


getLanguages()

getLanguages() => Promise<{ languages: string[]; }>

Gets all available languages.

Returns: Promise<{ languages: string[]; }>

Since: 1.0.0


isLanguageAvailable(...)

isLanguageAvailable(options: IsLanguageAvailableOptions) => Promise<{ isAvailable: boolean; }>

Checks if a specific language is available.

ParamTypeDescription
optionsIsLanguageAvailableOptions- The language to check

Returns: Promise<{ isAvailable: boolean; }>

Since: 1.0.0


isVoiceAvailable(...)

isVoiceAvailable(options: IsVoiceAvailableOptions) => Promise<{ isAvailable: boolean; }>

Checks if a specific voice is available.

ParamTypeDescription
optionsIsVoiceAvailableOptions- The voice ID to check

Returns: Promise<{ isAvailable: boolean; }>

Since: 1.0.0


initialize()

initialize() => Promise<void>

Initializes the speech synthesis engine (iOS optimization). This can reduce latency for the first speech request.

Since: 1.0.0


activateAudioSession(...)

activateAudioSession(options: ActivateAudioSessionOptions) => Promise<void>

Activates the audio session with a specific category (iOS only).

ParamTypeDescription
optionsActivateAudioSessionOptions- The audio session category

Since: 1.0.0


deactivateAudioSession()

deactivateAudioSession() => Promise<void>

Deactivates the audio session (iOS only).

Since: 1.0.0


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Gets the native plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


addListener('start', ...)

addListener(eventName: 'start', listenerFunc: (event: UtteranceEvent) => void) => Promise<PluginListenerHandle>

Listens for when an utterance starts speaking.

ParamTypeDescription
eventName'start'- The event name ('start')
listenerFunc(event: UtteranceEvent) => void- The callback function

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('end', ...)

addListener(eventName: 'end', listenerFunc: (event: UtteranceEvent) => void) => Promise<PluginListenerHandle>

Listens for when an utterance finishes speaking.

ParamTypeDescription
eventName'end'- The event name ('end')
listenerFunc(event: UtteranceEvent) => void- The callback function

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('boundary', ...)

addListener(eventName: 'boundary', listenerFunc: (event: BoundaryEvent) => void) => Promise<PluginListenerHandle>

Listens for word boundaries during speech.

ParamTypeDescription
eventName'boundary'- The event name ('boundary')
listenerFunc(event: BoundaryEvent) => void- The callback function

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('error', ...)

addListener(eventName: 'error', listenerFunc: (event: ErrorEvent) => void) => Promise<PluginListenerHandle>

Listens for synthesis errors.

ParamTypeDescription
eventName'error'- The event name ('error')
listenerFunc(event: ErrorEvent) => void- The callback function

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all event listeners.

Since: 1.0.0


Interfaces

SpeakResult

Result from speaking text.

PropTypeDescriptionSince
utteranceIdstringUnique identifier for this utterance.1.0.0

SpeakOptions

Options for speaking text.

PropTypeDescriptionSince
textstringThe text to speak.1.0.0
languagestringThe BCP-47 language tag (e.g., 'en-US', 'es-ES').1.0.0
voiceIdstringThe voice identifier to use.1.0.0
pitchnumberThe pitch of the voice (0.5 to 2.0, default: 1.0).1.0.0
ratenumberThe speaking rate (0.1 to 10.0, default: 1.0).1.0.0
volumenumberThe volume (0.0 to 1.0, default: 1.0).1.0.0
queueStrategy'Add' | 'Flush'The queue strategy: 'Add' to append or 'Flush' to replace queue. Default: 'Add'1.0.0

SynthesizeToFileResult

Result from synthesizing to file.

PropTypeDescriptionSince
filePathstringThe file path where audio was saved.1.0.0
utteranceIdstringUnique identifier for this utterance.1.0.0

VoiceInfo

Information about a voice.

PropTypeDescriptionSince
idstringUnique voice identifier.1.0.0
namestringDisplay name of the voice.1.0.0
languagestringBCP-47 language code.1.0.0
gender'male' | 'female' | 'neutral'Gender of the voice (iOS only).1.0.0
isNetworkConnectionRequiredbooleanWhether this voice requires a network connection.1.0.0
defaultbooleanWhether this is the default voice (Web only).1.0.0

IsLanguageAvailableOptions

Options for checking language availability.

PropTypeDescriptionSince
languagestringThe BCP-47 language code to check.1.0.0

IsVoiceAvailableOptions

Options for checking voice availability.

PropTypeDescriptionSince
voiceIdstringThe voice ID to check.1.0.0

ActivateAudioSessionOptions

Options for activating the audio session (iOS only).

PropTypeDescriptionSince
category'Ambient' | 'Playback'The audio session category. - 'Ambient': Mixes with other audio - 'Playback': Stops other audio1.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

UtteranceEvent

Event emitted when utterance starts or ends.

PropTypeDescriptionSince
utteranceIdstringThe utterance identifier.1.0.0

BoundaryEvent

Event emitted at word boundaries.

PropTypeDescriptionSince
utteranceIdstringThe utterance identifier.1.0.0
charIndexnumberThe character index in the text.1.0.0
charLengthnumberThe character length of the current word.1.0.0

ErrorEvent

Event emitted on synthesis error.

PropTypeDescriptionSince
utteranceIdstringThe utterance identifier.1.0.0
errorstringThe error message.1.0.0

版本与发布记录

@capgo/capacitor-speech-synthesis 共发布 29 个版本,首次发布于 2025/11/19;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.27latest2026/10/1525 天前
8.0.262026/10/1327 天前
8.0.252026/10/091 个月前
8.0.232026/10/081 个月前
8.0.242026/10/081 个月前
8.0.222026/09/161 个月前

关于 @capgo/capacitor-speech-synthesis 的常见问题

@capgo/capacitor-speech-synthesis 是什么?

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

如何安装 @capgo/capacitor-speech-synthesis?

在项目目录运行 npm install @capgo/capacitor-speech-synthesis,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-speech-synthesis 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-speech-synthesis 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-speech-synthesis 可以商用吗?

@capgo/capacitor-speech-synthesis 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-speech-synthesis 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-speech-synthesis 在 2026/10/09 – 2026/11/07 这 30 天内被下载 49,811 次,日均约 1,660 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-speech-synthesis 还在维护吗?

最新版本 8.0.27 发布于 2026/10/15(25 天前);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2025/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。