<button @click="handleSpeech">開(kāi)始閱讀</button>
/** 頁(yè)面自動(dòng)朗讀 */
const text = '矩形偏移量,可以有均可用像';
const msg = ref<null | SpeechSynthesisUtterance>(null);
const synth = window.speechSynthesis;
const initSpeechMessage = () => {
const utterance = new SpeechSynthesisUtterance();
utterance.text = text; // 內(nèi)容
utterance.lang = 'zh-CN'; // 設(shè)置語(yǔ)言為中文
utterance.rate = 1.0; // 設(shè)置語(yǔ)速
msg.value = utterance;
};
initSpeechMessage();
const handleSpeech = () => {
if (!msg.value) return;
synth.speak(msg.value);
};