- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
50 lines (44 loc) · 1.31 KB
/
Copy pathscript.js
File metadata and controls
50 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
constbutton=document.getElementById('button');
constaudioElement=document.getElementById('audio')
// Disabled / Enable button
functiontoggleButton(){
button.disabled=!button.disabled;
}
//Passing jokes to VoiceRSS API
functiontellMe(joke){
constjokeString=joke.trim().replace(//g,'%20');
VoiceRSS.speech({
key:'c7215ab6224340e4ad49e70b8c7bec8b',
src: `"The joke is " ${jokeString}`,
hl: 'en-us',
v: 'Linda',
r: 0,
c: 'mp3',
f: '44khz_16bit_stereo',
ssml: false
});
}
// Get Jokes from Joke API
asyncfunctiongetJokes(){
letjoke='';
constjokeApiUrl='https://sv443.net/jokeapi/v2/joke/Programming?blacklistFlags=nsfw,religious,political,racist,sexist';
try{
constresponse=awaitfetch(jokeApiUrl);
constdata=awaitresponse.json();
if(data.setup){
joke=`${data.setup} ... ${data.delivery}`
}else{
joke=data.joke;
}
//Text-to-Speech
tellMe(joke);
console.log(joke);
// Disable button
toggleButton();
}catch(error){
console.log('whoops! something went wrong',error)
}
}
//Add Event Listerns
button.addEventListener('click',getJokes);
audioElement.addEventListener('ended',toggleButton);