更新记录
1.0.1(2026-04-17)
初始化发布
平台兼容性
其他
| 多语言 | 暗黑模式 | 宽屏模式 |
|---|---|---|
| √ | √ | √ |
yq-TTS
yq-TTS 是一个基于 UTS 的多端文字转语音插件,支持 Android、iOS、Harmony 和 Web。
特点
- 支持文字转语音播报
- 支持暂停、继续、停止
- 支持获取可用语音/引擎列表
- 支持按语言、语速、音调、音量播报
- Web 端基于浏览器
SpeechSynthesis
平台
- App-Android
- App-iOS
- App-Harmony
- H5 / Web
安装
将 uni_modules/yq-tts 放入项目的 uni_modules 目录即可使用。
引入
import {
startSpeech,
stopSpeech,
pauseSpeech,
continueSpeech,
getEngines,
openSetting
} from "@/uni_modules/yq-tts";
使用示例
startSpeech({
text: "你好,这是 yq-TTS 示例。",
language: "zh-CN",
rate: 1,
pitch: 1,
volume: 1
}, (res) => {
console.log("tts event:", res);
});
pauseSpeech();
continueSpeech();
stopSpeech();
getEngines((res) => {
console.log("engines:", res);
});
项目中使用示例
<template>
<view>
<view class="area">
<textarea
:value="iptVal"
@input="iptHandle"
style="width: 100%;border: 1px solid #ccc;padding: 15px;background-color: #f2f2f2;margin-bottom: 15px;"
/>
<button type="default" @click="start">文本转语音播报</button>
<button type="default" @click="pause">播报暂停</button>
<button type="default" @click="resume">继续播报</button>
<button type="default" @click="stop">停止播报</button>
<button type="default" @click="getEnginesList">获取手机播报引擎</button>
<button type="default" @click="openSysSetting">打开设置页面</button>
</view>
<view class="eng-list" style="padding: 15px;">
<view class="title">
<text style="font-weight: bold;font-size: 20px;">引擎列表:</text>
</view>
<view v-for="(i, k) in engineList" :key="k" class="item">
{{ i.label || i.name }}
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { startSpeech, getEngines, stopSpeech, continueSpeech, pauseSpeech, openSetting } from "@/uni_modules/yq-tts";
const iptVal = ref("你好,这是 yq-TTS 示例。");
const engineList = ref([]);
const iptHandle = (e) => {
iptVal.value = e.detail.value;
};
const start = () => {
startSpeech({
text: iptVal.value,
language: "zh-CN",
rate: 1,
pitch: 1,
volume: 1
}, (res) => {
console.log("tts:", res);
});
};
const pause = () => {
pauseSpeech();
};
const resume = () => {
continueSpeech();
};
const stop = () => {
stopSpeech();
};
const getEnginesList = () => {
getEngines((res) => {
if (res.code === 0 && Array.isArray(res.data)) {
engineList.value = res.data;
}
});
};
const openSysSetting = () => {
openSetting((res) => {
console.log("setting:", res);
});
};
</script>
回调结构
{
code: 0,
msg: "播报开始",
event: "start",
data: {}
}
常用事件
start:开始播报segment:开始播报某个分段done:播报完成pause:已暂停continue:已继续stop:已停止error:发生错误engines:返回引擎列表setting:设置页结果
说明
- Android 使用系统
TextToSpeech - iOS 使用
AVSpeechSynthesizer - Harmony 使用官方 Core Speech Kit
- Web 使用浏览器语音合成
openSetting在非 Android 平台可能返回不支持getEngines在 Android/iOS/Web 返回可用引擎/语音列表,Harmony 返回默认项
示例页面
项目中可直接参考 pages/sample/tts_demo.vue

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 0
赞赏 0
下载 11579093
赞赏 1905
赞赏
京公网安备:11010802035340号