-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-voice-recognition.html
More file actions
387 lines (330 loc) · 11.2 KB
/
test-voice-recognition.html
File metadata and controls
387 lines (330 loc) · 11.2 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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voice Recognition Tester</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #1a1a1a;
color: #fff;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 800px;
margin: 0 auto;
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
}
h1 {
margin-bottom: 20px;
color: #4fc3f7;
}
.section {
margin-bottom: 20px;
padding: 15px;
background: #333;
border-left: 4px solid #4fc3f7;
border-radius: 4px;
}
.status {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
padding: 10px;
background: #404040;
border-radius: 4px;
}
.status-label {
font-weight: bold;
}
.status-value {
color: #4fc3f7;
}
.status-value.active {
color: #4caf50;
}
.status-value.inactive {
color: #f44336;
}
button {
background-color: #4fc3f7;
color: #000;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
font-size: 14px;
margin: 5px 5px 5px 0;
transition: background-color 0.3s;
}
button:hover {
background-color: #29b6f6;
}
button:active {
transform: scale(0.98);
}
.console {
background: #1a1a1a;
border: 1px solid #4fc3f7;
border-radius: 4px;
padding: 10px;
max-height: 300px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 12px;
margin-top: 10px;
}
.console-entry {
padding: 5px;
border-bottom: 1px solid #333;
}
.console-entry:last-child {
border-bottom: none;
}
.log-info {
color: #4fc3f7;
}
.log-success {
color: #4caf50;
}
.log-error {
color: #f44336;
}
.log-warning {
color: #ff9800;
}
.transcript-display {
background: #404040;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
min-height: 40px;
display: flex;
align-items: center;
}
.test-commands {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
margin-top: 10px;
}
.test-commands button {
font-size: 12px;
padding: 8px 12px;
margin: 0;
}
.clear-btn {
background-color: #f44336;
margin-top: 10px;
}
.clear-btn:hover {
background-color: #da190b;
}
</style>
</head>
<body>
<div class="container">
<h1>🎤 Voice Recognition Tester</h1>
<div class="section">
<h2>Status</h2>
<div class="status">
<span class="status-label">Supported:</span>
<span class="status-value" id="supportStatus">Checking...</span>
</div>
<div class="status">
<span class="status-label">Listening:</span>
<span class="status-value" id="listeningStatus">No</span>
</div>
<div class="status">
<span class="status-label">Last Result:</span>
<span class="status-value" id="lastResult">-</span>
</div>
</div>
<div class="section">
<h2>Controls</h2>
<button onclick="startListening()">Start Listening</button>
<button onclick="stopListening()">Stop Listening</button>
<button onclick="testTranscript()">Test Transcript</button>
</div>
<div class="section">
<h2>Test Voice Commands</h2>
<p>Click to simulate saying these commands:</p>
<div class="test-commands">
<button onclick="simulateVoiceInput('14')">Say "14"</button>
<button onclick="simulateVoiceInput('double 20')">Say "double 20"</button>
<button onclick="simulateVoiceInput('triple 15')">Say "triple 15"</button>
<button onclick="simulateVoiceInput('bullseye')">Say "bullseye"</button>
<button onclick="simulateVoiceInput('bull')">Say "bull"</button>
<button onclick="simulateVoiceInput('miss')">Say "miss"</button>
<button onclick="simulateVoiceInput('undo')">Say "undo"</button>
</div>
</div>
<div class="section">
<h2>Test Transcript Processing</h2>
<input type="text" id="testInput" placeholder="Enter text to test..." style="width: 100%; padding: 8px; background: #404040; color: #fff; border: 1px solid #4fc3f7; border-radius: 4px; margin-bottom: 10px;">
<button onclick="processTestTranscript()">Process Transcript</button>
</div>
<div class="section">
<h2>Console Output</h2>
<div class="console" id="console"></div>
<button class="clear-btn" onclick="clearConsole()">Clear Console</button>
</div>
</div>
<script>
const logs = [];
function log(message, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
const logEntry = `[${timestamp}] ${message}`;
logs.push({ message: logEntry, type });
const console_ = document.getElementById('console');
const entry = document.createElement('div');
entry.className = `console-entry log-${type}`;
entry.textContent = logEntry;
console_.appendChild(entry);
console_.scrollTop = console_.scrollHeight;
}
function clearConsole() {
logs.length = 0;
document.getElementById('console').innerHTML = '';
log('Console cleared', 'info');
}
// Check if browser supports speech recognition
function checkSupport() {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition;
const supported = !!SpeechRecognition;
document.getElementById('supportStatus').textContent = supported ? 'Yes ✓' : 'No ✗';
document.getElementById('supportStatus').className = `status-value ${supported ? 'active' : 'inactive'}`;
if (supported) {
log('Speech Recognition API supported', 'success');
} else {
log('Speech Recognition API NOT supported', 'error');
}
return supported;
}
let recognition = null;
let isListening = false;
function initRecognition() {
if (!checkSupport()) return;
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
recognition = new SpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.lang = 'en-US';
recognition.onstart = () => {
log('Recognition started', 'info');
isListening = true;
document.getElementById('listeningStatus').textContent = 'Yes ✓';
document.getElementById('listeningStatus').className = 'status-value active';
};
recognition.onend = () => {
log('Recognition ended', 'info');
isListening = false;
document.getElementById('listeningStatus').textContent = 'No';
document.getElementById('listeningStatus').className = 'status-value inactive';
};
recognition.onerror = (event) => {
log(`Error: ${event.error}`, 'error');
};
recognition.onresult = (event) => {
const results = event.results;
const lastResult = results[results.length - 1];
const transcript = lastResult[0].transcript;
const isFinal = lastResult.isFinal;
log(`Transcript: "${transcript}" (Final: ${isFinal})`, 'info');
document.getElementById('lastResult').textContent = transcript;
if (isFinal) {
log(`Processing final result: "${transcript}"`, 'success');
processTranscript(transcript);
}
};
}
function startListening() {
if (!recognition) initRecognition();
if (isListening) {
log('Already listening', 'warning');
return;
}
try {
recognition.start();
log('Listening started...', 'info');
} catch (e) {
log(`Error starting: ${e.message}`, 'error');
}
}
function stopListening() {
if (!recognition || !isListening) {
log('Not currently listening', 'warning');
return;
}
try {
recognition.stop();
log('Listening stopped', 'info');
} catch (e) {
log(`Error stopping: ${e.message}`, 'error');
}
}
async function processTranscript(transcript) {
try {
const { processTranscriptEnglish } = await import('./JS/VOICE_TRANSCRIPTION/voice_english.js');
const result = processTranscriptEnglish(transcript.toLowerCase().trim());
log(`Pattern result: "${result}"`, 'success');
} catch (e) {
log(`Error processing: ${e.message}`, 'error');
}
}
function processTestTranscript() {
const input = document.getElementById('testInput').value.trim();
if (!input) {
log('Please enter text to test', 'warning');
return;
}
log(`Testing: "${input}"`, 'info');
processTranscript(input);
}
function simulateVoiceInput(text) {
log(`Simulating voice input: "${text}"`, 'info');
document.getElementById('lastResult').textContent = text;
processTranscript(text);
}
function testTranscript() {
log('Running transcript test...', 'info');
const testCases = [
{ input: '14', expected: 'single-14' },
{ input: 'double 20', expected: 'double-20' },
{ input: 'triple 15', expected: 'triple-15' },
{ input: 'bullseye', expected: 'bulls-eye' },
{ input: 'bull', expected: 'single-bull' },
{ input: 'miss', expected: 'outer-ring' },
{ input: 'undo', expected: 'revert-score' }
];
(async () => {
for (const test of testCases) {
try {
const { processTranscriptEnglish } = await import('./JS/VOICE_TRANSCRIPTION/voice_english.js');
const result = processTranscriptEnglish(test.input);
const status = result === test.expected ? '✓' : '✗';
log(`${status} "${test.input}" → "${result}" (expected: "${test.expected}")`, result === test.expected ? 'success' : 'error');
} catch (e) {
log(`Error testing "${test.input}": ${e.message}`, 'error');
}
}
})();
}
// Initialize on load
window.onload = () => {
log('Voice Recognition Tester loaded', 'info');
initRecognition();
};
</script>
</body>
</html>