页面自动朗读
作者:
如果俞天阳会飞 | 来源:发表于
2023-08-16 15:39 被阅读0次<button @click="handleSpeech">开始阅读</button>
/** 页面自动朗读 */
const text = '矩形偏移量,可以有均可用像';
const msg = ref<null | SpeechSynthesisUtterance>(null);
const synth = window.speechSynthesis;
const initSpeechMessage = () => {
const utterance = new SpeechSynthesisUtterance();
utterance.text = text; // 内容
utterance.lang = 'zh-CN'; // 设置语言为中文
utterance.rate = 1.0; // 设置语速
msg.value = utterance;
};
initSpeechMessage();
const handleSpeech = () => {
if (!msg.value) return;
synth.speak(msg.value);
};
本文标题:页面自动朗读
本文链接:https://www.haomeiwen.com/subject/elokmdtx.html
网友评论