Skip to content

Commit

Permalink
✨ feat: Prevent Polly voices from talking over each other
Browse files Browse the repository at this point in the history
  • Loading branch information
jolzee committed Jun 10, 2020
1 parent 9430309 commit be4bd64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ function storeSetup(vuetify) {
localStorage.setItem("isChatOpen", true);
},
TOGGLE_CHAT_WINDOW_DISPLAY(state, _getters) {
polly.stop();
state.ui.showChatWindow = !state.ui.showChatWindow;
logger.debug(
`store: TOGGLE_CHAT_WINDOW_DISPLAY: state.ui.showChatWindow has toggled to: ${state.ui.showChatWindow}`
Expand Down
4 changes: 3 additions & 1 deletion src/utils/polly.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default class Polly {
}

say(text, voice) {
if (text) {
if (text && voice) {
this.stop();
this.audio = new Audio(
`${window.leopardConfig.tts.url}?text=${encodeURIComponent(text)}&voice=${voice}`
);
Expand All @@ -14,6 +15,7 @@ export default class Polly {

stop() {
if (this.audio) {
// console.log("Pausing Audio!!!");
this.audio.pause();
this.audio.src =
"data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAVFYAAFRWAAABAAgAZGF0YQAAAAA=";
Expand Down

0 comments on commit be4bd64

Please sign in to comment.