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

相关推荐
史林枫7 小时前
JavaScript 中call和apply的详细讲解 —— 连10岁的小朋友都能看懂!
javascript·apply·call
闲人编程7 小时前
从零开发一个简单的Web爬虫(使用Requests和BeautifulSoup)
前端·爬虫·beautifulsoup·bs4·web·request·codecapsule
紫小米7 小时前
Vue 2 和 Vue 3 的区别
前端·javascript·vue.js
dllxhcjla7 小时前
三大特性+盒子模型
java·前端·css
Cache技术分享7 小时前
233. Java 集合 - 遍历 Collection 中的元素
前端·后端
嚴寒8 小时前
Mac 安装 Dart & Flutter 完整开发环境指南
前端·macos
用户6600676685398 小时前
从变量提升到调用栈:V8 引擎如何 “读懂” JS 代码
前端·javascript
白兰地空瓶8 小时前
【深度揭秘】JS 那些看似简单方法的底层黑魔法
前端·javascript
进阶的小叮当8 小时前
Vue代码打包成apk?Cordova帮你解决!
android·前端·javascript
天天进步20158 小时前
从零开始构建现代化React应用:最佳实践与性能优化
前端·react.js·性能优化