-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
214 lines (190 loc) Β· 8.18 KB
/
script.js
File metadata and controls
214 lines (190 loc) Β· 8.18 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const languages = {
1: { name: "English", code: "en-IN" },
2: { name: "Hindi", code: "en-IN" },
3: { name: "Tamil", code: "en-IN" },
4: { name: "Telugu", code: "en-IN" },
5: { name: "Kannada", code: "en-IN" },
6: { name: "Malayalam", code: "en-IN" },
7: { name: "Bengali", code: "en-IN" },
8: { name: "Marathi", code: "en-IN" },
9: { name: "Gujarati", code: "en-IN" }
};
const features = {
1: "Show Nearby Hospitals",
2: "Free Government Health Schemes Information",
3: "Medicine Availability",
4: "Vaccine Availability",
5: "Emergency Services",
6: "Medical News",
};
const nearbyHospitals = [
{ name: "J.M Urgent Care Hospital", location: "Anna Nagar, Kinathukadavu, Tamil Nadu" },
{ name: "Sri Venkateshwara Hospital", location: "Pollachi Main Rd, Kinathukadavu, Tamil Nadu" },
{ name: "SV Medical Center", location: "Pollachi Main Rd, Kinathukadavu, Tamil Nadu" },
];
let step = 1;
let selectedLanguage = 1;
function speak(text, callback = null) {
speechSynthesis.cancel(); // Stop any ongoing speech
const utterance = new SpeechSynthesisUtterance(text);
const langCode = languages[selectedLanguage]?.code || "en-IN";
utterance.lang = langCode;
const voices = speechSynthesis.getVoices();
const matchingVoices = voices.filter(v => v.lang === langCode);
if (matchingVoices.length > 0) {
utterance.voice = matchingVoices[0];
} else {
console.warn(`No voice found for ${langCode}, using default.`);
utterance.voice = voices.find(v => v.lang.startsWith("en")) || voices[0];
}
if (callback) utterance.onend = callback;
speechSynthesis.speak(utterance);
}
function announceLanguages() {
let message = "Welcome to the Medical IVR System. Please select your language. ";
for (let i = 1; i <= 9; i++) {
message += `For ${languages[i].name}, press ${i}. `;
}
speak(message);
}
function checkMedicineAvailability() {
const message = "Common medicines like Paracetamol, Ibuprofen, and Amoxicillin are usually available in your nearby pharmacies. For accurate availability, please consult your local chemist or use a pharmacy app.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function checkVaccineAvailability() {
const message = "COVID-19 vaccines, Hepatitis, and Flu vaccines are generally available at government health centers and selected private hospitals. You can check availability through the CoWIN portal or local health department.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function emergencyServicesInfo() {
const message = "For emergency services: Ambulance - dial 108, Police - 100, Fire - 101. Please stay calm and provide accurate information when you call.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function provideMedicalNews() {
const message = "Here are some recent updates: The World Health Organization warns of rising flu cases this season. A new vaccine for dengue is under trial. Visit verified news sources or health ministry sites for more updates.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function announceFeatures() {
let message = "Please select a service. ";
for (let i = 1; i <= 6; i++) { // Update loop to include the 12 features
message += `To ${features[i]}, press ${i}. `;
}
speak(message);
}
function showNearbyHospitals() {
const output = document.getElementById("output");
let message = "Here are some nearby hospitals: ";
nearbyHospitals.forEach(hospital => {
message += `${hospital.name} located in ${hospital.location}. `;
});
output.innerHTML = `<strong>Nearby Hospitals:</strong><br>${nearbyHospitals.map(h => `${h.name} (${h.location})`).join('<br>')}`;
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
output.innerHTML += "<br><br>Starting over...";
announceLanguages();
});
}
function provideHealthSchemesInfo() {
const message = "Here is the information on Free Government Health Schemes: There are several government schemes available to the public, including Ayushman Bharat, Jan Arogya Yojana, and others aimed at providing affordable healthcare for rural and underserved areas.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
// Simple predefined features:
function provideHealthTips() {
const message = "Here are some general health tips: Eat balanced meals, drink plenty of water, get regular exercise, and avoid stress.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function contactEmergencyServices() {
const message = "For emergency services, you can contact the following numbers: Ambulance - 108, Fire Service - 101, Police - 100.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function healthTipsForAilments() {
const message = "Here are health tips for common ailments: For a cold, drink warm fluids and rest. For a headache, avoid bright lights and stay hydrated.";
speak(message, () => {
step = 1;
document.getElementById("title").innerText = "π Select Your Language";
document.getElementById("output").innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
});
}
function handleKey(key) {
const output = document.getElementById("output");
const title = document.getElementById("title");
if (step === 1) {
selectedLanguage = key;
const langName = languages[selectedLanguage]?.name || "English";
const msg = `You selected ${langName}. Now, here are the services available.`;
output.innerHTML = `β
Language selected: <strong>${langName}</strong><br><br>π Listen to the services...`;
title.innerText = "Select a Feature";
speak(msg, () => {
announceFeatures();
step = 2;
});
} else if (step === 2) {
const feature = features[key];
const msg = `You selected ${feature}. Processing your request.`;
output.innerHTML += `<br><br>β
Feature selected: <strong>${feature}</strong><br><br>π² Processing your request...`;
speak(msg, () => {
if (key === 1) {
showNearbyHospitals();
} else if (key === 2) {
provideHealthSchemesInfo();
} else if (key === 3) {
checkMedicineAvailability();
} else if (key === 4) {
checkVaccineAvailability();
} else if (key === 5) {
emergencyServicesInfo();
} else if (key === 6) {
provideMedicalNews();
} else {
// Handle under-development features if you expand later
step = 1;
title.innerText = "π This feature is under Development";
output.innerHTML += "<br><br>Returning to main menu...";
announceLanguages();
}
});
}
}
// Ensure voices load correctly (especially in Chrome)
window.onload = () => {
speechSynthesis.onvoiceschanged = () => {
speechSynthesis.getVoices(); // Force-load voices
};
announceLanguages();
};