🌟🌟Simple text a veu

Conversor de text a veu

🔊 Conversor de text a veu

<!DOCTYPE html>
<html lang="ca">
<head>
  <meta charset="UTF-8">
  <title>Conversor de text a veu</title>
  <style>
    body {
      font-family: sans-serif;
      padding: 2em;
      background-color: #f4f4f4;
    }
    input {
      font-size: 1.2em;
      padding: 0.5em;
      margin-top: 1em;
      width: 100%;
      max-width: 500px;
    }
    #speakBtn {
      font-size: 2em;
      background: none;
      border: none;
      cursor: pointer;
      margin-top: 1em;
    }
    #speakBtn:hover {
      color: #0078D7;
    }
  </style>
</head>
<body>
  <h2>🔊 Conversor de text a veu</h2>
  <input type="text" id="cercar" placeholder="Escriu el text que vols escoltar">
  <button id="speakBtn" title="Escolta el text">🔊</button>

  <script>
    document.addEventListener('DOMContentLoaded', () => {
      const inputElement = document.getElementById('cercar');
      const speakBtn = document.getElementById('speakBtn');
      let voices = [];

      function loadVoices() {
        voices = speechSynthesis.getVoices();
      }

      speechSynthesis.onvoiceschanged = loadVoices;
      loadVoices();

      function speakText() {
        const text = inputElement.value.trim();
        if (!text) return;

        const utterance = new SpeechSynthesisUtterance(text);
        const zira = voices.find(v => v.name === 'Microsoft Zira - English (United States)');

        if (zira) {
          utterance.voice = zira;
          utterance.lang = zira.lang;
        }

        utterance.rate = 1;
        utterance.pitch = 1;

        speechSynthesis.cancel();
        speechSynthesis.speak(utterance);
      }

      speakBtn.addEventListener('click', speakText);

      // 🔁 Repetir cada 10 segons
      setInterval(speakText, 10000);
    });
  </script>
</body>
</html>

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *

This site uses Akismet to reduce spam. Learn how your comment data is processed.