-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoiceInput_voicenavigation_lme.html
327 lines (306 loc) · 11.9 KB
/
voiceInput_voicenavigation_lme.html
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customer Onboarding</title>
<!-- Link to Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #121212;
color: #ffffff;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 50px auto;
background-color: #1e1e1e;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
border-radius: 10px;
}
h2 {
color: #ffffff;
font-size: 24px;
margin-bottom: 20px;
}
.progress-bar {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.progress-bar div {
width: 20%;
height: 4px;
background-color: #333;
border-radius: 2px;
}
.progress-bar .active {
background-color: #00ffcc;
}
.field {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-size: 16px;
color: #cccccc;
}
input[type="text"] {
width: 100%;
padding: 12px;
font-size: 16px;
border: 1px solid #333;
background-color: #222;
color: #ffffff;
border-radius: 5px;
box-sizing: border-box;
}
.voice-input-container {
display: flex;
align-items: center;
position: relative;
}
.voice-input-container input[type="text"] {
padding-right: 40px;
}
.voice-icon {
position: absolute;
right: 10px;
font-size: 1.5em;
color: #00ffcc;
cursor: pointer;
}
.action-button {
background-color: #00ffcc;
color: #121212;
border: none;
padding: 12px 20px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
width: 100%;
margin-top: 20px;
transition: background-color 0.3s;
}
.action-button:disabled {
background-color: #00ffcc;
opacity: 0.6;
cursor: not-allowed;
}
.action-button:hover {
background-color: #00d1b2;
}
#voicePrompt {
font-weight: bold;
color: #00ffcc;
margin-bottom: 20px;
text-align: center;
padding: 0 10px;
}
#loadingIndicator {
border: 4px solid #333;
border-top: 4px solid #00ffcc;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
display: none;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@media (max-width: 600px) {
.container {
margin: 20px;
padding: 15px;
}
h2 {
font-size: 20px;
}
.action-button {
padding: 10px;
font-size: 14px;
}
input[type="text"] {
padding: 10px;
font-size: 14px;
}
}
.language-selector {
margin-bottom: 20px;
text-align: right;
}
</style>
</head>
<body>
<div class="container">
<div class="language-selector">
<label for="language">Choose Language:</label>
<select id="language" onchange="changeLanguage()">
<option value="en">English</option>
<option value="hi">Hindi</option>
</select>
</div>
<h2 id="heading">Customer Onboarding</h2>
<div class="progress-bar">
<div class="active"></div>
<div class="active"></div>
<div class="active"></div>
<div></div>
<div></div>
</div>
<div class="field">
<label for="buildingName" id="buildingNameLabel">What is the customer's resident building/house name:</label>
<div class="voice-input-container">
<input type="text" id="buildingName" disabled>
<i class="fas fa-microphone voice-icon" onclick="startVoiceInput('buildingName')"></i>
</div>
</div>
<div class="field">
<label for="street" id="streetLabel">Which Street the customer is living:</label>
<div class="voice-input-container">
<input type="text" id="street" disabled>
<i class="fas fa-microphone voice-icon" onclick="startVoiceInput('street')"></i>
</div>
</div>
<div class="field">
<label for="city" id="cityLabel">Enter Customer's City Name:</label>
<div class="voice-input-container">
<input type="text" id="city" disabled>
<i class="fas fa-microphone voice-icon" onclick="startVoiceInput('city')"></i>
</div>
</div>
<div id="voicePrompt">Initializing voice input...</div>
<div id="loadingIndicator"></div>
<button class="action-button" id="startButton">Start Voice Navigation</button>
</div>
<script>
const languages = {
en: {
heading: "Customer Onboarding",
buildingName: "What is the customer's resident building/house name:",
street: "Which Street the customer is living:",
city: "Enter Customer's City Name:",
startButton: "Start Voice Navigation",
prompts: [
'Please say your resident building or house name.',
'Please say the street you live on.',
'Please say your city name.'
],
voiceInit: 'Initializing voice input...',
thankYou: 'Thank you! All details have been captured.'
},
hi: {
heading: "ग्राहक ऑनबोर्डिंग",
buildingName: "ग्राहक के निवास भवन/घर का नाम क्या है:",
street: "जिस सड़क पर ग्राहक रह रहा है:",
city: "कृपया ग्राहक का शहर का नाम दर्ज करें:",
startButton: "वॉयस नेविगेशन शुरू करें",
prompts: [
'कृपया अपने निवास भवन या घर का नाम बताएं।',
'कृपया वह सड़क बताएं जिस पर आप रहते हैं।',
'कृपया अपना शहर का नाम बताएं।'
],
voiceInit: 'वॉयस इनपुट प्रारंभ कर रहा है...',
thankYou: 'धन्यवाद! सभी विवरण कैप्चर किए जा चुके हैं।'
}
};
let currentLanguage = 'en';
const fields = [
{ id: 'buildingName', promptIndex: 0 },
{ id: 'street', promptIndex: 1 },
{ id: 'city', promptIndex: 2 }
];
let currentFieldIndex = 0;
const voicePrompt = document.getElementById('voicePrompt');
const loadingIndicator = document.getElementById('loadingIndicator');
const startButton = document.getElementById('startButton');
function changeLanguage() {
currentLanguage = document.getElementById('language').value;
updateContent();
}
function updateContent() {
const lang = languages[currentLanguage];
document.getElementById('heading').textContent = lang.heading;
document.getElementById('buildingNameLabel').textContent = lang.buildingName;
document.getElementById('streetLabel').textContent = lang.street;
document.getElementById('cityLabel').textContent = lang.city;
startButton.textContent = lang.startButton;
voicePrompt.textContent = lang.voiceInit;
}
function updateProgress() {
const progressBars = document.querySelectorAll('.progress-bar div');
progressBars.forEach((bar, index) => {
if (index <= currentFieldIndex) {
bar.classList.add('active');
} else {
bar.classList.remove('active');
}
});
}
function speakText(text) {
if ('speechSynthesis' in window) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = currentLanguage === 'hi' ? 'hi-IN' : 'en-US';
utterance.onend = function() {
startVoiceInput(fields[currentFieldIndex].id);
};
window.speechSynthesis.speak(utterance);
} else {
console.error('Speech Synthesis API is not supported in this browser.');
voicePrompt.textContent = text;
startVoiceInput(fields[currentFieldIndex].id);
}
}
function startVoiceInput(fieldId) {
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'en-US'; // Always capture input in English
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.start();
loadingIndicator.style.display = 'block';
recognition.onresult = function(event) {
const transcript = event.results[0][0].transcript;
document.getElementById(fieldId).value = transcript;
loadingIndicator.style.display = 'none';
new Audio('https://www.soundjay.com/button/beep-07.wav').play();
moveToNextField();
};
recognition.onerror = function(event) {
voicePrompt.textContent = 'Sorry, I didn\'t catch that. Please try again.';
loadingIndicator.style.display = 'none';
startVoiceInput(fieldId);
};
}
function moveToNextField() {
if (currentFieldIndex < fields.length - 1) {
currentFieldIndex++;
const nextField = document.getElementById(fields[currentFieldIndex].id);
nextField.disabled = false;
nextField.focus();
voicePrompt.textContent = languages[currentLanguage].prompts[currentFieldIndex];
speakText(languages[currentLanguage].prompts[currentFieldIndex]);
updateProgress();
} else {
voicePrompt.textContent = languages[currentLanguage].thankYou;
loadingIndicator.style.display = 'none';
}
}
startButton.addEventListener('click', function() {
document.getElementById(fields[currentFieldIndex].id).disabled = false;
voicePrompt.textContent = languages[currentLanguage].prompts[currentFieldIndex];
speakText(languages[currentLanguage].prompts[currentFieldIndex]);
updateProgress();
});
// Initialize the first content in the selected language
updateContent();
</script>
</body>
</html>