-
Notifications
You must be signed in to change notification settings - Fork 0
/
voiceInput.html
174 lines (159 loc) · 5.58 KB
/
voiceInput.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voice Navigation Form</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #1e1e1e;
color: #ffffff;
margin: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 0;
}
h2 {
color: #ffffff;
text-align: center;
margin-bottom: 20px;
font-size: 24px;
}
.field {
margin-bottom: 20px;
font-size: 18px;
width: 100%;
max-width: 400px;
}
label {
display: block;
margin-bottom: 5px;
color: #cccccc;
}
input {
width: 100%;
padding: 12px;
font-size: 16px;
background-color: #333333;
border: 1px solid #444444;
color: #ffffff;
border-radius: 5px;
transition: background-color 0.3s;
}
input:focus {
background-color: #444444;
}
#voicePrompt {
font-weight: bold;
color: #00ffcc;
margin-bottom: 20px;
text-align: center;
padding: 0 10px;
}
input:disabled {
background-color: #2c2c2c;
color: #666666;
}
#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-bottom: 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#progress {
margin-top: 20px;
color: #00ffcc;
text-align: center;
font-size: 16px;
}
</style>
</head>
<body>
<h2>User Address Details</h2>
<div id="voicePrompt">Initializing voice input...</div>
<div id="loadingIndicator"></div>
<div class="field">
<label for="city">City:</label>
<input type="text" id="city" disabled>
</div>
<div class="field">
<label for="street">Street:</label>
<input type="text" id="street" disabled>
</div>
<div class="field">
<label for="nationality">Nationality:</label>
<input type="text" id="nationality" disabled>
</div>
<div class="field">
<label for="birthPlace">Place of Birth:</label>
<input type="text" id="birthPlace" disabled>
</div>
<div id="progress"></div>
<script>
const fields = [
{ id: 'city', prompt: 'Please say your city.' },
{ id: 'street', prompt: 'Please say your street.' },
{ id: 'nationality', prompt: 'Please say your nationality.' },
{ id: 'birthPlace', prompt: 'Please say your place of birth.' }
];
let currentFieldIndex = 0;
const voicePrompt = document.getElementById('voicePrompt');
const loadingIndicator = document.getElementById('loadingIndicator');
const progress = document.getElementById('progress');
function updateProgress() {
progress.textContent = `Step ${currentFieldIndex + 1} of ${fields.length}`;
}
function startVoiceInput() {
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'en-US';
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(fields[currentFieldIndex].id).value = transcript;
loadingIndicator.style.display = 'none';
new Audio('https://www.soundjay.com/button/beep-07.wav').play(); // Feedback sound
moveToNextField();
};
recognition.onerror = function(event) {
voicePrompt.textContent = 'Sorry, I didn\'t catch that. Please try again.';
loadingIndicator.style.display = 'none';
startVoiceInput();
};
}
function moveToNextField() {
if (currentFieldIndex < fields.length - 1) {
currentFieldIndex++;
const nextField = document.getElementById(fields[currentFieldIndex].id);
nextField.disabled = false;
nextField.focus();
voicePrompt.textContent = fields[currentFieldIndex].prompt;
updateProgress();
startVoiceInput();
} else {
voicePrompt.textContent = 'Thank you! All details have been captured.';
loadingIndicator.style.display = 'none';
}
}
// Initialize the first field and start voice input
document.getElementById(fields[currentFieldIndex].id).disabled = false;
voicePrompt.textContent = fields[currentFieldIndex].prompt;
updateProgress();
startVoiceInput();
</script>
</body>
</html>