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

相关推荐
再努力"亿"点点4 小时前
炫酷JavaScript鼠标跟随特效
开发语言·前端·javascript
前端达人4 小时前
从 useEffect 解放出来!异步请求 + 缓存刷新 + 数据更新,React Query全搞定
前端·javascript·react.js·缓存·前端框架
qczg_wxg4 小时前
ReactNative系统组件四
javascript·react native·react.js
小浣熊喜欢揍臭臭4 小时前
uniapp+vue3 微信小程序全屏广告组件功能
微信小程序·uni-app
JIE_6 小时前
👨面试官:后端一次性给你一千万条数据,你该如何优化渲染?
前端
定栓6 小时前
vue3入门- script setup详解下
前端·vue.js·typescript
Json_Lee6 小时前
每次切项目都要改 Node 版本?macOS 自动化读取.nvmrc,解放双手!
前端
定栓6 小时前
vue3入门- script setup详解上
前端·javascript·vue.js
武汉刘德华6 小时前
Flutter配置环境,运行三端- iOS、android、harmony全流程操作实践(最新)
前端