Silence-dream / Silence-dream.github.io

blog博客
https://silence-dream.github.io
3 stars 0 forks source link

语音播放读取的内容 #31

Open Silence-dream opened 1 year ago

Silence-dream commented 1 year ago
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button onclick="press()">点击我</button>
    <script>
      function press() {
        const text = "你好";
        const utterance = new SpeechSynthesisUtterance(text);
        utterance.lang = "en"; // 语言
        utterance.rate = 1;
        utterance.pitch = 1;

        window.speechSynthesis.speak(utterance);
      }
    </script>
  </body>
</html>