-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
23 lines (18 loc) · 775 Bytes
/
main.js
File metadata and controls
23 lines (18 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
recognition.lang = 'en-US';
const words = document.querySelector('.words');
let p = document.createElement('p');
words.appendChild(p);
recognition.addEventListener('result', e => {
const transcript = Array.from(e.results).map(result => result[0]).map(result => result.transcript).join('');
const loveScript = transcript.replace(/khushi|anshika|shukla|parmar/gi, '💞❤️💕');
p.textContent = loveScript;
if(e.results[0].isFinal) {
p = document.createElement('p');
words.append(p);
}
})
recognition.addEventListener('end', recognition.start);
recognition.start();