-
Notifications
You must be signed in to change notification settings - Fork 5
/
speechRecognition.jade
40 lines (28 loc) · 1.02 KB
/
speechRecognition.jade
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
extends base
block vars
- var title = 'Speech Recognition'
block styles
link(rel="stylesheet" type="text/css" href="styles/speechRecognition.css")
block body
.words(contenteditable)
script(type="text/javascript").
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
const recognition = new SpeechRecognition()
recognition.interimResults = true
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 modifiedScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
$p.textContent = modifiedScript
if (e.results[0].isFinal) {
$p = document.createElement('p')
$words.appendChild($p)
}
})
recognition.addEventListener('end', recognition.start)
recognition.start()