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("请输入正确的用户名密码")

相关推荐
sghuter1 天前
Chrome如何重塑Web标准未来
前端·chrome
渣渣xiong1 天前
从零开始:前端转型AI agent直到就业第十四天-第十七天
前端·人工智能
changshuaihua0011 天前
React 入门
前端·javascript·react.js
兰为鹏1 天前
做前端需求总结出的非常好用的skill
前端
笨笨狗吞噬者1 天前
Opus 4.7 skill 编写和使用实践
前端·ai编程
舞影天上1 天前
WordPress MCP Adapter 调试实战:从"连接失败"到完全可用
前端·ai编程
可视之道1 天前
Web组态编辑器的撤销重做架构设计
前端
掘金安东尼1 天前
本周前端与 AI 技术情报|前端下一步 #462
前端·javascript·面试
赵庆明老师1 天前
vben开发入门5:vite.config.ts
前端·html·vue3·vben
qq_12084093711 天前
Three.js 工程向:实例化渲染 InstancedMesh 的批量优化
前端·javascript