Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="utf-8" />
- <title>Web Speech API - Sintetizador</title>
- </head>
- <body>
- <h1>Web Speech API - Sintetizador</h1>
- <p>Digite o texto no campo de entrada e clique no botão.</p>
- <input id="txt" type="text" size="50"/>
- <button id="play" type="button">Play</button>
- <script>
- const synth = window.speechSynthesis;
- function talk() {
- let t = document.getElementById('txt').value;
- let voices = synth.getVoices();
- if (voices.length !== 0) {
- console.log("talk");
- let msg = new SpeechSynthesisUtterance();
- msg.voice = voices[0]; // seleciono a primeira voz
- msg.rate = 1; // velocidade
- msg.pitch = 1; // tom
- msg.text = t; // pegando a msg do campo
- msg.lang = "pt-BR";
- synth.speak(msg);
- }
- }
- document.getElementById("play").onclick = talk; // evento
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment