Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagsten committed Apr 11, 2019
1 parent da039c9 commit f2e8c78
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 18 deletions.
49 changes: 41 additions & 8 deletions dist/talkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ talkify.playbar = function (parent, correlationId) {
' <i class="fa fa-grip-horizontal"></i> ' +
' </li> ' +
' <li> ' +
' <button class="talkify-play-button" title="Play"> ' +
' <button class="talkify-play-button talkify-disabled" title="Play"> ' +
' <i class="fa fa-play"></i> ' +
' </button> ' +
' <button class="talkify-pause-button" title="Pause"> ' +
' <button class="talkify-pause-button talkify-disabled" title="Pause"> ' +
' <i class="fa fa-pause"></i> ' +
' </button> ' +
' </li> ' +
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -571,6 +571,8 @@ talkify.Html5Player = function () {
currentUtterance: null
};

var timeupdater;

var me = this;

this.playbar = {
Expand Down Expand Up @@ -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);
}
}
};

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -704,6 +726,10 @@ talkify.Html5Player = function () {
}

u.onpause = function () {
if (timeupdater) {
clearInterval(timeupdater);
}

talkify.messageHub.publish(me.correlationId + ".player.html5.pause");
};

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1009,7 +1042,7 @@ talkify.messageHub = function () {
talkify.log("Calling subscriber", subscriber, c, message);
}

subscriber.fn(message);
subscriber.fn(message, topic);
});
})

Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/talkify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/talkify-controlcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ talkify.playbar = function (parent, correlationId) {
' <i class="fa fa-grip-horizontal"></i> ' +
' </li> ' +
' <li> ' +
' <button class="talkify-play-button" title="Play"> ' +
' <button class="talkify-play-button talkify-disabled" title="Play"> ' +
' <i class="fa fa-play"></i> ' +
' </button> ' +
' <button class="talkify-pause-button" title="Pause"> ' +
' <button class="talkify-pause-button talkify-disabled" title="Pause"> ' +
' <i class="fa fa-pause"></i> ' +
' </button> ' +
' </li> ' +
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 30 additions & 2 deletions src/talkify-html5-speechsynthesis-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ talkify.Html5Player = function () {
currentUtterance: null
};

var timeupdater;

var me = this;

this.playbar = {
Expand Down Expand Up @@ -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);
}
}
};

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -144,6 +166,10 @@ talkify.Html5Player = function () {
}

u.onpause = function () {
if (timeupdater) {
clearInterval(timeupdater);
}

talkify.messageHub.publish(me.correlationId + ".player.html5.pause");
};

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/talkify-messagehub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -48,7 +53,7 @@ talkify.messageHub = function () {
talkify.log("Calling subscriber", subscriber, c, message);
}

subscriber.fn(message);
subscriber.fn(message, topic);
});
})

Expand Down
4 changes: 2 additions & 2 deletions src/talkify-playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit f2e8c78

Please sign in to comment.