@capacitor-community/text-to-speech

中文文档
8.0.2发布于 2026/06/15MITTypeScriptESM + CJS零依赖近 30 天下载 32.5万

Capacitor plugin for synthesizing speech from text.

原始使用文档
文档目录18 节
  1. Text to Speech
  2. Maintainers
  3. Installation
  4. Configuration
  5. Demo
  6. Usage
  7. API
  8. speak(...)
  9. stop()
  10. getSupportedLanguages()
  11. getSupportedVoices()
  12. isLanguageSupported(...)
  13. openInstall()
  14. addListener('onRangeStart', ...)
  15. Interfaces
  16. Enums
  17. Changelog
  18. License


Text to Speech

@capacitor-community/text-to-speech

Capacitor community plugin for synthesizing speech from text.


Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

npm install @capacitor-community/text-to-speech
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { TextToSpeech } from '@capacitor-community/text-to-speech';

const speak = async () => {
  await TextToSpeech.speak({
    text: 'This is a sample text.',
    lang: 'en-US',
    rate: 1.0,
    pitch: 1.0,
    volume: 1.0,
    category: 'ambient',
    queueStrategy: 1
  });
};

const stop = async () => {
  await TextToSpeech.stop();
};

const getSupportedLanguages = async () => {
  const languages = await TextToSpeech.getSupportedLanguages();
};

const getSupportedVoices = async () => {
  const voices = await TextToSpeech.getSupportedVoices();
};

const isLanguageSupported = async (lang: string) => {
  const isSupported = await TextToSpeech.isLanguageSupported({ lang });
};

API

speak(...)

speak(options: TTSOptions) => Promise<void>

Starts the TTS engine and plays the desired text.

ParamType
optionsTTSOptions

stop()

stop() => Promise<void>

Stops the TTS engine.


getSupportedLanguages()

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

Returns a list of supported BCP 47 language tags.

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


getSupportedVoices()

getSupportedVoices() => Promise<{ voices: SpeechSynthesisVoice[]; }>

Returns a list of supported voices.

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


isLanguageSupported(...)

isLanguageSupported(options: { lang: string; }) => Promise<{ supported: boolean; }>

Checks if a specific BCP 47 language tag is supported.

ParamType
options{ lang: string; }

Returns: Promise<{ supported: boolean; }>


openInstall()

openInstall() => Promise<void>

Verifies proper installation and availability of resource files on the system.

Only available for Android.


addListener('onRangeStart', ...)

addListener(eventName: 'onRangeStart', listenerFunc: (info: { start: number; end: number; spokenWord: string; }) => void) => Promise<PluginListenerHandle>
ParamType
eventName'onRangeStart'
listenerFunc(info: { start: number; end: number; spokenWord: string; }) => void

Returns: Promise<PluginListenerHandle>


Interfaces

TTSOptions

PropTypeDescriptionDefaultSince
textstringThe text that will be synthesised when the utterance is spoken.
langstringThe language of the utterance. Possible languages can be queried using getSupportedLanguages."en-US"
ratenumberThe speed at which the utterance will be spoken at.1.0
pitchnumberThe pitch at which the utterance will be spoken at.1.0
volumenumberThe volume that the utterance will be spoken at.1.0
voicenumberThe index of the selected voice that will be used to speak the utterance. Possible voices can be queried using getSupportedVoices.
categorystringSelect the iOS Audio session category. Possible values: ambient and playback. Use playback to play audio even when the app is in the background. Only available for iOS."ambient"
queueStrategyQueueStrategySelect the strategy to adopt when several requests to speak overlap.QueueStrategy.Flush5.1.0

SpeechSynthesisVoice

The SpeechSynthesisVoice interface represents a voice that the system supports.

PropTypeDescription
defaultbooleanSpecifies whether the voice is the default voice for the current app (true) or not (false).
langstringBCP 47 language tag indicating the language of the voice.
localServicebooleanSpecifies whether the voice is supplied by a local (true) or remote (false) speech synthesizer service.
namestringHuman-readable name that represents the voice.
voiceURIstringType of URI and location of the speech synthesis service for this voice.

PluginListenerHandle

PropType
remove() => Promise<void>

Enums

QueueStrategy

MembersValueDescription
Flush0Use Flush to stop the current request when a new request is sent.
Add1Use Add to buffer the speech request. The request will be executed when all previous requests have been completed.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capacitor-community/text-to-speech 共发布 47 个版本,首次发布于 2020/06/24;过去 12 个月发布了 3 个版本。

版本发布日期距今
8.0.2latest2026/06/154 个月前
8.0.12026/06/075 个月前
8.0.02026/01/319 个月前
6.1.02025/10/241 年前
6.0.02025/01/291.8 年前
5.1.0-dev.cf04aa9.1738003753dev2025/01/281.8 年前

关于 @capacitor-community/text-to-speech 的常见问题

@capacitor-community/text-to-speech 是什么?

Capacitor plugin for synthesizing speech from text.

如何安装 @capacitor-community/text-to-speech?

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

@capacitor-community/text-to-speech 支持 TypeScript 吗?

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

@capacitor-community/text-to-speech 支持 ESM 还是 CommonJS?

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

@capacitor-community/text-to-speech 可以商用吗?

@capacitor-community/text-to-speech 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/text-to-speech 的下载量有多少?

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

@capacitor-community/text-to-speech 还在维护吗?

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