forked from SWC-RCCIIT/STAXLR8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.html
More file actions
152 lines (125 loc) · 3.45 KB
/
speech.html
File metadata and controls
152 lines (125 loc) · 3.45 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Speech</title>
</head>
<body>
<div style="margin-bottom:30px;">
<p id="adding"></p></div>
<div>
<h1>Name:</h1>
<p id="name"></p>
</div>
<div>
<h1>Age:</h1>
<p id="age"></p>
</div>
<div>
<h1>Gender:</h1>
<p id="gender"></p>
</div>
<div>
<h1>Symptoms:</h1>
<p id="symptoms"></p>
</div>
<div>
<h1>Prescirption:</h1>
<p id="prescription"></p>
</div>
<div>
<h1>Advice:</h1>
<p id="advice"></p>
</div>
</body>
<script>
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
let p = document.createElement('p');
const words = document.getElementById('adding');
words.appendChild(p);
let finalTranscript = "";
recognition.onresult=(event) => {
const transcript = Array.from(event.results)
.map(result => result[0]).map(result => result.transcript).join("");
if(event.results[0].isFinal){
findKeyword(transcript);
}
// console.log(finalTranscript);
p.textContent = transcript;
if(event.results[0].isFinal){
p = document.createElement('span');
words.appendChild(p);
}
finalTranscript = transcript;
}
// console.log(finalTranscript);
recognition.onspeechend = function (){
console.log("end");
}
recognition.onend = ()=>{
recognition.start();
// console.log(finalTranscript);
// var t =finalTranscript[0].split(" ");
// console.log(t);
// if(t.includes(name)){
// console.log();
// }
};
recognition.start();
recognition.onsoundstart = function(){
console.log("Listening");
};
recognition.onsoundend = function(){
console.log("stopped");
};
function findKeyword(ts){
const firstWord = ts.split(" ");
keyWord = firstWord[0].toLowerCase();
keyIndex = keyWord.length;
console.log(keyWord);
if(keyWord == 'neem' || keyWord == 'name'){
buildName(ts.substring(keyIndex));
}
if(keyWord == 'age'){
buildAge(ts.substring(keyIndex));
}
if(keyWord == 'diagnosis' || keyWord== 'digonosis '){
buildAge(ts.substring(keyIndex));
}
if(keyWord == 'gender'){
buildGender(ts.substring(keyIndex));
}
if(keyWord == 'symptom' || keyWord == 'symptoms'){
buildSymptoms(ts.substring(keyIndex));
}
if(keyWord == 'prescription' || keyWord == 'prescription'){
buildPrescription(ts.substring(keyIndex));
}
if(keyWord == 'advice' || keyWord == 'advise ' || keyWord == 'vice' || keyWord == 'adwise'){
buildAdvice(ts.substring(keyIndex));
}
};
function buildName(string){
document.getElementById('name').innerText = string;
}
function buildAge(string){
document.getElementById('age').innerText = string;
}
function buildGender(string){
document.getElementById('gender').innerText = string;
}
function buildSymptoms(string){
document.getElementById('symptoms').innerText = string;
}
function buildPrescription(string){
document.getElementById('prescription').innerText = string;
}
function buildAdvice(string){
document.getElementById('advice').innerText = string;
}
</script>
</html>