Skip to content

Commit

Permalink
add voice over
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasileios committed Apr 5, 2024
1 parent b6be906 commit 5d816df
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions JokeTeller/script.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
const button = document.getElementById("button");
const audioElement = document.getElementById("audio");

function toggleButton() {
button.disabled = !button.disabled;
}

function tellMe(joke) {
const jokeString = joke.trim().replace(/ /g, "%20");

VoiceRSS.speech({
key: "YOUR_API_KEY_HERE",
src: jokeString,
hl: "en-us",
r: 0,
c: "mp3",
f: "44khz_16bit_stereo",
ssml: false,
});
}

async function getJokes() {
let joke = "";
const apiUrl =
"https://sv443.net/jokeapi/v2/joke/Programming?blacklistFlags=nsfw,racist,sexist";
try {
const response = await fetch(apiUrl);
const data = await response.json();

if (data.setup) {
joke = `${data.setup} ... ${data.delivery}`;
} else {
joke = data.joke;
}

tellMe(joke);

toggleButton();
} catch (error) {
console.log(error);
}
}

button.addEventListener("click", getJokes);
audioElement.addEventListener("ended", toggleButton);

0 comments on commit 5d816df

Please sign in to comment.