问题:语音播报读出阿拉伯数字,而不是中文
解决方案:对阿拉伯数字文本切割加空格就能读出阿拉伯数字,而不是中文,或者文本内加----可实现
let SpeechTTS, msg, isReady = false
const initSpeak = () => {
if (typeof plus !== 'undefined') {
SpeechTTS = uni.requireNativePlugin("MT-TTS-Speech");
SpeechTTS.init((callback) => {
isReady = true;
}, 'com.iflytek.speechcloud');
// SpeechTTS.setPitch(50); //设置语调 setPitch(num) 0-100, 默认 50
SpeechTTS.setSpeed(1); //设置语速 setSpeed(num) 0-100, 默认 50
} else {
// 使用 SpeechRecognition 识别语音
const recognition = new webkitSpeechRecognition();
recognition.onresult = function(event) {
const result = event.results[0][0].transcript;
// 将识别的文本转换成语音
const speech = new SpeechSynthesisUtterance(result);
window.speechSynthesis.speak(speech);
};
// 启动语音识别
recognition.start();
//初始化语音播报
SpeechTTS = window.speechSynthesis; // 启用文本
msg = new SpeechSynthesisUtterance();
var tips = '开始播放语音,请注意:';
msg.lang = "zh-CN"; // 使用的语言:中文
msg.volume = 1; // 声音音量:1
msg.rate = 1; // 语速:1
msg.pitch = 1; // 音高:1
}
}
const updateSpeakMsg = (index) => {
const data = page.list[index]
if (!data) return
if (typeof plus !== 'undefined' && isReady) {
const queueNo = res.data.queueNo.split("").join(' ')
SpeechTTS.speak({
text: `请 ${queueNo} 号到${res.data.windowName}`
});
} else if (SpeechTTS) {
msg.text = `请${data.queueNo}--- 号到${data.windowName}`
SpeechTTS.speak(msg); // 播放
}
}
转载:https://blog.csdn.net/qq_23073811/article/details/127486966