# @capacitor-community/text-to-speech 中文文档

规范地址：https://npmcn.com/package/%40capacitor-community/text-to-speech/

版本：8\.0\.2
npm 元数据更新时间：2026-10-23T21:48:06.718Z
中文译文更新时间：2026-11-09T02:02:20.064Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40capacitor-community/text-to-speech
原文对照：https://npmcn.com/package/%40capacitor-community/text-to-speech/?lang=original
项目主页：https://github.com/capacitor-community/text-to-speech#readme
源码仓库：https://github.com/capacitor-community/text-to-speech

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：91.3 kB，28 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@capacitor/core \>=8\.0\.0
- 首次发布：2020-06-23T17:01:11.342Z
- 最新版本发布：2026-06-15T12:48:26.284Z
- 近 30 天下载量：325001（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：47（近 12 个月 3 个）

## 中文简介

从文本中合成语音的电容插件 .

## 安装

```sh
npm install @capacitor-community/text-to-speech
```

也可以使用：`pnpm add @capacitor-community/text-to-speech`、`yarn add @capacitor-community/text-to-speech`、`bun add @capacitor-community/text-to-speech`

## README

  
![](https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png)

### 文本到语音

**`@capacitor-community/text-to-speech`**

从文本中合成语音的电容社区插件 .

![](https://img.shields.io/maintenance/yes/2026?style=flat-square) [![](https://img.shields.io/github/actions/workflow/status/capacitor-community/text-to-speech/ci.yml?branch=master&style=flat-square)](https://github.com/capacitor-community/text-to-speech/actions?query=workflow%3A%22CI%22) [![](https://img.shields.io/npm/l/@capacitor-community/text-to-speech?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/text-to-speech)  
[![](https://img.shields.io/npm/dw/@capacitor-community/text-to-speech?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/text-to-speech) [![](https://img.shields.io/npm/v/@capacitor-community/text-to-speech?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/text-to-speech) [![](https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square)](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-contributors-)

## 维护者

| 维护者 | GitHub 图像 | 社会 |
| --- | --- | --- |
| 罗宾·根兹 | [抢劫](https://github.com/robingenz) | [@robin genz (中文(简体) )](https://twitter.com/robin_genz) |

## 安装

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

## 配置

此插件不需要配置 .

## 演示

这里有一个实例: [robingenz/电容器-插管-demo](https://github.com/robingenz/capacitor-plugin-demo)

## 使用量

```typescript
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(...)`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-speak)
-   [`stop()`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-stop)
-   [`getSupportedLanguages()`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-getsupportedlanguages)
-   [`getSupportedVoices()`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-getsupportedvoices)
-   [`isLanguageSupported(...)`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-islanguagesupported)
-   [`openInstall()`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-openinstall)
-   [`addListener('onRangeStart', ...)`](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-addlisteneronrangestart-)
-   [接口](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-interfaces)
-   [数字](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-enums)

### 说话(...)

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

启动 TTS 引擎并播放想要的文本 .

| 参数 | 类型 |
| --- | --- |
| **`options`** | `[TTSOptions](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-ttsoptions)` |

* * *

### 停止( )

```typescript
stop() => Promise<void>
```

停止TTS引擎.

* * *

### 获取支持语言( )

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

返回支持的 BCP 47 语言标记列表 .

**回返情况:** `Promise<{ languages: string[]; }>`

* * *

### 获得支持的声音( )

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

返回一个支持的声音列表 .

**回返情况:** `Promise<{ voices: SpeechSynthesisVoice[]; }>`

* * *

### 语言支持(...)

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

检查是否支持特定的 BCP 47 语言标记 .

| 参数 | 类型 |
| --- | --- |
| **`options`** | `{ lang: string; }` |

**回返情况:** `Promise<{ supported: boolean; }>`

* * *

### 打开Install ()

```typescript
openInstall() => Promise<void>
```

核实系统中资源文件的适当安装和可用性.

仅供Android使用.

* * *

### 添加 Listener ('on RangeStart', ...) 键入

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

| 参数 | 类型 |
| --- | --- |
| **`eventName`** | `'onRangeStart'` |
| **`listenerFunc`** | `(info: { start: number; end: number; spokenWord: string; }) => void` |

**回返情况:** `Promise<[PluginListenerHandle](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-pluginlistenerhandle)>`

* * *

### 接口

#### TTS 选项

| Prop | 类型 | 说明 | 默认 | 自兹 |
| --- | --- | --- | --- | --- |
| **`text`** | `string` | 语出后会合成的文字. |  |  |
| **`lang`** | `string` | 出言之语. 可以使用 `getSupportedLanguages`。 。 。 . | `"en-US"` |  |
| **`rate`** | `number` | 说话的速度. | `1.0` |  |
| **`pitch`** | `number` | 说话的音响. | `1.0` |  |
| **`volume`** | `number` | 语音的音量. | `1.0` |  |
| **`voice`** | `number` | 用于说话的选定语音索引 。 可用 `getSupportedVoices`。 。 。 . |  |  |
| **`category`** | `string` | 选择 iOS 音频会话分类 。 可能的数值 : `ambient` 财务报告和审定财务报表 `playback`启用 `playback` 用于播放音频,即使应用程序处于背景状态。 仅供iOS使用. | `"ambient"` |  |
| **`queueStrategy`** | `[QueueStrategy](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-queuestrategy)` | 选择多个发言请求重叠时要采用的策略 . | `QueueStrategy.Flush` | 5.1.0 国家 |

#### 语音合成

这个 [语音合成](https://npmcn.com/package/%40capacitor-community/text-to-speech/#readme-speechsynthesisvoice) 接口代表系统支持的声音.

| Prop | 类型 | 说明 |
| --- | --- | --- |
| **`default`** | `boolean` | 指定语音是否为当前应用程序的默认语音( S)`true`)或不(`false`) (中文(简体) ). |
| **`lang`** | `string` | BCP 47语言标记表示语音语言. |
| **`localService`** | `boolean` | 指定该语音是否由本地(`true`)或远程(`false`) 语音合成器服务. |
| **`name`** | `string` | 代表声音的人类可读名. |
| **`voiceURI`** | `string` | 此语音的URI类型和语音合成服务位置. |

#### 插件听筒

| Prop | 类型 |
| --- | --- |
| **`remove`** | `() => Promise<void>` |

### 数字

#### 队列战略

| 成员 | 数值 | 说明 |
| --- | --- | --- |
| **`Flush`** | `0` | 使用 `Flush` 当新请求发出时, 停止当前请求. |
| **`Add`** | `1` | 使用 `Add` 以缓冲语音请求。 请求将在所有先前的请求完成后执行. |

## 更改日志

见 [变动情况](https://github.com/capacitor-community/text-to-speech/blob/master/CHANGELOG.md)。 。 。 .

## 许可证

见 [自由主义](https://github.com/capacitor-community/text-to-speech/blob/master/LICENSE)。 。 。 .

## 常见问题

### @capacitor-community/text-to-speech 是什么？

从文本中合成语音的电容插件 \.

### 如何安装 @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 和提交记录判断。

