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 分钟前
从 PHP 到 AI + Golang,程序员自救转型手记(十七):登录接口完善,登录页接口整合,解决跨域
前端·后端·ai编程
唐诗18 分钟前
改 3 行配置,我的 Tauri dev 冷启动从 100 秒干到 4 秒
前端·客户端
SmartBoyW30 分钟前
深入ECMAScript规范:彻底搞懂JS隐式类型转换与底层ToPrimitive机制
前端·javascript
牧艺31 分钟前
Cursor Rules / Skills 分层设计:让 Agent 像「团队新同事」
前端·人工智能·cursor
光影少年1 小时前
react navite 跨端核心原理
前端·react native·react.js
用户852495071841 小时前
解密 JavaScript 中的 this:谁才是真正的调用者?
javascript·面试
monologues1 小时前
Vue 3 渲染器的核心秘密:从 VNode 创建到快速 Diff 算法
前端
奇奇怪怪的1 小时前
从开发到生产——生成优化、监控、安全与成本
前端
10share1 小时前
100行代码 模拟实现Vue 响应式系统
前端·vue.js
Heo1 小时前
Vite进阶用法详解
前端·javascript·面试