Skip to content

Commit

Permalink
fix: polly - fix check for pause
Browse files Browse the repository at this point in the history
  • Loading branch information
jolzee committed Jun 22, 2020
1 parent 9470b80 commit e335344
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/polly.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Polly {

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

async waitForPollyToFinish() {
while (true) {
if (!isPlaying()) {
if (this.isPaused()) {
return;
}
await null; // prevents app from hanging
}
}

isPaused() {
return this.audio.paused;
}

isPlaying() {
return !this.audio.paused;
}
Expand Down

0 comments on commit e335344

Please sign in to comment.