eReader-TTS
Its a eReader using Google's & iSpeech's webservice for Text-To-Speech
HTML
<div class=container>
<div>
<textarea class=textToRead rows="10" cols="100" placeholder="Enter text to read">
It's incredible stowaway lived through the five-and-a-half hour flight from California to Hawaii in the plane's wheel well given the intense pressure from altitude and below freezing temperatures he experienced.
</textarea>
<button class=readByGoogle>Read now by Google</button>
<button class=readByISpeech>Read now by iSpeech</button>
<audio id=player>
<source class="audioSource" src="https://ssl.gstatic.com/dictionary/static/sounds/de/0/welcome.mp3" type="audio/mp3"></source>
</audio>
</div>
</div>
JavaScript
$(document).ready(function(){
var tokens=[];
var player = $('#player')[0];
$(".readByGoogle").on("click",function(){
var textToRead = $(".textToRead").val();
tokens = textToRead.split(/\W/gi);
$("audio").each(function () {
this.addEventListener("ended",function () {
if(tokens.length!=0)
playNext(tokens.shift());
});
this.addEventListener('error', function failed(e) {
if(!$(this).src){
playNext(tokens.shift());
}
}, true);
});
player.play();
});
$(".readByISpeech").on("click",function(){
var textToRead = $(".textToRead").val();
$('.audioSource').attr('src', 'http://www.ispeech.org/p/generic/getaudio?text='+encodeURIComponent(textToRead)+'%2C&voice=usenglishfemale&speed=-4&action=convert');
player.load();
player.play();
});
function playNext(word){
var isWord = /\w/;
if(isWord.test(word)){
$('.audioSource').attr('src', 'https://ssl.gstatic.com/dictionary/static/sounds/de/0/'+word.toLowerCase()+'.mp3');
player.load();
player.play();
}else{
playNext(tokens.shift());
}
}
});