uni app 的app 端调用tts 进行文字转语音

本文使用了谷歌引擎。我的资源中已上传

speckutils.js 代码如下

复制代码
// #ifdef APP
const SpeechTTS = uni.requireNativePlugin("MT-TTS-Speech");
// #endif



function init(callback) {
	// #ifdef APP
	console.log('>> tts: init = 111');
	SpeechTTS.init((res) => {
		console.log(JSON.stringify(res))
		callback(true)
		console.log('>> tts: init success');
	});
	console.log('>> tts: init = 222');
	// #endif
}

function speckAndShwoTast(text) {

	uni.showToast({
		title: text,
		icon: 'none'
	});
	// #ifdef APP
	const res = SpeechTTS.speak({
		text: text
	});
	console.log('>> tts: play result = ' + res);
	// #endif
}

function speckText(text) {
	// #ifdef APP
	const res = SpeechTTS.speak({
		text: text
	});
	console.log('>> tts: play result = ' + res);
	// #endif
}

function speckstop() {
	// #ifdef APP
	SpeechTTS.stop((res) => {
		console.log("speckstop", JSON.stringify(res))
	})
	// #endif
}

function destroy() {
	// #ifdef APP
	console.log("销毁tts")
	SpeechTTS.destroy()
	// #endif
}


module.exports = {

	init: init,
	speckAndShwoTast: speckAndShwoTast,
	speckText: speckText,
	destroy: destroy,

};

使用

import {

speckAndShwoTast

} from '../../utils/speckutils'

speckAndShwoTast("请输入正确的用户名密码")

相关推荐
GuWenyue3 小时前
放弃云端API!一套React+WebGPU本地LLM方案,零数据上传、离线可用
前端·人工智能·前端框架
原则猫5 小时前
函数/变量提升
前端
码兄科技5 小时前
实战:基于Spring Boot + UniApp的地理信息小程序开发
spring boot·后端·uni-app
独泪了无痕5 小时前
Vue3 Hooks使用实战解析
前端·vue.js
shawxlee7 小时前
vue3在public下封装config.js自定义配置动态数据,可在打包后直接修改,方便后端部署及后续维护
前端·javascript·经验分享·vue·团队开发·js·项目优化
用户059540174467 小时前
把记忆存储的回归测试从手工换成 Playwright + GitHub Actions,线上缺陷降低 80%
前端·css
触底反弹7 小时前
🚀 从 DOM0 级到 React 合成事件:前端事件监听的 20 年演进史
前端·react.js·面试
kyriewen7 小时前
我给前端项目的接口请求套了6层保护——才发现以前一直在裸奔
前端·javascript·面试
颜酱7 小时前
04 | 召回前置准备:搭好召回所需的四个数据库
前端·人工智能·后端
郝亚军9 小时前
如何安装webstorm、Node.js和vue CLI
前端·javascript·vue.js