SHARE
TWEET

tts test

Happy99 Jul 23rd, 2019 (edited) 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <textarea id="text" rows=15 cols=80 maxlength=500>
  2. </textarea>
  3. <div>
  4.     <audio id="audio" controls="">
  5.         <source id="source" type="audio/wav">
  6.     </audio>
  7. <div>
  8. <div>
  9.     <button type="submit" id="button">OMEGA</button>
  10. </div>
  11. <span id="charlen">0</span>
  12.  
  13. <script>
  14.  
  15. document.getElementById("text").oninput = function() {
  16.     document.getElementById("charlen").innerHTML = document.getElementById("text").value.length;
  17. };
  18.  
  19. document.getElementById("button").onclick = async function() {
  20.     let text = document.getElementById("text").value;
  21.     let speak = await fetch("https://api.streamelements.com/kappa/v2/speech?voice=Hans&text=" + encodeURIComponent(text.trim()));
  22.  
  23.     if (speak.status != 200) {
  24.         alert(await speak.text());
  25.         return;
  26.     }
  27.  
  28.     let mp3 = await speak.blob();
  29.  
  30.     let blobUrl = URL.createObjectURL(mp3);
  31.     document.getElementById("source").setAttribute("src", blobUrl);
  32.     let audio = document.getElementById("audio");
  33.     audio.pause();
  34.     audio.load();
  35.     audio.play();
  36. };
  37. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top