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

相关推荐
2501_920931703 小时前
React Native鸿蒙跨平台采用ScrollView的horizontal属性实现横向滚动实现特色游戏轮播和分类导航
javascript·react native·react.js·游戏·ecmascript·harmonyos
0思必得05 小时前
[Web自动化] Selenium处理动态网页
前端·爬虫·python·selenium·自动化
东东5165 小时前
智能社区管理系统的设计与实现ssm+vue
前端·javascript·vue.js·毕业设计·毕设
catino5 小时前
图片、文件的预览
前端·javascript
2501_920931707 小时前
React Native鸿蒙跨平台实现推箱子游戏,完成玩家移动与箱子推动,当所有箱子都被推到目标位置时,玩家获胜
javascript·react native·react.js·游戏·ecmascript·harmonyos
layman05287 小时前
webpack5 css-loader:从基础到原理
前端·css·webpack
半桔7 小时前
【前端小站】CSS 样式美学:从基础语法到界面精筑的实战宝典
前端·css·html
AI老李7 小时前
PostCSS完全指南:功能/配置/插件/SourceMap/AST/插件开发/自定义语法
前端·javascript·postcss
_OP_CHEN7 小时前
【前端开发之CSS】(一)初识 CSS:网页化妆术的终极指南,新手也能轻松拿捏页面美化!
前端·css·html·网页开发·样式表·界面美化
啊哈一半醒8 小时前
CSS 主流布局
前端·css·css布局·标准流 浮动 定位·flex grid 响应式布局