SpeechRecognition Day 20 of 30.
This commit is contained in:
parent
73fd3627c4
commit
e2fae631c2
89
Speech Detection [20-30]/index.html
Normal file
89
Speech Detection [20-30]/index.html
Normal file
@ -0,0 +1,89 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Speech Detection</title>
|
||||
<link rel="icon" href="https://fav.farm/🔥" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="words" contenteditable>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
const recognition = new SpeechRecognition();
|
||||
recognition.interimResults = true;
|
||||
recognition.lang = 'en-US';
|
||||
|
||||
let p = document.createElement('p');
|
||||
const words = document.querySelector('.words');
|
||||
words.appendChild(p);
|
||||
|
||||
recognition.addEventListener('result', e => {
|
||||
const transcript = Array.from(e.results)
|
||||
.map(result => result[0])
|
||||
.map(result => result.transcript)
|
||||
.join('');
|
||||
|
||||
const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
|
||||
p.textContent = poopScript;
|
||||
|
||||
if (e.results[0].isFinal) {
|
||||
p = document.createElement('p');
|
||||
words.appendChild(p);
|
||||
}
|
||||
});
|
||||
|
||||
recognition.addEventListener('end', recognition.start);
|
||||
|
||||
recognition.start();
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<style>
|
||||
html {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
body {
|
||||
background: #ffc600;
|
||||
font-family: 'helvetica neue';
|
||||
font-weight: 200;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.words {
|
||||
max-width: 500px;
|
||||
margin: 50px auto;
|
||||
background: white;
|
||||
border-radius: 5px;
|
||||
box-shadow: 10px 10px 0 rgba(0,0,0,0.1);
|
||||
padding: 1rem 2rem 1rem 5rem;
|
||||
background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px;
|
||||
background-size: 100% 3rem;
|
||||
position: relative;
|
||||
line-height: 3rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0 0 3rem;
|
||||
}
|
||||
|
||||
.words:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 4px;
|
||||
top: 0;
|
||||
left: 30px;
|
||||
bottom: 0;
|
||||
border: 1px solid;
|
||||
border-color: transparent #efe4e4;
|
||||
}
|
||||
</style>
|
||||
|
||||
</body>
|
||||
</html>
|
14
Speech Detection [20-30]/package.json
Normal file
14
Speech Detection [20-30]/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "gum",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "scripts.js",
|
||||
"scripts": {
|
||||
"start": "browser-sync start --directory --server --files \"*.css, *.html, *.js\""
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"browser-sync": "^2.12.5 <2.23.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user