页面自动朗读

2023-08-16  本文已影响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);
};
上一篇 下一篇

猜你喜欢

热点阅读