Refactoring Complet
Voir facebook pour l'installation de la nouvelle BDD.
This commit is contained in:
@ -1,302 +0,0 @@
|
||||
function showSelection() {
|
||||
$('#addpicture').hide();
|
||||
$('#selection').show("slow");
|
||||
$('#liAddImages').removeClass("active");
|
||||
$('#liSelection').addClass("active");
|
||||
}
|
||||
|
||||
function showAddPicture() {
|
||||
$('#selection').hide();
|
||||
$('#addpicture').show("slow");
|
||||
$('#liSelection').removeClass("active");
|
||||
$('#liAddImages').addClass("active");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Selection d'une recherche d'oeuvre
|
||||
$('.listeoeuvre').click(function(event) {
|
||||
showSelection();
|
||||
$("#sessionName").empty();
|
||||
$("#sessionName").text($(this).children(".sessionName").text());
|
||||
$('.listeoeuvre').removeClass("active");
|
||||
$(this).addClass("active");
|
||||
$('#oeuvrePic').empty();
|
||||
|
||||
// asso games
|
||||
url = "/getAssoGames/" + $(this).children('.idListeOeuvre').val();
|
||||
var p = new XMLHttpRequest();
|
||||
p.open("GET", url, true);
|
||||
p.onreadystatechange = function () {
|
||||
if (p.readyState != 4 || p.status != 200)
|
||||
return;
|
||||
var data2 = JSON.parse(p.response);
|
||||
$( ".checkboxGame" ).prop( "checked", false);
|
||||
|
||||
for (el in data2) {
|
||||
id = data2[el].id;
|
||||
$('#checkbox' + id).prop( "checked", true );
|
||||
}
|
||||
};
|
||||
p.send();
|
||||
|
||||
url = "/showListOeuvres/" + $(this).children('.idListeOeuvre').val();
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("GET", url, true);
|
||||
r.onreadystatechange = function () {
|
||||
if (r.readyState != 4 || r.status != 200)
|
||||
return;
|
||||
var data = JSON.parse(r.response);
|
||||
if (data.length == 0 )
|
||||
$("#oeuvrePic").append("Aucune Oeuvre");
|
||||
else {
|
||||
$("#oeuvrePic").append('<select multiple="multiple" id="my_selection" name="my_selection" class="image-picker show-html">');
|
||||
for (el in data)
|
||||
{
|
||||
$('#my_selection').append('<option data-img-src="http://www.augustins.org/documents/10180/156407/' + data[el].urlPhoto + '" class="option_selected" id="selection'+ data[el].id +'" value="'+ data[el].id + '"></option>');
|
||||
$("select").imagepicker();
|
||||
}
|
||||
}
|
||||
};
|
||||
r.send();
|
||||
});
|
||||
|
||||
|
||||
|
||||
//Enregistrement d'une liste d'ouevre
|
||||
$('#enregistrer').click(function() {
|
||||
url = "setListOeuvres";
|
||||
dataSend = {
|
||||
_token : $('#_tokenRes').val(),
|
||||
idListeOeuvre : "1",
|
||||
oeuvres : "1-2-3-4"};
|
||||
$.post(url,
|
||||
dataSend,
|
||||
function( data ) {
|
||||
;
|
||||
}, "json")
|
||||
.done(function() {
|
||||
$("#oeuvrePic").append('<div class="alert alert-success">'
|
||||
+'<ul>'
|
||||
+'<li>Sauvegarde validée</li>'
|
||||
+'</ul>'
|
||||
+'</div>');
|
||||
})
|
||||
.fail(function() {
|
||||
$("#oeuvrePic").append('<div class="alert alert-danger">'
|
||||
+'<strong>Oouups!</strong> Il y a un problème.<br><br>'
|
||||
+'<ul>'
|
||||
+'<li>Erreur lors de l\'envoie</li>'
|
||||
+'</ul>'
|
||||
+'</div>');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Suppression des n oeuvres selectionnés
|
||||
$('#removeFromSelection').click(function() {
|
||||
|
||||
url = "removeFromSelection";
|
||||
dataSend = {
|
||||
_token : $('#_tokenRemoveFromSelection').val(),
|
||||
oeuvres : $('#my_selection').val()};
|
||||
$.post(url,
|
||||
dataSend,
|
||||
function( data ) {
|
||||
;
|
||||
}, "json")
|
||||
.done(function() {
|
||||
$('#my_selection').val().forEach( function(el) {
|
||||
$('#selection'+ el).remove();
|
||||
});
|
||||
$("select").imagepicker();
|
||||
})
|
||||
.fail(function() {
|
||||
$("#oeuvrePic").append('<div class="alert alert-danger">'
|
||||
+'<strong>Oouups!</strong> Il y a un problème.<br><br>'
|
||||
+'<ul>'
|
||||
+'<li>Erreur lors de la Suppression</li>'
|
||||
+'</ul>'
|
||||
+'</div>');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Add to my favorites list
|
||||
$('#addIntoMyList').click(function() {
|
||||
|
||||
url = "addItemsToList";
|
||||
dataSend = {
|
||||
_token : $('#_tokenRes').val(),
|
||||
oeuvres : $('#my_researches').val()};
|
||||
$.post(url,
|
||||
dataSend,
|
||||
function( data ) {
|
||||
;
|
||||
}, "json")
|
||||
.done(function() {
|
||||
$('#oeuvreRes').empty();
|
||||
})
|
||||
.fail(function() {
|
||||
$("#oeuvreRes").append('<div class="alert alert-danger">'
|
||||
+'<strong>Oouups!</strong> Il y a un problème.<br><br>'
|
||||
+'<ul>'
|
||||
+'<li>Erreur lors de l\'ajout dans ma liste d\'oeuvre</li>'
|
||||
+'</ul>'
|
||||
+'</div>'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Afficher résultat de recherche d'oeuvre
|
||||
$('#search_button, #previous, #next').click(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Disable oeuvres already taken
|
||||
alreadySelected = $('.option_selected').map(function(){
|
||||
return parseInt($(this).val());
|
||||
}).get();
|
||||
|
||||
if(this.id == $('#next').attr('id') && $("#next").parent().hasClass('disabled') || this.id == $('#previous').attr('id') && $("#previous").parent().hasClass('disabled'))
|
||||
return 0;
|
||||
if (this.id == $('#next').attr('id')) {
|
||||
str = $("#next").attr('href');
|
||||
url = "/search?page="+/([0-9]+)/.exec(/page=([0-9]+)/.exec(str)[0])[0];
|
||||
}else if (this.id == $('#previous').attr('id')) {
|
||||
str = $("#previous").attr('href');
|
||||
url = "/search?page="+/([0-9]+)/.exec(/page=([0-9]+)/.exec(str)[0])[0];
|
||||
}else {
|
||||
url = "/search";
|
||||
}
|
||||
|
||||
$('#oeuvreRes').empty();
|
||||
dataSend = {
|
||||
_token : $('#_tokenRes').val(),
|
||||
auteur: $('#auteur').val(),
|
||||
designation: $('#designation').val(),
|
||||
matiere: $('#matiere').val(),
|
||||
domaine: $('#domaine').val(),
|
||||
technique: $('#technique').val(),
|
||||
debut: $('#debut').val(),
|
||||
fin: $('#fin').val()
|
||||
};
|
||||
|
||||
$.post(url,
|
||||
dataSend,
|
||||
function( data ) {
|
||||
if (data.data.length == 0 )
|
||||
$("#oeuvreRes").append("Aucune Oeuvre Trouvé..");
|
||||
else {
|
||||
$("#oeuvreRes").append('<select multiple="multiple" id="my_researches" class="image-picker show-html">');
|
||||
data.data.forEach( function(el) {
|
||||
|
||||
if($.inArray(el.id, alreadySelected) != -1){
|
||||
$('#my_researches').append('<option disabled="disabled" data-img-src="http://www.augustins.org/documents/10180/156407/' + el.urlPhoto + '" value="'+ el.id + '"></option>');
|
||||
} else {
|
||||
$('#my_researches').append('<option data-img-src="http://www.augustins.org/documents/10180/156407/' + el.urlPhoto + '" value="'+ el.id + '"></option>');
|
||||
}
|
||||
$("select").imagepicker();
|
||||
});
|
||||
}
|
||||
if(data.prev_page_url == null) {
|
||||
$("#previous").parent().addClass('disabled');
|
||||
}else {
|
||||
$("#previous").attr('href', data.prev_page_url);
|
||||
$("#previous").parent().removeClass('disabled');
|
||||
}
|
||||
if(data.next_page_url == null) {
|
||||
$("#next").parent().addClass('disabled');
|
||||
}else {
|
||||
$("#next").attr('href', data.next_page_url);
|
||||
$("#next").parent().removeClass('disabled');
|
||||
}
|
||||
}, "json" )
|
||||
.fail(function() {
|
||||
$("#oeuvreRes").append('<div class="alert alert-danger">'
|
||||
+'<strong>Oouups!</strong> Il y a un problème.<br><br>'
|
||||
+'<ul>'
|
||||
+'<li>Erreur lors de la récupération</li>'
|
||||
+'</ul>'
|
||||
+'</div>'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// Mettre à jour les jeux associés à la liste d'oeuvre
|
||||
$('.checkbox').click(function(event) {
|
||||
|
||||
// Recuperation des données necessaire au traitement
|
||||
var searchIDs = $("input#idGame").map(function(){
|
||||
return $(this).val();
|
||||
}).get();
|
||||
|
||||
var searchValues = $(".checkboxGame").map(function(){
|
||||
return $(this).is(":checked");
|
||||
}).get();
|
||||
|
||||
r = [];
|
||||
for (i = 0; i < searchIDs.length; i++) {
|
||||
r[searchIDs[i]] = searchValues[i];
|
||||
}
|
||||
|
||||
dataSend = { _token : $('#_tokenRes').val(), data: r };
|
||||
$.post('updateAssoGames', dataSend, function() {
|
||||
// Nada
|
||||
}, "json" )
|
||||
|
||||
.fail(function() {
|
||||
// Nada
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// Mettre à jour l'état des liste d'oeuvres
|
||||
$('.checkboxSession').click(function(event) {
|
||||
|
||||
el = $(this).attr('id');
|
||||
valueCheckbox = $(this).is(":checked");
|
||||
|
||||
$(".checkboxSession").map(function(){
|
||||
if (el != $(this).attr('id'))
|
||||
$(this).attr("checked", false);
|
||||
});
|
||||
|
||||
dataSend = { _token : $('#_tokenRes').val(), idListeOeuvre: el, value: valueCheckbox};
|
||||
$.post('updateSessionState', dataSend, function() {
|
||||
// Nada
|
||||
}, "json" )
|
||||
|
||||
.fail(function() {
|
||||
// Nada
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//swicth onglets de bg ma selection /ajouter
|
||||
|
||||
$('#liSelection').click(function() {
|
||||
showSelection();
|
||||
});
|
||||
|
||||
$('#liAddImages').click(function() {
|
||||
showAddPicture();
|
||||
});
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
1
SRC/public/js/classList.min.js
vendored
1
SRC/public/js/classList.min.js
vendored
@ -1 +0,0 @@
|
||||
"document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var a=document.createElement("_");if(a.classList.add("c1","c2"),!a.classList.contains("c2")){var b=function(a){var b=DOMTokenList.prototype[a];DOMTokenList.prototype[a]=function(a){var c,d=arguments.length;for(c=0;d>c;c++)a=arguments[c],b.call(this,a)}};b("add"),b("remove")}if(a.classList.toggle("c3",!1),a.classList.contains("c3")){var c=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(a,b){return 1 in arguments&&!this.contains(a)==!b?b:c.call(this,a)}}a=null}():!function(a){"use strict";if("Element"in a){var b="classList",c="prototype",d=a.Element[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++c<d);e&&this._updateClassName()},k.remove=function(){var a,b,c=arguments,d=0,e=c.length,f=!1;do for(a=c[d]+"",b=i(this,a);-1!==b;)this.splice(b,1),f=!0,b=i(this,a);while(++d<e);f&&this._updateClassName()},k.toggle=function(a,b){a+="";var c=this.contains(a),d=c?b!==!0&&"remove":b!==!1&&"add";return d&&this[d](a),b===!0||b===!1?b:!c},k.toString=function(){return this.join(" ")},e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){-2146823252===n.number&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}}(self));
|
@ -1,3 +0,0 @@
|
||||
function hideIcon(self) {
|
||||
self.style.backgroundImage = 'none';
|
||||
}
|
1
SRC/public/js/phaser.map
Normal file
1
SRC/public/js/phaser.map
Normal file
File diff suppressed because one or more lines are too long
27
SRC/public/js/phaser.min.js
vendored
Normal file
27
SRC/public/js/phaser.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,19 +0,0 @@
|
||||
// fonction qui recherche le referent donnee en parametre
|
||||
function rechercherReferent()
|
||||
{
|
||||
// on recupere le mot cle rentrer dans le champs de recherche
|
||||
var motCle = document.getElementById("searchfield").value;
|
||||
|
||||
//boucle sur chaque item
|
||||
var list = document.getElementsByClassName("item");
|
||||
|
||||
for (var i = 0; i < list.length; i++)
|
||||
{
|
||||
referent = list[i].getElementsByClassName('nomRef')[0].innerHTML; //recupere le nom du referent referent
|
||||
if (referent.indexOf(motCle) > -1) //on compare si la recherche correspond au nom
|
||||
{
|
||||
//on remplace la classe
|
||||
list[i].className = "item active";
|
||||
}
|
||||
}
|
||||
}
|
492
SRC/public/js/responsivevoice.js
Normal file
492
SRC/public/js/responsivevoice.js
Normal file
@ -0,0 +1,492 @@
|
||||
var ResponsiveVoice = function(){
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
// Ourn own collection of voices
|
||||
var responsivevoices = [
|
||||
{name: 'UK English Female', voiceIDs: [3,5,1,6,7,8] },
|
||||
{name: 'UK English Male', voiceIDs: [0,4,2,6,7,8] },
|
||||
{name: 'US English Female', voiceIDs: [39,40,41,42,43,44] },
|
||||
{name: 'Spanish Female', voiceIDs: [19,16,17,18,20,15] },
|
||||
{name: 'French Female', voiceIDs: [21,22,23,26] },
|
||||
{name: 'Deutsch Female', voiceIDs: [27,28,29,30,31,32] },
|
||||
{name: 'Italian Female', voiceIDs: [33,34,35,36,37,38] },
|
||||
{name: 'Hungarian Female', voiceIDs: [9,10,11] },
|
||||
{name: 'Serbian Male', voiceIDs: [12] },
|
||||
{name: 'Croatian Male', voiceIDs: [13] },
|
||||
{name: 'Bosnian Male', voiceIDs: [14] },
|
||||
{name: 'Fallback UK Female', voiceIDs: [8] }
|
||||
|
||||
];
|
||||
|
||||
//All voices available on every system and device
|
||||
var voicecollection = [
|
||||
{name: 'Google UK English Male'}, //0 male uk android/chrome
|
||||
{name: 'Agnes'}, //1 female us safari mac
|
||||
{name: 'Daniel Compact'}, //2 male us safari mac
|
||||
{name: 'Google UK English Female'}, //3 female uk android/chrome
|
||||
{name: 'en-GB', rate: 0.5, pitch: 1}, //4 male uk IOS
|
||||
{name: 'en-AU', rate: 0.5, pitch: 1}, //5 female english IOS
|
||||
{name: 'inglés Reino Unido'}, //6 spanish english android
|
||||
{name: 'English United Kingdom'}, //7 english english android
|
||||
{name: 'Fallback en-GB Female', lang: 'en-GB', fallbackvoice: true}, //8 fallback english female
|
||||
{name: 'Eszter Compact'}, //9 Hungarian mac
|
||||
{name: 'hu-HU', rate: 0.4}, //10 Hungarian iOS
|
||||
{name: 'Fallback Hungarian', lang: 'hu', fallbackvoice:true}, //11 Hungarian fallback
|
||||
{name: 'Fallback Serbian', lang: 'sr', fallbackvoice:true}, //12 Serbian fallback
|
||||
{name: 'Fallback Croatian', lang: 'hr', fallbackvoice:true}, //13 Croatian fallback
|
||||
{name: 'Fallback Bosnian', lang: 'bs', fallbackvoice:true}, //14 Bosnian fallback
|
||||
|
||||
{name: 'Fallback Spanish', lang: 'es', fallbackvoice:true}, //15 Spanish fallback
|
||||
{name: 'Spanish Spain'}, //16 female es android/chrome
|
||||
{name: 'español España'}, //17 female es android/chrome
|
||||
{name: 'Diego Compact', rate: 0.3}, //18 male es mac
|
||||
{name: 'Google Español'}, //19 male es chrome
|
||||
{name: 'es-ES', rate: 0.3}, //20 male es iOS
|
||||
|
||||
{name: 'Google Français'}, //21 FR chrome
|
||||
{name: 'French France'}, //22 android/chrome
|
||||
{name: 'francés Francia'}, //23 android/chrome
|
||||
{name: 'Virginie Compact', rate: 0.5}, //24 mac
|
||||
{name: 'fr-FR', rate: 0.5}, //25 iOS
|
||||
{name: 'Fallback French', lang: 'fr', fallbackvoice:true}, //26 fallback
|
||||
|
||||
{name: 'Google Deutsch'}, //27 DE chrome
|
||||
{name: 'German Germany'}, //28 android/chrome
|
||||
{name: 'alemán Alemania'}, //29 android/chrome
|
||||
{name: 'Yannick Compact', rate: 0.5}, //30 mac
|
||||
{name: 'de-DE', rate: 0.5}, //31 iOS
|
||||
{name: 'Fallback Deutsch', lang: 'de', fallbackvoice:true}, //32 fallback
|
||||
|
||||
{name: 'Google Italiano'}, //33 DE chrome
|
||||
{name: 'Italian Italy'}, //34 android/chrome
|
||||
{name: 'italiano Italia'}, //35 android/chrome
|
||||
{name: 'Paolo Compact', rate: 0.5}, //36 mac
|
||||
{name: 'it-IT', rate: 0.5}, //37 iOS
|
||||
{name: 'Fallback Italian', lang: 'it', fallbackvoice:true}, //38 fallback
|
||||
|
||||
{name: 'Google US English'}, //39 DE chrome
|
||||
{name: 'English United States'}, //40 android/chrome
|
||||
{name: 'inglés Estados Unidos'}, //41 android/chrome
|
||||
{name: 'Vicki'}, //42 mac
|
||||
{name: 'en-US', rate: 0.5}, //43 iOS
|
||||
{name: 'Fallback English', lang: 'en-US', fallbackvoice:true}, //44 fallback
|
||||
|
||||
];
|
||||
|
||||
var systemvoices;
|
||||
|
||||
var CHARACTER_LIMIT = 100;
|
||||
var VOICESUPPORT_ATTEMPTLIMIT = 5;
|
||||
var voicesupport_attempts = 0;
|
||||
var fallbackMode = false;
|
||||
|
||||
this.fallback_playing = false;
|
||||
this.fallback_parts = null;
|
||||
this.fallback_part_index = 0;
|
||||
this.fallback_audio = null;
|
||||
|
||||
//Wait until system voices are ready and trigger the event OnVoiceReady
|
||||
if (typeof speechSynthesis != 'undefined') {
|
||||
speechSynthesis.onvoiceschanged = function() {
|
||||
|
||||
systemvoices = window.speechSynthesis.getVoices();
|
||||
|
||||
if (self.OnVoiceReady!=null) {
|
||||
self.OnVoiceReady.call();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.default_rv = responsivevoices[0];
|
||||
|
||||
|
||||
|
||||
this.OnVoiceReady = null;
|
||||
|
||||
|
||||
//We should use jQuery if it's available
|
||||
if (typeof $ === 'undefined') {
|
||||
document.addEventListener('DOMContentLoaded',function(){
|
||||
init();
|
||||
});
|
||||
}else{
|
||||
|
||||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
|
||||
if (typeof speechSynthesis === 'undefined') {
|
||||
|
||||
enableFallbackMode();
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
//Waiting a few ms before calling getVoices() fixes some issues with safari on IOS as well as Chrome
|
||||
setTimeout(function(){
|
||||
var gsvinterval = setInterval(function() {
|
||||
|
||||
var v = window.speechSynthesis.getVoices();
|
||||
|
||||
if (v.length==0 && (systemvoices==null || systemvoices.length==0)) {
|
||||
console.log('Voice support NOT ready');
|
||||
|
||||
voicesupport_attempts++;
|
||||
if (voicesupport_attempts > VOICESUPPORT_ATTEMPTLIMIT) {
|
||||
//We don't support voices. Using fallback
|
||||
|
||||
clearInterval(gsvinterval);
|
||||
|
||||
enableFallbackMode();
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
console.log('Voice support ready');
|
||||
|
||||
clearInterval(gsvinterval);
|
||||
|
||||
systemvoices = v;
|
||||
|
||||
mapRVs();
|
||||
|
||||
if (self.OnVoiceReady!=null)
|
||||
self.OnVoiceReady.call();
|
||||
|
||||
}
|
||||
|
||||
},100);
|
||||
},100);
|
||||
}
|
||||
}
|
||||
|
||||
function enableFallbackMode() {
|
||||
|
||||
fallbackMode = true;
|
||||
console.log('Voice not supported. Using fallback mode');
|
||||
|
||||
mapRVs();
|
||||
|
||||
if (self.OnVoiceReady!=null)
|
||||
self.OnVoiceReady.call();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.getVoices = function() {
|
||||
|
||||
//Create voices array
|
||||
|
||||
var v = [];
|
||||
|
||||
for (var i=0; i<responsivevoices.length; i++) {
|
||||
v.push( { name: responsivevoices[i].name });
|
||||
}
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.speak = function(text, voicename) {
|
||||
|
||||
|
||||
//Support for multipart text (there is a limit on characters)
|
||||
var multipartText = [];
|
||||
|
||||
if (text.length>CHARACTER_LIMIT) {
|
||||
|
||||
var tmptxt = text;
|
||||
|
||||
while(tmptxt.length>CHARACTER_LIMIT) {
|
||||
|
||||
//Split by common phrase delimiters
|
||||
var p = tmptxt.search(/[:!?.;]+/);
|
||||
var part = '';
|
||||
|
||||
//Coludn't split by priority characters, try commas
|
||||
if (p==-1 || p>=CHARACTER_LIMIT ) {
|
||||
p = tmptxt.search(/[,]+/);
|
||||
}
|
||||
|
||||
//Couldn't split by normal characters, then we use spaces
|
||||
if (p==-1 || p>=CHARACTER_LIMIT) {
|
||||
|
||||
var words = tmptxt.split(' ');
|
||||
|
||||
for (var i=0; i<words.length; i++) {
|
||||
|
||||
if (part.length + words[i].length +1 >CHARACTER_LIMIT)
|
||||
break;
|
||||
|
||||
part += (i!=0?' ':'') + words[i];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
part = tmptxt.substr(0, p+1);
|
||||
|
||||
}
|
||||
|
||||
tmptxt = tmptxt.substr(part.length, tmptxt.length-part.length);
|
||||
|
||||
multipartText.push(part);
|
||||
//console.log(part.length + " - " + part);
|
||||
|
||||
}
|
||||
|
||||
//Add the remaining text
|
||||
if (tmptxt.length>0) {
|
||||
multipartText.push(tmptxt);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
//Small text
|
||||
multipartText.push(text);
|
||||
}
|
||||
|
||||
|
||||
//Find system voice that matches voice name
|
||||
var rv;
|
||||
|
||||
if (voicename==null) {
|
||||
rv = self.default_rv;
|
||||
}else{
|
||||
rv = getResponsiveVoice(voicename);
|
||||
}
|
||||
|
||||
var profile = {};
|
||||
|
||||
|
||||
|
||||
|
||||
//Map was done so no need to look for the mapped voice
|
||||
if (rv.mappedProfile!=null) {
|
||||
|
||||
profile = rv.mappedProfile;
|
||||
|
||||
}else{
|
||||
|
||||
profile.systemvoice = getMatchedVoice(rv);
|
||||
profile.collectionvoice = {};
|
||||
|
||||
if (profile.systemvoice==null) {
|
||||
console.log('ERROR: No voice found for: ' + voicename);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (profile.collectionvoice.fallbackvoice==true) {
|
||||
fallbackMode = true;
|
||||
self.fallback_parts = [];
|
||||
}else{
|
||||
fallbackMode = false;
|
||||
}
|
||||
|
||||
|
||||
//Play multipart text
|
||||
for (var i=0; i<multipartText.length; i++) {
|
||||
|
||||
if (!fallbackMode) {
|
||||
//Use SpeechSynthesis
|
||||
|
||||
//Create msg object
|
||||
var msg = new SpeechSynthesisUtterance();
|
||||
msg.voice = profile.systemvoice;
|
||||
msg.voiceURI = profile.systemvoice.voiceURI;
|
||||
msg.volume = profile.collectionvoice.volume || profile.systemvoice.volume || 1; // 0 to 1
|
||||
msg.rate = profile.collectionvoice.rate || profile.systemvoice.rate || 1; // 0.1 to 10
|
||||
msg.pitch = profile.collectionvoice.pitch || profile.systemvoice.pitch || 1; //0 to 2*/
|
||||
msg.text = multipartText[i];
|
||||
msg.lang = profile.collectionvoice.lang || profile.systemvoice.lang;
|
||||
msg.onend = self.OnFinishedPlaying;
|
||||
msg.onerror = function(e){
|
||||
console.log('Error');
|
||||
console.log(e);
|
||||
};
|
||||
//console.log(msg);
|
||||
|
||||
speechSynthesis.speak(msg);
|
||||
|
||||
}else{
|
||||
|
||||
var url = 'http://www.corsproxy.com/translate.google.com/translate_tts?ie=UTF-8&q=' + multipartText[i] + '&tl=' + profile.collectionvoice.lang || profile.systemvoice.lang || 'en-US';
|
||||
|
||||
var audio = new Audio(url);
|
||||
audio.playbackRate = 1;
|
||||
audio.preload = 'auto';
|
||||
audio.volume = profile.collectionvoice.volume || profile.systemvoice.volume || 1; // 0 to 1;
|
||||
self.fallback_parts.push(audio);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (fallbackMode)
|
||||
self.fallback_startPlaying();
|
||||
|
||||
}
|
||||
|
||||
this.fallback_startPlaying = function() {
|
||||
|
||||
//console.log('start playing');
|
||||
|
||||
self.fallback_part_index = 0;
|
||||
|
||||
//console.log(self.fallback_parts);
|
||||
|
||||
self.fallback_finishedplaying();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
this.fallback_finishedplaying = function(e) {
|
||||
//console.log('chunk ended');
|
||||
self.fallback_audio = self.fallback_parts[self.fallback_part_index];
|
||||
//console.log(self.fallback_audio);
|
||||
|
||||
|
||||
|
||||
//self.fallback_audio.addEventListener('error', function(e){ console.log('error'); console.log(e)});
|
||||
//self.fallback_audio.addEventListener('progress', function(e){ console.log('progress'); this.play();});
|
||||
//self.fallback_audio.addEventListener('loadstart', function(e){ console.log('loadstart'); console.log(e)});
|
||||
//self.fallback_audio.load();
|
||||
self.fallback_audio.play();
|
||||
|
||||
//audio.addEventListener('play', utterance.onstart);
|
||||
|
||||
self.fallback_part_index ++;
|
||||
|
||||
if (self.fallback_part_index < self.fallback_parts.length) {
|
||||
|
||||
self.fallback_audio.addEventListener('ended', self.fallback_finishedplaying);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.cancel = function() {
|
||||
|
||||
if (fallbackMode)
|
||||
self.fallback_audio.pause();
|
||||
else
|
||||
speechSynthesis.cancel();
|
||||
}
|
||||
|
||||
|
||||
this.voiceSupport = function() {
|
||||
|
||||
return ('speechSynthesis' in window);
|
||||
|
||||
}
|
||||
|
||||
this.OnFinishedPlaying = function(event) {
|
||||
|
||||
}
|
||||
|
||||
//Set default voice to use when no voice name is supplied to speak()
|
||||
this.setDefaultVoice = function(voicename) {
|
||||
|
||||
var vr = getResponsiveVoice(voicename);
|
||||
|
||||
if (vr!=null) {
|
||||
self.default_vr = vr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Map responsivevoices to system voices
|
||||
function mapRVs() {
|
||||
|
||||
for (var i=0; i<responsivevoices.length; i++) {
|
||||
|
||||
var rv = responsivevoices[i];
|
||||
|
||||
for (var j=0; j<rv.voiceIDs.length; j++) {
|
||||
|
||||
var vcoll = voicecollection[rv.voiceIDs[j]];
|
||||
|
||||
if (vcoll.fallbackvoice != true) { // vcoll.fallbackvoice would be null instead of false
|
||||
|
||||
// Look on system voices
|
||||
var v = getSystemVoice(vcoll.name);
|
||||
if (v!=null) {
|
||||
rv.mappedProfile = {
|
||||
systemvoice: v,
|
||||
collectionvoice: vcoll
|
||||
};
|
||||
console.log("Mapped " + rv.name + " to " + v.name);
|
||||
break;
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
//Pick the fallback voice
|
||||
rv.mappedProfile = {
|
||||
systemvoice: {},
|
||||
collectionvoice: vcoll
|
||||
};
|
||||
console.log("Mapped " + rv.name + " to " + vcoll.lang + " fallback voice");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Look for the voice in the system that matches the one in our collection
|
||||
function getMatchedVoice(rv) {
|
||||
|
||||
for (var i=0; i<rv.voiceIDs.length; i++) {
|
||||
var v = getSystemVoice(voicecollection[rv.voiceIDs[i]].name);
|
||||
if (v!=null)
|
||||
return v;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
function getSystemVoice(name) {
|
||||
|
||||
if (typeof systemvoices === 'undefined') return null;
|
||||
|
||||
for (var i=0; i<systemvoices.length; i++) {
|
||||
if (systemvoices[i].name == name)
|
||||
return systemvoices[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
function getResponsiveVoice(name) {
|
||||
|
||||
for (var i=0; i<responsivevoices.length; i++) {
|
||||
if (responsivevoices[i].name == name) {
|
||||
return responsivevoices[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var responsiveVoice = new ResponsiveVoice();
|
Reference in New Issue
Block a user