Skip to content

Commit 3508a2c

Browse files
author
vanntile
committed
Day 20 - N/A
1 parent bf933b5 commit 3508a2c

5 files changed

Lines changed: 85 additions & 62 deletions

File tree

20 - Speech Detection/index-START.html

Lines changed: 0 additions & 61 deletions
This file was deleted.

20 - Speech Detection/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Speech Detection</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
10+
<body>
11+
12+
<div class="words" contenteditable>
13+
</div>
14+
<script src="script.js"></script>
15+
16+
</body>
17+
18+
</html>

20 - Speech Detection/script.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
2+
3+
const recognition = new SpeechRecognition();
4+
recognition.interimResults = true;
5+
recognition.lang = 'en-US';
6+
7+
let p = document.createElement('p');
8+
const words = document.querySelector('.words');
9+
words.appendChild(p);
10+
11+
recognition.addEventListener('result', e => {
12+
const transcript = Array.from(e.results)
13+
.map(result => result[0])
14+
.map(result => result.transcript)
15+
.join('');
16+
17+
const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
18+
p.textContent = poopScript;
19+
20+
if (e.results[0].isFinal) {
21+
p = document.createElement('p');
22+
words.appendChild(p);
23+
}
24+
});
25+
26+
recognition.addEventListener('end', recognition.start);
27+
28+
recognition.start();

20 - Speech Detection/style.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
html {
2+
font-size: 10px;
3+
}
4+
5+
body {
6+
background: #ffc600;
7+
font-family: 'helvetica neue';
8+
font-weight: 200;
9+
font-size: 20px;
10+
}
11+
12+
.words {
13+
max-width: 500px;
14+
margin: 50px auto;
15+
background: white;
16+
border-radius: 5px;
17+
box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.1);
18+
padding: 1rem 2rem 1rem 5rem;
19+
background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px;
20+
background-size: 100% 3rem;
21+
position: relative;
22+
line-height: 3rem;
23+
}
24+
25+
p {
26+
margin: 0 0 3rem;
27+
}
28+
29+
.words:before {
30+
content: '';
31+
position: absolute;
32+
width: 4px;
33+
top: 0;
34+
left: 30px;
35+
bottom: 0;
36+
border: 1px solid;
37+
border-color: transparent #efe4e4;
38+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Check the course at [https://JavaScript30.com](https://JavaScript30.com)
3737
18. [x] [Adding Up Times with Reduce](https://vanntile.github.io/JavaScript30/18%20-%20Adding%20Up%20Times%20with%20Reduce)
3838
19. [x] [Webcam Fun](https://vanntile.github.io/JavaScript30/19%20-%20Webcam%20Fun)
3939
and my [notes](./19%20-%20Webcam%20Fun)
40-
20. [ ] Speech Detection
40+
20. [ ] Speech Detection (not working in browsers for now)
4141
21. [ ] Geolocation
4242
22. [ ] Follow Along Link Highlighter
4343
23. [ ] Speech Synthesis

0 commit comments

Comments
 (0)