本文使用了谷歌引擎。我的资源中已上传
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("请输入正确的用户名密码")