-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (38 loc) · 1.08 KB
/
script.js
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
const btn = document.querySelector('.talk')
const end = document.querySelector('.end')
const instructions = document.getElementById('instructions')
const content = document.querySelector('.content')
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
const recognition = new SpeechRecognition()
var speech = ''
recognition.onstart= function()
{
instructions.innerText = "Recognition is on\n Press Button to Stop"
btn.style.display = "none"
end.style.display = "block"
}
recognition.onspeechend = function()
{
instructions.text("No activity")
recognition.stop()
}
recognition.onerror = function()
{
instructions.text("Try Again")
}
recognition.continuous = true
recognition.onresult = function(event)
{
const current = event.resultIndex
const transcript = event.results[current][0].transcript
speech += transcript
content.innerText = speech
console.log(transcript)
}
btn.addEventListener('click' ,() => {
recognition.start()
})
end.addEventListener('click' ,() => {
recognition.stop()
window.location.reload()
})