JSFiddle - React, Tailwind, and code Playground

by reporter

HTML

<html>
  <head>
  </head>
 <body onLoad="start()">Spielt einen Text als Ton ab
  </body>
</html>

JavaScript

//Liste mit allen Audio Elementen (HTML5)
audioElementListe = new Array(3);
function start()
{
 text_part = new Array(3);
 text_part[0]='Hallo';
 text_part[1]='Florian';
 text_part[2]='Haha';

 //Beginn for-Schleife
 for(var i = 0; i < text_part.length; i++)
 {
  //Gibt einen Link zu einer mp3-Datei zurück
  var url = "http://translate.google.com/translate_tts?tl=de&q="+text_part[i];

  audioElementListe[i] = new Audio("");
  document.body.appendChild(audioElementListe[i]);
  audioElementListe[i].src=url;
  audioElementListe[i].addEventListener('canPlay', function()
  {
   audioElementListe[i].play();
  }, false);
  audioElementListe[i].addEventListener('ended', function()
  {
   //hier scheint der Fehler zu liegen!!
   if ((i + 1) < text_part.length)
   {
    audioElementListe[i++].play();
   }
  });
    alert(audioElementListe[i].src);
 }
 //Ende der For-Schleife

 //Playaufruf des ersten Elements
 audioElementListe[0].play();
}