From f2e8c788ea05f2f6ba7cad6a21ee89e0da352c73 Mon Sep 17 00:00:00 2001 From: Andreas Hagsten Date: Thu, 11 Apr 2019 20:03:35 +0200 Subject: [PATCH] Small fixes --- dist/talkify.js | 49 +++++++++++++++++---- dist/talkify.min.js | 2 +- package.json | 2 +- src/talkify-controlcenter.js | 6 +-- src/talkify-html5-speechsynthesis-player.js | 32 +++++++++++++- src/talkify-messagehub.js | 7 ++- src/talkify-playlist.js | 4 +- 7 files changed, 84 insertions(+), 18 deletions(-) diff --git a/dist/talkify.js b/dist/talkify.js index 921e99f..066055a 100644 --- a/dist/talkify.js +++ b/dist/talkify.js @@ -165,10 +165,10 @@ talkify.playbar = function (parent, correlationId) { ' ' + ' ' + '
  • ' + - ' ' + - ' ' + '
  • ' + @@ -363,7 +363,7 @@ talkify.playbar = function (parent, correlationId) { } function isTalkifyHostedVoice(voice) { - return voice && voice.isTalkify; + return voice && voice.constructor.name !== "SpeechSynthesisVoice";//voice.isTalkify; } function featureToggle(voice) { @@ -571,6 +571,8 @@ talkify.Html5Player = function () { currentUtterance: null }; + var timeupdater; + var me = this; this.playbar = { @@ -607,6 +609,10 @@ talkify.Html5Player = function () { talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.pause"); talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.volume"); talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.rate"); + + if (timeupdater) { + clearInterval(timeupdater); + } } }; @@ -652,6 +658,10 @@ talkify.Html5Player = function () { talkify.messageHub.subscribe("html5player", me.correlationId + ".controlcenter.request.rate", function (rate) { me.settings.rate = rate / 5; }); function playCurrentContext() { + if (timeupdater) { + clearInterval(timeupdater); + } + var item = me.currentContext.item; var chuncks = chunckText(item.text); @@ -677,6 +687,10 @@ talkify.Html5Player = function () { me.currentContext.utterances[me.currentContext.utterances.length - 1].onend = function (e) { talkify.messageHub.publish(me.correlationId + ".player.html5.utterancecomplete", item); + if (timeupdater) { + clearInterval(timeupdater); + } + if (!me.currentContext.currentUtterance) { return; } @@ -696,6 +710,14 @@ talkify.Html5Player = function () { me.currentContext.currentUtterance = e.utterance; talkify.messageHub.publish(me.correlationId + ".player.html5.loaded", me.currentContext.item); talkify.messageHub.publish(me.correlationId + ".player.html5.play", { item: me.currentContext.item, positions: [], currentTime: 0 }); + + if (timeupdater) { + clearInterval(timeupdater); + } + + timeupdater = setInterval(function () { + talkify.messageHub.publish(me.correlationId + ".player.html5.timeupdated", (wordIndex + 1) / words.length); + }, 100); }; } else { u.onstart = function (e) { @@ -704,6 +726,10 @@ talkify.Html5Player = function () { } u.onpause = function () { + if (timeupdater) { + clearInterval(timeupdater); + } + talkify.messageHub.publish(me.correlationId + ".player.html5.pause"); }; @@ -714,8 +740,6 @@ talkify.Html5Player = function () { return; } - talkify.messageHub.publish(me.correlationId + ".player.html5.timeupdated", (wordIndex + 1) / words.length); - if (!me.settings.useTextHighlight || !u.voice.localService) { return; } @@ -899,6 +923,10 @@ talkify.Html5Player = function () { talkify.messageHub.publish(me.correlationId + ".player.html5.pause"); window.speechSynthesis.cancel(); + if (timeupdater) { + clearInterval(timeupdater); + } + if (me.currentContext.utterances.indexOf(me.currentContext.currentUtterance) < me.currentContext.utterances.length - 1) { console.log('Not the last, finishing anyway...'); talkify.messageHub.publish(me.correlationId + ".player.html5.utterancecomplete", me.currentContext.item); @@ -972,6 +1000,11 @@ talkify.messageHub = function () { var candidates = []; Object.keys(subscribers).forEach(function (subscriberKey) { + if(subscriberKey === '*'){ + candidates.push(subscriberKey); + return; + } + var s = subscriberKey.split('.'); if (s.length != topics.length) { @@ -1009,7 +1042,7 @@ talkify.messageHub = function () { talkify.log("Calling subscriber", subscriber, c, message); } - subscriber.fn(message); + subscriber.fn(message, topic); }); }) @@ -1815,8 +1848,8 @@ talkify.playlist = function () { }); function onComplete(refLang) { - playlist.referenceLanguage = refLang; - player.withReferenceLanguage(refLang); + playlist.referenceLanguage = { Culture: refLang.Cultures[0], Language: refLang.Language }; + player.withReferenceLanguage(playlist.referenceLanguage); playItem(playlist.queue[0]); } diff --git a/dist/talkify.min.js b/dist/talkify.min.js index 697807b..7cb114b 100644 --- a/dist/talkify.min.js +++ b/dist/talkify.min.js @@ -1 +1 @@ -(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i=300)&&j.status!==304;h.done(a,j.responseText,j)}};j.send(k);return h}function h(a){return function(b,c,d){return g(a,b,c,d)}}var i={Promise:b,join:c,chain:d,ajax:g,get:h("GET"),post:h("POST"),put:h("PUT"),del:h("DELETE"),ENOXHR:1,ETIMEOUT:2,ajaxTimeout:0};if(typeof define==="function"&&define.amd)define(function(){return i});else a.promise=i})(this)},{}],3:[function(require,module,exports){talkify=talkify||{};talkify.http=function ajax(){var get=function(url){var call=new promise.Promise;var keypart=(url.indexOf("?")!==-1?"&key=":"?key=")+talkify.config.remoteService.apiKey;promise.get(window.talkify.config.remoteService.host+url+keypart).then(function(error,data){try{var jsonObj=JSON.parse(data);call.done(error,jsonObj)}catch(e){call.done(e,data)}});return call};return{get:get}}()},{}],4:[function(require,module,exports){talkify=talkify||{};talkify.config={debug:false,ui:{audioControls:{enabled:false,container:document.body}},formReader:{voice:null,rate:0,remoteService:true,requiredText:"This field is required",valueText:"You have entered {value} as: {label}.",selectedText:"You have selected {label}.",notSelectedText:"{label} is not selected."},remoteService:{active:true,host:"https://talkify.net",apiKey:"",speechBaseUrl:"/api/speech/v1",languageBaseUrl:"/api/language/v1"},keyboardCommands:{enabled:false,commands:{playPause:32,next:39,previous:37}},voiceCommands:{enabled:false,keyboardActivation:{enabled:true,key:77},commands:{playPause:["play","pause","stop","start"],next:["play next","next"],previous:["play previous","previous","back","go back"]}}}},{}],5:[function(require,module,exports){talkify=talkify||{};talkify.playbar=function(parent,correlationId){var settings={parentElement:parent||talkify.config.ui.audioControls.container||document.body};var playElement,pauseElement,rateElement,volumeElement,progressElement,voiceElement,currentTimeElement,textHighlightingElement,wrapper;var attachElement,detatchedElement,dragArea;function hide(element){if(element.classList.contains("talkify-hidden")){return}element.className+=" talkify-hidden"}function show(element){element.className=element.className.replace("talkify-hidden","")}function play(){hide(playElement);show(pauseElement)}function pause(){hide(pauseElement);show(playElement)}function addClass(element,c){if(element.classList.contains(c)){return}element.className+=" "+c}function removeClass(element,c){element.className=element.className.replace(c,"")}function createElement(type,classes){var element=document.createElement(type);element.className=classes;return element}function render(){var existingControl=document.getElementsByClassName("talkify-control-center")[0];if(existingControl){existingControl.parentNode.removeChild(existingControl)}wrapper=createElement("div","talkify-control-center attached");wrapper.innerHTML=" "+'
    '+" Voice: "+"
    ";playElement=wrapper.getElementsByClassName("talkify-play-button")[0];pauseElement=wrapper.getElementsByClassName("talkify-pause-button")[0];rateElement=wrapper.querySelector(".rate-button input[type=range]");volumeElement=wrapper.querySelector(".volume-button input[type=range]");progressElement=wrapper.getElementsByTagName("progress")[0];textHighlightingElement=wrapper.getElementsByClassName("talkify-cc-button")[0];currentTimeElement=wrapper.getElementsByClassName("talkify-time-element")[0];attachElement=wrapper.getElementsByClassName("talkify-detatched")[0];detatchedElement=wrapper.getElementsByClassName("talkify-attached")[0];voiceWrapperElement=wrapper.querySelector(".talkify-voice-selector select");dragArea=wrapper.getElementsByClassName("drag-area")[0];settings.parentElement.appendChild(wrapper);pause()}function setupBindings(){var controlCenter=document.getElementsByClassName("talkify-control-center")[0];playElement.addEventListener("click",function(){if(playElement.classList.contains("talkify-disabled")){return}talkify.messageHub.publish(correlationId+".controlcenter.request.play")});pauseElement.addEventListener("click",function(){if(pauseElement.classList.contains("talkify-disabled")){return}talkify.messageHub.publish(correlationId+".controlcenter.request.pause")});rateElement.addEventListener("change",function(){talkify.messageHub.publish(correlationId+".controlcenter.request.rate",parseInt(this.value))});volumeElement.addEventListener("change",function(e){talkify.messageHub.publish(correlationId+".controlcenter.request.volume",parseInt(this.value))});textHighlightingElement.addEventListener("click",function(e){if(textHighlightingElement.classList.contains("talkify-disabled")){removeClass(textHighlightingElement,"talkify-disabled");talkify.messageHub.publish(correlationId+".controlcenter.texthighlightoggled",true)}else{addClass(textHighlightingElement,"talkify-disabled");talkify.messageHub.publish(correlationId+".controlcenter.texthighlightoggled",false)}});progressElement.addEventListener("click",function(e){var clickedValue=e.offsetX*this.max/this.offsetWidth;if(clickedValue>1){clickedValue=1}if(clickedValue<0){clickedValue=0}talkify.messageHub.publish(correlationId+".controlcenter.request.seek",clickedValue)});attachElement.addEventListener("click",function(){addClass(controlCenter,"attached")});detatchedElement.addEventListener("click",function(){removeClass(controlCenter,"attached")});dragArea.addEventListener("mousedown",onMouseDown);document.addEventListener("mouseup",onMouseUp);function onMouseUp(e){document.removeEventListener("mousemove",onMouseMove)}function onMouseDown(e){document.addEventListener("mousemove",onMouseMove)}function onMouseMove(e){controlCenter.style.top=e.clientY+"px";controlCenter.style.left=e.clientX+"px"}}function initialize(){render();setupBindings();talkify.messageHub.subscribe("controlcenter",[correlationId+".player.*.pause",correlationId+".player.*.disposed"],pause);talkify.messageHub.subscribe("controlcenter",[correlationId+".player.*.play",correlationId+".player.*.resume"],play);talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.disposed",dispose);talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.loaded",function(){removeClass(pauseElement,"talkify-disabled");removeClass(playElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.texthighlight.enabled",function(){removeClass(textHighlightingElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.texthighlight.disabled",function(){addClass(textHighlightingElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.ratechanged",function(rate){rateElement.value=rate});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.voiceset",function(voice){featureToggle(voice);setVoiceName(voice)});talkify.messageHub.subscribe("controlcenter",correlationId+".player.tts.timeupdated",updateClock);talkify.messageHub.subscribe("controlcenter",correlationId+".player.html5.timeupdated",function(value){progressElement.setAttribute("value",value)})}function updateClock(timeInfo){var currentTime=timeInfo.currentTime;var duration=timeInfo.duration;progressElement.setAttribute("value",currentTime/duration);if(!currentTimeElement){return}var currentminutes=Math.floor(currentTime/60);var currentseconds=Math.round(currentTime)-currentminutes*60;var totalminutes=!!duration?Math.floor(duration/60):0;var totalseconds=!!duration?Math.round(duration)-totalminutes*60:0;currentTimeElement.textContent=currentminutes+":"+(currentseconds<10?"0"+currentseconds:currentseconds)+" / "+totalminutes+":"+(totalseconds<10?"0"+totalseconds:totalseconds)}function isTalkifyHostedVoice(voice){return voice&&voice.isTalkify}function featureToggle(voice){show(progressElement);show(textHighlightingElement);if(!voice){return}if(isTalkifyHostedVoice(voice)){return}hide(currentTimeElement);if(!voice.localService){hide(progressElement);hide(textHighlightingElement)}}function setVoiceName(voice){var voiceElement=document.querySelector(".talkify-voice-selector > span");if(!voice){voiceElement.textContent="Automatic voice detection";return}if(isTalkifyHostedVoice(voice)){voiceElement.textContent=voice.description;return}voiceElement.textContent=voice.name}function dispose(){var existingControl=document.getElementById("htmlPlaybar");if(existingControl){existingControl.parentNode.removeChild(existingControl)}talkify.messageHub.unsubscribe("controlcenter",[correlationId+".player.*.pause",correlationId+".player.*.disposed"]);talkify.messageHub.unsubscribe("controlcenter",[correlationId+".player.*.play",correlationId+".player.*.resume"]);talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.disposed");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.loaded");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.texthighlight.enabled");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.texthighlight.disabled");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.ratechanged");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.voiceset");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.tts.timeupdated");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.html5.timeupdated")}initialize();return{setMaxRate:function(value){rateElement.setAttribute("max",value);return this},setMinRate:function(value){rateElement.setAttribute("min",value);return this},dispose:dispose}}},{}],6:[function(require,module,exports){talkify=talkify||{};talkify.formReader=function(){var player;var timeout;function setupForm(formElement){var elements=formElement.elements;for(var i=0;i-1?70:language.indexOf("ko-")>-1?130:200;var chuncks=[];var sentences=text.split(/(\?|\.|。)+/g);var currentChunck="";sentences.forEach(function(sentence){if(sentence===""||sentence==="."||sentence==="。"||sentence==="?"){if(currentChunck){currentChunck+=sentence}return}if(currentChunck&¤tChunck.length+sentence.length>chunckSize){chuncks.push(currentChunck);currentChunck=""}if(sentence.length>chunckSize){var words=extractWords(sentence,language);words.forEach(function(word){if(currentChunck.length+word.length>chunckSize){chuncks.push(currentChunck);currentChunck=""}currentChunck+=word.trim()+" "});if(currentChunck.trim()){chuncks.push(currentChunck.trim()+".");currentChunck=""}return}currentChunck+=sentence});chuncks.push(currentChunck);return chuncks}function extractWords(text,language){var wordRegex=new RegExp(/[&\$\-|]|([("\-&])*(\b[^\s]+[.:,"-)!&?]*)/g);if(language){if(language.indexOf("zh-")>-1){return text.split(",")}if(language.indexOf("ko-")>-1){return text.split(".")}}var words=[];var m;while((m=wordRegex.exec(text))!==null){if(m.index===wordRegex.lastIndex){wordRegex.lastIndex++}words.push(m[0])}return words}function selectVoiceToPlay(voices){var matchingVoices=[];var voice=null;var language=me.settings.lockedLanguage||me.settings.referenceLanguage.Culture;for(var i=0;i-1}).forEach(function(subscriberKey){subscribers[subscriberKey]=subscribers[subscriberKey].filter(function(subscriber){return subscriber.key!==key})})}return{publish:publish,subscribe:subscribe,unsubscribe:unsubscribe}}()},{}],10:[function(require,module,exports){talkify=talkify||{};talkify.BasePlayer=function(_audiosource,_playbar){this.correlationId=talkify.generateGuid();this.audioSource=_audiosource;this.wordHighlighter=new talkify.wordHighlighter(this.correlationId);var me=this;this.settings={useTextHighlight:false,referenceLanguage:{Culture:"",Language:-1},lockedLanguage:null,rate:1,useControls:false};this.playbar=_playbar;this.forcedVoice=null;if(talkify.config.ui.audioControls.enabled){this.playbar.instance=talkify.playbar(null,this.correlationId)}talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.loaded",function(item){item.isLoading=false});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.ended",function(item){item.isPlaying=false});talkify.messageHub.subscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled",function(enabled){me.settings.useTextHighlight=enabled});talkify.messageHub.publish(this.correlationId+".player.*.ratechanged",me.settings.rate);this.withReferenceLanguage=function(refLang){this.settings.referenceLanguage=refLang;return this};this.enableTextHighlighting=function(){this.settings.useTextHighlight=true;talkify.messageHub.publish(this.correlationId+".player.*.texthighlight.enabled");return this};this.disableTextHighlighting=function(){this.settings.useTextHighlight=false;talkify.messageHub.publish(this.correlationId+".player.*.texthighlight.disabled");return this};this.setRate=function(r){this.settings.rate=r;talkify.messageHub.publish(this.correlationId+".player.*.ratechanged",r);return this};this.subscribeTo=function(subscriptions){talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.pause",subscriptions.onPause||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.resume",subscriptions.onResume||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.play",subscriptions.onPlay||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.loaded",subscriptions.onItemLoaded||function(){});talkify.messageHub.subscribe("core-player",[this.correlationId+".wordhighlighter.complete",this.correlationId+".player.html5.utterancecomplete"],subscriptions.onItemFinished||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.prepareplay",subscriptions.onBeforeItemPlaying||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled",subscriptions.onTextHighligtChanged||function(){});return this};this.playItem=function(item){if(item&&item.isPlaying){if(this.audioSource.paused()){this.audioSource.play()}else{this.audioSource.pause()}}talkify.messageHub.publish(this.correlationId+".player.*.prepareplay",item);item.isLoading=true;item.isPlaying=true;item.element.classList.add("playing");this.playAudio(item)};this.createItems=function(text){var safeMaxQuerystringLength=1e3;var items=[];if(text.length>safeMaxQuerystringLength){var f=text.substr(0,safeMaxQuerystringLength);items.push(template(f));items=items.concat(this.createItems(text.substr(safeMaxQuerystringLength,text.length-1)));return items}items.push(template(text));return items;function template(t){var element=document.createElement("span");var clone=element.cloneNode(true);return{text:t,preview:t.substr(0,40),element:element,originalElement:clone,isPlaying:false,isLoading:false}}};this.playText=function(text){if(!text){return}var items=this.createItems(text);var currentItem=0;talkify.messageHub.subscribe("core-player.playText",this.correlationId+".player.*.ended",function(){currentItem++;if(currentItem>=items.length){talkify.messageHub.unsubscribe("core.playText",this.correlationId+".player.*.ended");return}this.playItem(items[currentItem])});this.playItem(items[currentItem])};this.paused=function(){return this.audioSource.paused()};this.isPlaying=function(){return this.audioSource.isPlaying()};this.play=function(){this.audioSource.play()};this.pause=function(){this.audioSource.pause();var me=this;if(!me.audioSource.paused()&&me.audioSource.cancel){me.audioSource.cancel(true)}};this.dispose=function(){talkify.messageHub.publish(this.correlationId+".player.tts.disposed");this.audioSource.stop();this.audioSource.dispose();this.wordHighlighter.dispose();talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.loaded");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.ended");talkify.messageHub.unsubscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.pause");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.resume");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.play");talkify.messageHub.unsubscribe("core-player",[this.correlationId+".wordhighlighter.complete",this.correlationId+".player.html5.utterancecomplete"]);talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.prepareplay");talkify.messageHub.unsubscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled")};this.forceLanguage=function(culture){this.settings.lockedLanguage=culture;return this};this.forceVoice=function(voice){this.forcedVoice=voice!==undefined?voice:null;this.settings.lockedLanguage=voice&&(voice.lang||voice.culture)||this.settings.lockedLanguage;talkify.messageHub.publish(this.correlationId+".player.*.voiceset",voice);return this}}},{}],11:[function(require,module,exports){talkify=talkify||{};talkify.TtsPlayer=function(){if(!talkify.config.remoteService.active){throw"This player needs to communicate to a remote service. To enable this player please set flag talkify.config.remoteService.active to true."}var me=this;var audioElement,timeupdater;this.currentContext={item:null,positions:[]};this.playbar={instance:null};this.audioSource={play:function(){audioElement.play()},pause:function(){audioElement.pause()},isPlaying:function(){return audioElement.duration>0&&!audioElement.paused},paused:function(){return audioElement.paused},currentTime:function(){return audioElement.currentTime},stop:function(){audioElement.pause();audioElement.currentTime=0},dispose:function(){if(timeupdater){clearInterval(timeupdater)}var existingElement=document.getElementById("talkify-audio");if(existingElement){existingElement.outerHTML=""}talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.play");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.pause");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.seek");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.volume");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.rate")}};talkify.BasePlayer.call(this,this.audioSource,this.playbar);function setupBindings(){audioElement.addEventListener("pause",onPause);audioElement.addEventListener("play",onPlay);audioElement.addEventListener("seeked",onSeek)}function onSeek(){talkify.messageHub.publish(me.correlationId+".player.tts.seeked",this.currentTime);if(me.audioSource.paused()&&me.audioSource.currentTime()>.1){me.audioSource.play()}}function onPause(){if(timeupdater){clearInterval(timeupdater)}talkify.messageHub.publish(me.correlationId+".player.tts.pause")}function onPlay(){if(timeupdater){clearInterval(timeupdater)}timeupdater=setInterval(function(){talkify.messageHub.publish(me.correlationId+".player.tts.timeupdated",{currentTime:audioElement.currentTime,duration:audioElement.duration})},50);if(!me.currentContext.positions.length){talkify.messageHub.publish(me.correlationId+".player.tts.play",{item:me.currentContext.item,positions:[],currentTime:me.audioSource.currentTime()});return}if(me.audioSource.currentTime()>.1){talkify.messageHub.publish(me.correlationId+".player.tts.resume",{currentTime:me.audioSource.currentTime()})}else{var interval=setInterval(function(){if(me.audioSource.currentTime()>0){clearInterval(interval);talkify.messageHub.publish(me.correlationId+".player.tts.play",{item:me.currentContext.item,positions:me.currentContext.positions,currentTime:me.audioSource.currentTime()})}},20)}}function initialize(){if(timeupdater){clearInterval(timeupdater)}audioElement=null;var existingElement=document.getElementById("talkify-audio");if(existingElement){existingElement.outerHTML=""}var mp3Source=document.createElement("source");var wavSource=document.createElement("source");audioElement=document.createElement("audio");audioElement.appendChild(mp3Source);audioElement.appendChild(wavSource);mp3Source.type="audio/mpeg";wavSource.type="audio/wav";audioElement.id="talkify-audio";audioElement.controls=!talkify.config.ui.audioControls.enabled;audioElement.autoplay=false;document.body.appendChild(audioElement);var clonedAudio=audioElement.cloneNode(true);audioElement.parentNode.replaceChild(clonedAudio,audioElement);audioElement=clonedAudio;talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.play",function(){me.play()});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.pause",function(){audioElement.pause()});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.seek",function(position){var pos=audioElement.duration*position;if(isNaN(audioElement.duration)){return}audioElement.currentTime=pos});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.volume",function(volume){audioElement.volume=volume/10});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.rate",function(rate){me.settings.rate=rate});if(me.playbar.instance){me.playbar.instance.setMinRate(-5).setMaxRate(5)}}function getPositions(requestId){var p=new promise.Promise;talkify.http.get(talkify.config.remoteService.speechBaseUrl+"/marks?id="+requestId).then(function(error,positions){p.done(null,positions)});return p}initialize.apply(this);this.playAudio=function(item){talkify.messageHub.publish(me.correlationId+".player.tts.loading",item);me.currentContext.item=item;me.currentContext.positions=[];audioElement.onloadeddata=null;audioElement.onended=null;var sources=audioElement.getElementsByTagName("source");var textToPlay=encodeURIComponent(item.text.replace(/\n/g," "));var voice=this.forcedVoice?this.forcedVoice.name:"";var requestId=talkify.generateGuid();var audioUrl=talkify.config.remoteService.host+talkify.config.remoteService.speechBaseUrl+"?text="+textToPlay+"&fallbackLanguage="+this.settings.referenceLanguage.Language+"&voice="+voice+"&rate="+this.settings.rate+"&key="+talkify.config.remoteService.apiKey;if(me.settings.useTextHighlight){audioUrl+="&marksid="+requestId}sources[0].src=audioUrl+"&format=mp3";sources[1].src=audioUrl+"&format=wav";audioElement.load();audioElement.onloadeddata=function(){me.audioSource.pause();if(!me.settings.useTextHighlight){talkify.messageHub.publish(me.correlationId+".player.tts.loaded",me.currentContext.item);me.audioSource.play();return}getPositions(requestId).then(function(error,positions){me.currentContext.positions=positions||[];talkify.messageHub.publish(me.correlationId+".player.tts.loaded",me.currentContext.item);me.audioSource.play()})};audioElement.onended=function(){talkify.messageHub.publish(me.correlationId+".player.tts.ended",item)}};setupBindings()};talkify.TtsPlayer.prototype.constructor=talkify.TtsPlayer},{}],12:[function(require,module,exports){talkify=talkify||{};talkify.playlist=function(){var defaults={useGui:false,useTextInteraction:false,domElements:[],exclusions:[],rootSelector:"body",events:{onEnded:null,onVoiceCommandListeningStarted:null,onVoiceCommandListeningEnded:null}};var s=JSON.parse(JSON.stringify(defaults));var p=null;function isSupported(){var a=document.createElement("audio");return typeof a.canPlayType==="function"&&(a.canPlayType("audio/mpeg")!==""||a.canPlayType("audio/wav")!=="")}function implementation(_settings,player){var textextractor=new talkify.textextractor;var playlist={queue:[],currentlyPlaying:null,refrenceText:"",referenceLanguage:{Culture:"",Language:-1}};var settings=_settings;var playerHasBeenReplaced=false;var commands=[new talkify.KeyboardCommands(talkify.config.keyboardCommands),new talkify.SpeechCommands(talkify.config.voiceCommands)];var voiceCommands=commands[1];for(var k=0;ksafeMaxQuerystringLength){var breakAt=text.substr(0,safeMaxQuerystringLength).lastIndexOf(".");breakAt=breakAt>-1?breakAt:safeMaxQuerystringLength;var f=text.substr(0,breakAt);items.push(template(f,element));items=items.concat(createItems(text.substr(breakAt,text.length-1),element));return items}items.push(template(text,element));return items;function template(t,el){el=el||document.createElement("span");var clone=el.cloneNode(true);return{text:t,preview:t.substr(0,40),element:el,originalElement:clone,isPlaying:false,isLoading:false}}}function play(item){if(!item){if(playlist.queue.length===0){return}playFromBeginning();return}playItem(item)}function pause(){player.pause()}function setupItemForUserInteraction(item){item.element.style.cursor="pointer";item.element.classList.add("talkify-highlight");removeEventListeners("click",item.element);addEventListener("click",item.element,textInteractionEventListener);function textInteractionEventListener(){play(item)}}function removeUserInteractionForItem(item){item.element.style.cursor="inherit";item.element.classList.remove("talkify-highlight");removeEventListeners("click",item.element)}function initialize(){reset();if(!settings.domElements||settings.domElements.length===0){settings.domElements=textextractor.extract(settings.rootSelector,settings.exclusions)}for(var i=0;iplaylist.refrenceText.length){playlist.refrenceText=text}}if(settings.useTextInteraction){for(var j=0;j0){var isSameAsPrevious=item.element===playlist.queue[j-1].element;if(isSameAsPrevious){continue}}setupItemForUserInteraction(item)}}}function getNextItem(){var currentQueuePosition=playlist.queue.indexOf(playlist.currentlyPlaying);if(currentQueuePosition===playlist.queue.length-1){return null}return playlist.queue[currentQueuePosition+1]}function getPreviousItem(){var currentQueuePosition=playlist.queue.indexOf(playlist.currentlyPlaying);if(currentQueuePosition===0){return null}return playlist.queue[currentQueuePosition-1]}function playFromBeginning(){if(!talkify.config.remoteService.active){onComplete({Culture:"",Language:-1});return}talkify.http.get(talkify.config.remoteService.languageBaseUrl+"/detect?text="+playlist.refrenceText).then(function(error,data){if(error){onComplete({Culture:"",Language:-1});return}onComplete(data)});function onComplete(refLang){playlist.referenceLanguage=refLang;player.withReferenceLanguage(refLang);playItem(playlist.queue[0])}}function insertElement(element){var items=[];var text=element.innerText;if(text.trim()===""){return items}if(domElementExistsInQueue(element)){return items}var documentPositionFollowing=4;for(var j=0;j-1})[0];if(match){possibleMatches.push(key);break}}}if(possibleMatches.length>0){var bestValue=0;var bestCommand=null;for(var j=0;jbestValue){bestValue=temp;bestCommand=possibleMatches[j]}}return bestCommand}return null}function levenshtein(s1,s2){var longer=s1;var shorter=s2;if(s1.length0){var newValue=costs[j-1];if(s1.charAt(i-1)!=s2.charAt(j-1))newValue=Math.min(Math.min(newValue,lastValue),costs[j])+1;costs[j-1]=lastValue;lastValue=newValue}}}if(i>0)costs[s2.length]=lastValue}return costs[s2.length]}if(speechCommandConfig.keyboardActivation.enabled){document.addEventListener("keyup",function(e){if(!e.ctrlKey){return}if(isListening){return}var key=e.keyCode?e.keyCode:e.which;if(key===speechCommandConfig.keyboardActivation.key){recognition.start()}})}return{onPrevious:function(callback){onPreviousCallback=callback},onNext:function(callback){onNextCallback=callback},onPlayPause:function(callback){onPlayPauseCallback=callback},start:function(){if(isListening){return}recognition.start()},onListeningStarted:function(callback){onListeningStartedCallback=callback},onListeningEnded:function(callback){onListeningEndedCallback=callback},dispose:function(){}}}},{}],14:[function(require,module,exports){talkify=talkify||{};talkify.textextractor=function(){var validElements=[];var inlineElements=["a","span","b","big","i","small","tt","abbr","acronym","cite","code","dfn","em","kbd","strong","samp","var","a","bdo","q","sub","sup","label"];var forbiddenElementsString=["img","map","object","script","button","input","select","textarea","br","style","code","nav","#nav","#navigation",".nav",".navigation","footer","rp","rt"];var userExcludedElements=[];function getVisible(elements){var result=[];for(var j=0;j=10}return false}function isValidAnchor(node){var nrOfSiblings=getSiblings(node);if(nrOfSiblings.length>=1){return true}var previous=node.previousSibling;if(isValidTextNode(previous)){return true}if(isValidTextNode(node.nextSibling)){return true}return false}function isValidForGrouping(node){var isTextNode=node.nodeType===3;var textLength=getStrippedText(node.textContent).length;return isTextNode&&textLength>=5||!isForbidden(node)&&elementIsInlineElement(node)}function getConnectedElements(nodes,firstIndex){var connectedElements=[];for(var l=firstIndex;l1){var wrapping=group(connectedElements);var isAboveThreshold=getStrippedText(wrapping.innerText).length>=20;if(isAboveThreshold){nodes[i].parentNode.replaceChild(wrapping,nodes[i]);for(var j=0;j "+generateExcludesFromForbiddenElements());var date=new Date;for(var i=0;i=position&&time<=currentPositions[i+1].Position){currentPos=i;break}}highlight(currentItem,currentPositions[currentPos].Word,currentPositions[currentPos].CharPosition)});function highlight(item,word,charPosition){resetCurrentItem();currentItem=item;var text=item.element.innerText.trim();var sentence=findCurrentSentence(item,charPosition);item.element.innerHTML=text.substring(0,sentence.start)+''+text.substring(sentence.start,charPosition)+''+text.substring(charPosition,charPosition+word.length)+""+text.substring(charPosition+word.length,sentence.end)+""+text.substring(sentence.end)}function cancel(){resetCurrentItem();currentPositions=[]}function setupWordHightlighting(item,positions,startFrom){cancel();if(!positions.length){return}currentPositions=positions;var i=startFrom||0;var internalCallback=function(){highlight(item,positions[i].Word,positions[i].CharPosition);i++;if(i>=positions.length){window.setTimeout(function(){item.element.innerHTML=item.originalElement.innerHTML;talkify.messageHub.publish(correlationId+".wordhighlighter.complete",item)},1e3);return}};internalCallback()}function resetCurrentItem(){if(currentItem){currentItem.element.innerHTML=currentItem.originalElement.innerHTML}}function setPosition(time){var diff=0;var timeInMs=time*1e3;var nextPosition=0;for(var i=0;i=charactersTraversed&&charPosition<=charactersTraversed+result[i].length){if(charactersTraversed>0){sentenceStart=charactersTraversed+1}sentenceEnd=charactersTraversed+result[i].length;break}charactersTraversed+=result[i].length}return{start:sentenceStart,end:sentenceEnd}}function dispose(){talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.seeked");talkify.messageHub.unsubscribe("word-highlighter",[correlationId+".player.tts.loading",correlationId+".player.tts.disposed"]);talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.play");talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.timeupdated")}return{start:setupWordHightlighting,highlight:highlight,dispose:dispose}}},{}],17:[function(require,module,exports){talkify={}},{}]},{},[1]); +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i=300)&&j.status!==304;h.done(a,j.responseText,j)}};j.send(k);return h}function h(a){return function(b,c,d){return g(a,b,c,d)}}var i={Promise:b,join:c,chain:d,ajax:g,get:h("GET"),post:h("POST"),put:h("PUT"),del:h("DELETE"),ENOXHR:1,ETIMEOUT:2,ajaxTimeout:0};if(typeof define==="function"&&define.amd)define(function(){return i});else a.promise=i})(this)},{}],3:[function(require,module,exports){talkify=talkify||{};talkify.http=function ajax(){var get=function(url){var call=new promise.Promise;var keypart=(url.indexOf("?")!==-1?"&key=":"?key=")+talkify.config.remoteService.apiKey;promise.get(window.talkify.config.remoteService.host+url+keypart).then(function(error,data){try{var jsonObj=JSON.parse(data);call.done(error,jsonObj)}catch(e){call.done(e,data)}});return call};return{get:get}}()},{}],4:[function(require,module,exports){talkify=talkify||{};talkify.config={debug:false,ui:{audioControls:{enabled:false,container:document.body}},formReader:{voice:null,rate:0,remoteService:true,requiredText:"This field is required",valueText:"You have entered {value} as: {label}.",selectedText:"You have selected {label}.",notSelectedText:"{label} is not selected."},remoteService:{active:true,host:"https://talkify.net",apiKey:"",speechBaseUrl:"/api/speech/v1",languageBaseUrl:"/api/language/v1"},keyboardCommands:{enabled:false,commands:{playPause:32,next:39,previous:37}},voiceCommands:{enabled:false,keyboardActivation:{enabled:true,key:77},commands:{playPause:["play","pause","stop","start"],next:["play next","next"],previous:["play previous","previous","back","go back"]}}}},{}],5:[function(require,module,exports){talkify=talkify||{};talkify.playbar=function(parent,correlationId){var settings={parentElement:parent||talkify.config.ui.audioControls.container||document.body};var playElement,pauseElement,rateElement,volumeElement,progressElement,voiceElement,currentTimeElement,textHighlightingElement,wrapper;var attachElement,detatchedElement,dragArea;function hide(element){if(element.classList.contains("talkify-hidden")){return}element.className+=" talkify-hidden"}function show(element){element.className=element.className.replace("talkify-hidden","")}function play(){hide(playElement);show(pauseElement)}function pause(){hide(pauseElement);show(playElement)}function addClass(element,c){if(element.classList.contains(c)){return}element.className+=" "+c}function removeClass(element,c){element.className=element.className.replace(c,"")}function createElement(type,classes){var element=document.createElement(type);element.className=classes;return element}function render(){var existingControl=document.getElementsByClassName("talkify-control-center")[0];if(existingControl){existingControl.parentNode.removeChild(existingControl)}wrapper=createElement("div","talkify-control-center attached");wrapper.innerHTML="
      "+'
    • '+' '+"
    • "+"
    • "+' "+' "+"
    • "+'
    • '+' '+' 00:00 / 00:00 '+"
    • "+"
    • "+'
    • "+"
    • "+' "+"
    • "+"
    • "+' "+"
    • "+"
    • "+' "+' "+"
    "+'
    '+" Voice: "+"
    ";playElement=wrapper.getElementsByClassName("talkify-play-button")[0];pauseElement=wrapper.getElementsByClassName("talkify-pause-button")[0];rateElement=wrapper.querySelector(".rate-button input[type=range]");volumeElement=wrapper.querySelector(".volume-button input[type=range]");progressElement=wrapper.getElementsByTagName("progress")[0];textHighlightingElement=wrapper.getElementsByClassName("talkify-cc-button")[0];currentTimeElement=wrapper.getElementsByClassName("talkify-time-element")[0];attachElement=wrapper.getElementsByClassName("talkify-detatched")[0];detatchedElement=wrapper.getElementsByClassName("talkify-attached")[0];voiceWrapperElement=wrapper.querySelector(".talkify-voice-selector select");dragArea=wrapper.getElementsByClassName("drag-area")[0];settings.parentElement.appendChild(wrapper);pause()}function setupBindings(){var controlCenter=document.getElementsByClassName("talkify-control-center")[0];playElement.addEventListener("click",function(){if(playElement.classList.contains("talkify-disabled")){return}talkify.messageHub.publish(correlationId+".controlcenter.request.play")});pauseElement.addEventListener("click",function(){if(pauseElement.classList.contains("talkify-disabled")){return}talkify.messageHub.publish(correlationId+".controlcenter.request.pause")});rateElement.addEventListener("change",function(){talkify.messageHub.publish(correlationId+".controlcenter.request.rate",parseInt(this.value))});volumeElement.addEventListener("change",function(e){talkify.messageHub.publish(correlationId+".controlcenter.request.volume",parseInt(this.value))});textHighlightingElement.addEventListener("click",function(e){if(textHighlightingElement.classList.contains("talkify-disabled")){removeClass(textHighlightingElement,"talkify-disabled");talkify.messageHub.publish(correlationId+".controlcenter.texthighlightoggled",true)}else{addClass(textHighlightingElement,"talkify-disabled");talkify.messageHub.publish(correlationId+".controlcenter.texthighlightoggled",false)}});progressElement.addEventListener("click",function(e){var clickedValue=e.offsetX*this.max/this.offsetWidth;if(clickedValue>1){clickedValue=1}if(clickedValue<0){clickedValue=0}talkify.messageHub.publish(correlationId+".controlcenter.request.seek",clickedValue)});attachElement.addEventListener("click",function(){addClass(controlCenter,"attached")});detatchedElement.addEventListener("click",function(){removeClass(controlCenter,"attached")});dragArea.addEventListener("mousedown",onMouseDown);document.addEventListener("mouseup",onMouseUp);function onMouseUp(e){document.removeEventListener("mousemove",onMouseMove)}function onMouseDown(e){document.addEventListener("mousemove",onMouseMove)}function onMouseMove(e){controlCenter.style.top=e.clientY+"px";controlCenter.style.left=e.clientX+"px"}}function initialize(){render();setupBindings();talkify.messageHub.subscribe("controlcenter",[correlationId+".player.*.pause",correlationId+".player.*.disposed"],pause);talkify.messageHub.subscribe("controlcenter",[correlationId+".player.*.play",correlationId+".player.*.resume"],play);talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.disposed",dispose);talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.loaded",function(){removeClass(pauseElement,"talkify-disabled");removeClass(playElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.texthighlight.enabled",function(){removeClass(textHighlightingElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.texthighlight.disabled",function(){addClass(textHighlightingElement,"talkify-disabled")});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.ratechanged",function(rate){rateElement.value=rate});talkify.messageHub.subscribe("controlcenter",correlationId+".player.*.voiceset",function(voice){featureToggle(voice);setVoiceName(voice)});talkify.messageHub.subscribe("controlcenter",correlationId+".player.tts.timeupdated",updateClock);talkify.messageHub.subscribe("controlcenter",correlationId+".player.html5.timeupdated",function(value){progressElement.setAttribute("value",value)})}function updateClock(timeInfo){var currentTime=timeInfo.currentTime;var duration=timeInfo.duration;progressElement.setAttribute("value",currentTime/duration);if(!currentTimeElement){return}var currentminutes=Math.floor(currentTime/60);var currentseconds=Math.round(currentTime)-currentminutes*60;var totalminutes=!!duration?Math.floor(duration/60):0;var totalseconds=!!duration?Math.round(duration)-totalminutes*60:0;currentTimeElement.textContent=currentminutes+":"+(currentseconds<10?"0"+currentseconds:currentseconds)+" / "+totalminutes+":"+(totalseconds<10?"0"+totalseconds:totalseconds)}function isTalkifyHostedVoice(voice){return voice&&voice.constructor.name!=="SpeechSynthesisVoice"}function featureToggle(voice){show(progressElement);show(textHighlightingElement);if(!voice){return}if(isTalkifyHostedVoice(voice)){return}hide(currentTimeElement);if(!voice.localService){hide(progressElement);hide(textHighlightingElement)}}function setVoiceName(voice){var voiceElement=document.querySelector(".talkify-voice-selector > span");if(!voice){voiceElement.textContent="Automatic voice detection";return}if(isTalkifyHostedVoice(voice)){voiceElement.textContent=voice.description;return}voiceElement.textContent=voice.name}function dispose(){var existingControl=document.getElementById("htmlPlaybar");if(existingControl){existingControl.parentNode.removeChild(existingControl)}talkify.messageHub.unsubscribe("controlcenter",[correlationId+".player.*.pause",correlationId+".player.*.disposed"]);talkify.messageHub.unsubscribe("controlcenter",[correlationId+".player.*.play",correlationId+".player.*.resume"]);talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.disposed");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.loaded");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.texthighlight.enabled");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.texthighlight.disabled");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.ratechanged");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.*.voiceset");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.tts.timeupdated");talkify.messageHub.unsubscribe("controlcenter",correlationId+".player.html5.timeupdated")}initialize();return{setMaxRate:function(value){rateElement.setAttribute("max",value);return this},setMinRate:function(value){rateElement.setAttribute("min",value);return this},dispose:dispose}}},{}],6:[function(require,module,exports){talkify=talkify||{};talkify.formReader=function(){var player;var timeout;function setupForm(formElement){var elements=formElement.elements;for(var i=0;i-1?70:language.indexOf("ko-")>-1?130:200;var chuncks=[];var sentences=text.split(/(\?|\.|。)+/g);var currentChunck="";sentences.forEach(function(sentence){if(sentence===""||sentence==="."||sentence==="。"||sentence==="?"){if(currentChunck){currentChunck+=sentence}return}if(currentChunck&¤tChunck.length+sentence.length>chunckSize){chuncks.push(currentChunck);currentChunck=""}if(sentence.length>chunckSize){var words=extractWords(sentence,language);words.forEach(function(word){if(currentChunck.length+word.length>chunckSize){chuncks.push(currentChunck);currentChunck=""}currentChunck+=word.trim()+" "});if(currentChunck.trim()){chuncks.push(currentChunck.trim()+".");currentChunck=""}return}currentChunck+=sentence});chuncks.push(currentChunck);return chuncks}function extractWords(text,language){var wordRegex=new RegExp(/[&\$\-|]|([("\-&])*(\b[^\s]+[.:,"-)!&?]*)/g);if(language){if(language.indexOf("zh-")>-1){return text.split(",")}if(language.indexOf("ko-")>-1){return text.split(".")}}var words=[];var m;while((m=wordRegex.exec(text))!==null){if(m.index===wordRegex.lastIndex){wordRegex.lastIndex++}words.push(m[0])}return words}function selectVoiceToPlay(voices){var matchingVoices=[];var voice=null;var language=me.settings.lockedLanguage||me.settings.referenceLanguage.Culture;for(var i=0;i-1}).forEach(function(subscriberKey){subscribers[subscriberKey]=subscribers[subscriberKey].filter(function(subscriber){return subscriber.key!==key})})}return{publish:publish,subscribe:subscribe,unsubscribe:unsubscribe}}()},{}],10:[function(require,module,exports){talkify=talkify||{};talkify.BasePlayer=function(_audiosource,_playbar){this.correlationId=talkify.generateGuid();this.audioSource=_audiosource;this.wordHighlighter=new talkify.wordHighlighter(this.correlationId);var me=this;this.settings={useTextHighlight:false,referenceLanguage:{Culture:"",Language:-1},lockedLanguage:null,rate:1,useControls:false};this.playbar=_playbar;this.forcedVoice=null;if(talkify.config.ui.audioControls.enabled){this.playbar.instance=talkify.playbar(null,this.correlationId)}talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.loaded",function(item){item.isLoading=false});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.ended",function(item){item.isPlaying=false});talkify.messageHub.subscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled",function(enabled){me.settings.useTextHighlight=enabled});talkify.messageHub.publish(this.correlationId+".player.*.ratechanged",me.settings.rate);this.withReferenceLanguage=function(refLang){this.settings.referenceLanguage=refLang;return this};this.enableTextHighlighting=function(){this.settings.useTextHighlight=true;talkify.messageHub.publish(this.correlationId+".player.*.texthighlight.enabled");return this};this.disableTextHighlighting=function(){this.settings.useTextHighlight=false;talkify.messageHub.publish(this.correlationId+".player.*.texthighlight.disabled");return this};this.setRate=function(r){this.settings.rate=r;talkify.messageHub.publish(this.correlationId+".player.*.ratechanged",r);return this};this.subscribeTo=function(subscriptions){talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.pause",subscriptions.onPause||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.resume",subscriptions.onResume||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.play",subscriptions.onPlay||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.loaded",subscriptions.onItemLoaded||function(){});talkify.messageHub.subscribe("core-player",[this.correlationId+".wordhighlighter.complete",this.correlationId+".player.html5.utterancecomplete"],subscriptions.onItemFinished||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".player.*.prepareplay",subscriptions.onBeforeItemPlaying||function(){});talkify.messageHub.subscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled",subscriptions.onTextHighligtChanged||function(){});return this};this.playItem=function(item){if(item&&item.isPlaying){if(this.audioSource.paused()){this.audioSource.play()}else{this.audioSource.pause()}}talkify.messageHub.publish(this.correlationId+".player.*.prepareplay",item);item.isLoading=true;item.isPlaying=true;item.element.classList.add("playing");this.playAudio(item)};this.createItems=function(text){var safeMaxQuerystringLength=1e3;var items=[];if(text.length>safeMaxQuerystringLength){var f=text.substr(0,safeMaxQuerystringLength);items.push(template(f));items=items.concat(this.createItems(text.substr(safeMaxQuerystringLength,text.length-1)));return items}items.push(template(text));return items;function template(t){var element=document.createElement("span");var clone=element.cloneNode(true);return{text:t,preview:t.substr(0,40),element:element,originalElement:clone,isPlaying:false,isLoading:false}}};this.playText=function(text){if(!text){return}var items=this.createItems(text);var currentItem=0;talkify.messageHub.subscribe("core-player.playText",this.correlationId+".player.*.ended",function(){currentItem++;if(currentItem>=items.length){talkify.messageHub.unsubscribe("core.playText",this.correlationId+".player.*.ended");return}this.playItem(items[currentItem])});this.playItem(items[currentItem])};this.paused=function(){return this.audioSource.paused()};this.isPlaying=function(){return this.audioSource.isPlaying()};this.play=function(){this.audioSource.play()};this.pause=function(){this.audioSource.pause();var me=this;if(!me.audioSource.paused()&&me.audioSource.cancel){me.audioSource.cancel(true)}};this.dispose=function(){talkify.messageHub.publish(this.correlationId+".player.tts.disposed");this.audioSource.stop();this.audioSource.dispose();this.wordHighlighter.dispose();talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.loaded");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.ended");talkify.messageHub.unsubscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.pause");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.resume");talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.play");talkify.messageHub.unsubscribe("core-player",[this.correlationId+".wordhighlighter.complete",this.correlationId+".player.html5.utterancecomplete"]);talkify.messageHub.unsubscribe("core-player",this.correlationId+".player.*.prepareplay");talkify.messageHub.unsubscribe("core-player",this.correlationId+".controlcenter.texthighlightoggled")};this.forceLanguage=function(culture){this.settings.lockedLanguage=culture;return this};this.forceVoice=function(voice){this.forcedVoice=voice!==undefined?voice:null;this.settings.lockedLanguage=voice&&(voice.lang||voice.culture)||this.settings.lockedLanguage;talkify.messageHub.publish(this.correlationId+".player.*.voiceset",voice);return this}}},{}],11:[function(require,module,exports){talkify=talkify||{};talkify.TtsPlayer=function(){if(!talkify.config.remoteService.active){throw"This player needs to communicate to a remote service. To enable this player please set flag talkify.config.remoteService.active to true."}var me=this;var audioElement,timeupdater;this.currentContext={item:null,positions:[]};this.playbar={instance:null};this.audioSource={play:function(){audioElement.play()},pause:function(){audioElement.pause()},isPlaying:function(){return audioElement.duration>0&&!audioElement.paused},paused:function(){return audioElement.paused},currentTime:function(){return audioElement.currentTime},stop:function(){audioElement.pause();audioElement.currentTime=0},dispose:function(){if(timeupdater){clearInterval(timeupdater)}var existingElement=document.getElementById("talkify-audio");if(existingElement){existingElement.outerHTML=""}talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.play");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.pause");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.seek");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.volume");talkify.messageHub.unsubscribe("tts-player",me.correlationId+".controlcenter.request.rate")}};talkify.BasePlayer.call(this,this.audioSource,this.playbar);function setupBindings(){audioElement.addEventListener("pause",onPause);audioElement.addEventListener("play",onPlay);audioElement.addEventListener("seeked",onSeek)}function onSeek(){talkify.messageHub.publish(me.correlationId+".player.tts.seeked",this.currentTime);if(me.audioSource.paused()&&me.audioSource.currentTime()>.1){me.audioSource.play()}}function onPause(){if(timeupdater){clearInterval(timeupdater)}talkify.messageHub.publish(me.correlationId+".player.tts.pause")}function onPlay(){if(timeupdater){clearInterval(timeupdater)}timeupdater=setInterval(function(){talkify.messageHub.publish(me.correlationId+".player.tts.timeupdated",{currentTime:audioElement.currentTime,duration:audioElement.duration})},50);if(!me.currentContext.positions.length){talkify.messageHub.publish(me.correlationId+".player.tts.play",{item:me.currentContext.item,positions:[],currentTime:me.audioSource.currentTime()});return}if(me.audioSource.currentTime()>.1){talkify.messageHub.publish(me.correlationId+".player.tts.resume",{currentTime:me.audioSource.currentTime()})}else{var interval=setInterval(function(){if(me.audioSource.currentTime()>0){clearInterval(interval);talkify.messageHub.publish(me.correlationId+".player.tts.play",{item:me.currentContext.item,positions:me.currentContext.positions,currentTime:me.audioSource.currentTime()})}},20)}}function initialize(){if(timeupdater){clearInterval(timeupdater)}audioElement=null;var existingElement=document.getElementById("talkify-audio");if(existingElement){existingElement.outerHTML=""}var mp3Source=document.createElement("source");var wavSource=document.createElement("source");audioElement=document.createElement("audio");audioElement.appendChild(mp3Source);audioElement.appendChild(wavSource);mp3Source.type="audio/mpeg";wavSource.type="audio/wav";audioElement.id="talkify-audio";audioElement.controls=!talkify.config.ui.audioControls.enabled;audioElement.autoplay=false;document.body.appendChild(audioElement);var clonedAudio=audioElement.cloneNode(true);audioElement.parentNode.replaceChild(clonedAudio,audioElement);audioElement=clonedAudio;talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.play",function(){me.play()});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.pause",function(){audioElement.pause()});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.seek",function(position){var pos=audioElement.duration*position;if(isNaN(audioElement.duration)){return}audioElement.currentTime=pos});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.volume",function(volume){audioElement.volume=volume/10});talkify.messageHub.subscribe("tts-player",me.correlationId+".controlcenter.request.rate",function(rate){me.settings.rate=rate});if(me.playbar.instance){me.playbar.instance.setMinRate(-5).setMaxRate(5)}}function getPositions(requestId){var p=new promise.Promise;talkify.http.get(talkify.config.remoteService.speechBaseUrl+"/marks?id="+requestId).then(function(error,positions){p.done(null,positions)});return p}initialize.apply(this);this.playAudio=function(item){talkify.messageHub.publish(me.correlationId+".player.tts.loading",item);me.currentContext.item=item;me.currentContext.positions=[];audioElement.onloadeddata=null;audioElement.onended=null;var sources=audioElement.getElementsByTagName("source");var textToPlay=encodeURIComponent(item.text.replace(/\n/g," "));var voice=this.forcedVoice?this.forcedVoice.name:"";var requestId=talkify.generateGuid();var audioUrl=talkify.config.remoteService.host+talkify.config.remoteService.speechBaseUrl+"?text="+textToPlay+"&fallbackLanguage="+this.settings.referenceLanguage.Language+"&voice="+voice+"&rate="+this.settings.rate+"&key="+talkify.config.remoteService.apiKey;if(me.settings.useTextHighlight){audioUrl+="&marksid="+requestId}sources[0].src=audioUrl+"&format=mp3";sources[1].src=audioUrl+"&format=wav";audioElement.load();audioElement.onloadeddata=function(){me.audioSource.pause();if(!me.settings.useTextHighlight){talkify.messageHub.publish(me.correlationId+".player.tts.loaded",me.currentContext.item);me.audioSource.play();return}getPositions(requestId).then(function(error,positions){me.currentContext.positions=positions||[];talkify.messageHub.publish(me.correlationId+".player.tts.loaded",me.currentContext.item);me.audioSource.play()})};audioElement.onended=function(){talkify.messageHub.publish(me.correlationId+".player.tts.ended",item)}};setupBindings()};talkify.TtsPlayer.prototype.constructor=talkify.TtsPlayer},{}],12:[function(require,module,exports){talkify=talkify||{};talkify.playlist=function(){var defaults={useGui:false,useTextInteraction:false,domElements:[],exclusions:[],rootSelector:"body",events:{onEnded:null,onVoiceCommandListeningStarted:null,onVoiceCommandListeningEnded:null}};var s=JSON.parse(JSON.stringify(defaults));var p=null;function isSupported(){var a=document.createElement("audio");return typeof a.canPlayType==="function"&&(a.canPlayType("audio/mpeg")!==""||a.canPlayType("audio/wav")!=="")}function implementation(_settings,player){var textextractor=new talkify.textextractor;var playlist={queue:[],currentlyPlaying:null,refrenceText:"",referenceLanguage:{Culture:"",Language:-1}};var settings=_settings;var playerHasBeenReplaced=false;var commands=[new talkify.KeyboardCommands(talkify.config.keyboardCommands),new talkify.SpeechCommands(talkify.config.voiceCommands)];var voiceCommands=commands[1];for(var k=0;ksafeMaxQuerystringLength){var breakAt=text.substr(0,safeMaxQuerystringLength).lastIndexOf(".");breakAt=breakAt>-1?breakAt:safeMaxQuerystringLength;var f=text.substr(0,breakAt);items.push(template(f,element));items=items.concat(createItems(text.substr(breakAt,text.length-1),element));return items}items.push(template(text,element));return items;function template(t,el){el=el||document.createElement("span");var clone=el.cloneNode(true);return{text:t,preview:t.substr(0,40),element:el,originalElement:clone,isPlaying:false,isLoading:false}}}function play(item){if(!item){if(playlist.queue.length===0){return}playFromBeginning();return}playItem(item)}function pause(){player.pause()}function setupItemForUserInteraction(item){item.element.style.cursor="pointer";item.element.classList.add("talkify-highlight");removeEventListeners("click",item.element);addEventListener("click",item.element,textInteractionEventListener);function textInteractionEventListener(){play(item)}}function removeUserInteractionForItem(item){item.element.style.cursor="inherit";item.element.classList.remove("talkify-highlight");removeEventListeners("click",item.element)}function initialize(){reset();if(!settings.domElements||settings.domElements.length===0){settings.domElements=textextractor.extract(settings.rootSelector,settings.exclusions)}for(var i=0;iplaylist.refrenceText.length){playlist.refrenceText=text}}if(settings.useTextInteraction){for(var j=0;j0){var isSameAsPrevious=item.element===playlist.queue[j-1].element;if(isSameAsPrevious){continue}}setupItemForUserInteraction(item)}}}function getNextItem(){var currentQueuePosition=playlist.queue.indexOf(playlist.currentlyPlaying);if(currentQueuePosition===playlist.queue.length-1){return null}return playlist.queue[currentQueuePosition+1]}function getPreviousItem(){var currentQueuePosition=playlist.queue.indexOf(playlist.currentlyPlaying);if(currentQueuePosition===0){return null}return playlist.queue[currentQueuePosition-1]}function playFromBeginning(){if(!talkify.config.remoteService.active){onComplete({Culture:"",Language:-1});return}talkify.http.get(talkify.config.remoteService.languageBaseUrl+"/detect?text="+playlist.refrenceText).then(function(error,data){if(error){onComplete({Culture:"",Language:-1});return}onComplete(data)});function onComplete(refLang){playlist.referenceLanguage={Culture:refLang.Cultures[0],Language:refLang.Language};player.withReferenceLanguage(playlist.referenceLanguage);playItem(playlist.queue[0])}}function insertElement(element){var items=[];var text=element.innerText;if(text.trim()===""){return items}if(domElementExistsInQueue(element)){return items}var documentPositionFollowing=4;for(var j=0;j-1})[0];if(match){possibleMatches.push(key);break}}}if(possibleMatches.length>0){var bestValue=0;var bestCommand=null;for(var j=0;jbestValue){bestValue=temp;bestCommand=possibleMatches[j]}}return bestCommand}return null}function levenshtein(s1,s2){var longer=s1;var shorter=s2;if(s1.length0){var newValue=costs[j-1];if(s1.charAt(i-1)!=s2.charAt(j-1))newValue=Math.min(Math.min(newValue,lastValue),costs[j])+1;costs[j-1]=lastValue;lastValue=newValue}}}if(i>0)costs[s2.length]=lastValue}return costs[s2.length]}if(speechCommandConfig.keyboardActivation.enabled){document.addEventListener("keyup",function(e){if(!e.ctrlKey){return}if(isListening){return}var key=e.keyCode?e.keyCode:e.which;if(key===speechCommandConfig.keyboardActivation.key){recognition.start()}})}return{onPrevious:function(callback){onPreviousCallback=callback},onNext:function(callback){onNextCallback=callback},onPlayPause:function(callback){onPlayPauseCallback=callback},start:function(){if(isListening){return}recognition.start()},onListeningStarted:function(callback){onListeningStartedCallback=callback},onListeningEnded:function(callback){onListeningEndedCallback=callback},dispose:function(){}}}},{}],14:[function(require,module,exports){talkify=talkify||{};talkify.textextractor=function(){var validElements=[];var inlineElements=["a","span","b","big","i","small","tt","abbr","acronym","cite","code","dfn","em","kbd","strong","samp","var","a","bdo","q","sub","sup","label"];var forbiddenElementsString=["img","map","object","script","button","input","select","textarea","br","style","code","nav","#nav","#navigation",".nav",".navigation","footer","rp","rt"];var userExcludedElements=[];function getVisible(elements){var result=[];for(var j=0;j=10}return false}function isValidAnchor(node){var nrOfSiblings=getSiblings(node);if(nrOfSiblings.length>=1){return true}var previous=node.previousSibling;if(isValidTextNode(previous)){return true}if(isValidTextNode(node.nextSibling)){return true}return false}function isValidForGrouping(node){var isTextNode=node.nodeType===3;var textLength=getStrippedText(node.textContent).length;return isTextNode&&textLength>=5||!isForbidden(node)&&elementIsInlineElement(node)}function getConnectedElements(nodes,firstIndex){var connectedElements=[];for(var l=firstIndex;l1){var wrapping=group(connectedElements);var isAboveThreshold=getStrippedText(wrapping.innerText).length>=20;if(isAboveThreshold){nodes[i].parentNode.replaceChild(wrapping,nodes[i]);for(var j=0;j "+generateExcludesFromForbiddenElements());var date=new Date;for(var i=0;i=position&&time<=currentPositions[i+1].Position){currentPos=i;break}}highlight(currentItem,currentPositions[currentPos].Word,currentPositions[currentPos].CharPosition)});function highlight(item,word,charPosition){resetCurrentItem();currentItem=item;var text=item.element.innerText.trim();var sentence=findCurrentSentence(item,charPosition);item.element.innerHTML=text.substring(0,sentence.start)+''+text.substring(sentence.start,charPosition)+''+text.substring(charPosition,charPosition+word.length)+""+text.substring(charPosition+word.length,sentence.end)+""+text.substring(sentence.end)}function cancel(){resetCurrentItem();currentPositions=[]}function setupWordHightlighting(item,positions,startFrom){cancel();if(!positions.length){return}currentPositions=positions;var i=startFrom||0;var internalCallback=function(){highlight(item,positions[i].Word,positions[i].CharPosition);i++;if(i>=positions.length){window.setTimeout(function(){item.element.innerHTML=item.originalElement.innerHTML;talkify.messageHub.publish(correlationId+".wordhighlighter.complete",item)},1e3);return}};internalCallback()}function resetCurrentItem(){if(currentItem){currentItem.element.innerHTML=currentItem.originalElement.innerHTML}}function setPosition(time){var diff=0;var timeInMs=time*1e3;var nextPosition=0;for(var i=0;i=charactersTraversed&&charPosition<=charactersTraversed+result[i].length){if(charactersTraversed>0){sentenceStart=charactersTraversed+1}sentenceEnd=charactersTraversed+result[i].length;break}charactersTraversed+=result[i].length}return{start:sentenceStart,end:sentenceEnd}}function dispose(){talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.seeked");talkify.messageHub.unsubscribe("word-highlighter",[correlationId+".player.tts.loading",correlationId+".player.tts.disposed"]);talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.play");talkify.messageHub.unsubscribe("word-highlighter",correlationId+".player.tts.timeupdated")}return{start:setupWordHightlighting,highlight:highlight,dispose:dispose}}},{}],17:[function(require,module,exports){talkify={}},{}]},{},[1]); diff --git a/package.json b/package.json index 0fe455f..361de8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "talkify-tts", - "version": "2.5.4", + "version": "2.5.5", "description": "A JavaScript text to speech (TTS) library. Provides you with high quality TTS voices in many languages and a high quality language. These voices and engines runs on a Talkify hosted server. This lib also supports browser built in voices via the SpeechSynthesis API if you rather not rely on Talkify servers.", "main": "dist/talkify.js", "style": "dist/styles/*.css", diff --git a/src/talkify-controlcenter.js b/src/talkify-controlcenter.js index 27a3a65..72389d7 100644 --- a/src/talkify-controlcenter.js +++ b/src/talkify-controlcenter.js @@ -63,10 +63,10 @@ talkify.playbar = function (parent, correlationId) { ' ' + ' ' + '
  • ' + - ' ' + - ' ' + '
  • ' + @@ -261,7 +261,7 @@ talkify.playbar = function (parent, correlationId) { } function isTalkifyHostedVoice(voice) { - return voice && voice.isTalkify; + return voice && voice.constructor.name !== "SpeechSynthesisVoice"; } function featureToggle(voice) { diff --git a/src/talkify-html5-speechsynthesis-player.js b/src/talkify-html5-speechsynthesis-player.js index 9c243ea..c51df3b 100644 --- a/src/talkify-html5-speechsynthesis-player.js +++ b/src/talkify-html5-speechsynthesis-player.js @@ -11,6 +11,8 @@ talkify.Html5Player = function () { currentUtterance: null }; + var timeupdater; + var me = this; this.playbar = { @@ -47,6 +49,10 @@ talkify.Html5Player = function () { talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.pause"); talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.volume"); talkify.messageHub.unsubscribe("html5player", me.correlationId + ".controlcenter.request.rate"); + + if (timeupdater) { + clearInterval(timeupdater); + } } }; @@ -92,6 +98,10 @@ talkify.Html5Player = function () { talkify.messageHub.subscribe("html5player", me.correlationId + ".controlcenter.request.rate", function (rate) { me.settings.rate = rate / 5; }); function playCurrentContext() { + if (timeupdater) { + clearInterval(timeupdater); + } + var item = me.currentContext.item; var chuncks = chunckText(item.text); @@ -117,6 +127,10 @@ talkify.Html5Player = function () { me.currentContext.utterances[me.currentContext.utterances.length - 1].onend = function (e) { talkify.messageHub.publish(me.correlationId + ".player.html5.utterancecomplete", item); + if (timeupdater) { + clearInterval(timeupdater); + } + if (!me.currentContext.currentUtterance) { return; } @@ -136,6 +150,14 @@ talkify.Html5Player = function () { me.currentContext.currentUtterance = e.utterance; talkify.messageHub.publish(me.correlationId + ".player.html5.loaded", me.currentContext.item); talkify.messageHub.publish(me.correlationId + ".player.html5.play", { item: me.currentContext.item, positions: [], currentTime: 0 }); + + if (timeupdater) { + clearInterval(timeupdater); + } + + timeupdater = setInterval(function () { + talkify.messageHub.publish(me.correlationId + ".player.html5.timeupdated", (wordIndex + 1) / words.length); + }, 100); }; } else { u.onstart = function (e) { @@ -144,6 +166,10 @@ talkify.Html5Player = function () { } u.onpause = function () { + if (timeupdater) { + clearInterval(timeupdater); + } + talkify.messageHub.publish(me.correlationId + ".player.html5.pause"); }; @@ -154,8 +180,6 @@ talkify.Html5Player = function () { return; } - talkify.messageHub.publish(me.correlationId + ".player.html5.timeupdated", (wordIndex + 1) / words.length); - if (!me.settings.useTextHighlight || !u.voice.localService) { return; } @@ -339,6 +363,10 @@ talkify.Html5Player = function () { talkify.messageHub.publish(me.correlationId + ".player.html5.pause"); window.speechSynthesis.cancel(); + if (timeupdater) { + clearInterval(timeupdater); + } + if (me.currentContext.utterances.indexOf(me.currentContext.currentUtterance) < me.currentContext.utterances.length - 1) { console.log('Not the last, finishing anyway...'); talkify.messageHub.publish(me.correlationId + ".player.html5.utterancecomplete", me.currentContext.item); diff --git a/src/talkify-messagehub.js b/src/talkify-messagehub.js index eaaed14..6ae6529 100644 --- a/src/talkify-messagehub.js +++ b/src/talkify-messagehub.js @@ -11,6 +11,11 @@ talkify.messageHub = function () { var candidates = []; Object.keys(subscribers).forEach(function (subscriberKey) { + if(subscriberKey === '*'){ + candidates.push(subscriberKey); + return; + } + var s = subscriberKey.split('.'); if (s.length != topics.length) { @@ -48,7 +53,7 @@ talkify.messageHub = function () { talkify.log("Calling subscriber", subscriber, c, message); } - subscriber.fn(message); + subscriber.fn(message, topic); }); }) diff --git a/src/talkify-playlist.js b/src/talkify-playlist.js index e5a9eb2..3efb97c 100644 --- a/src/talkify-playlist.js +++ b/src/talkify-playlist.js @@ -327,8 +327,8 @@ talkify.playlist = function () { }); function onComplete(refLang) { - playlist.referenceLanguage = refLang; - player.withReferenceLanguage(refLang); + playlist.referenceLanguage = { Culture: refLang.Cultures[0], Language: refLang.Language }; + player.withReferenceLanguage(playlist.referenceLanguage); playItem(playlist.queue[0]); }