【TTS】uni-app语音播报app开发 / MT-TTS安卓原生自带语音合成插件——实现播放阿拉伯数字

问题:语音播报读出阿拉伯数字,而不是中文
解决方案:对阿拉伯数字文本切割加空格就能读出阿拉伯数字,而不是中文,或者文本内加----可实现

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

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值