Spaces:
Running
Running
Upload index.html
Browse files- index.html +63 -0
index.html
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Voice Activity Detection Demo</title>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js"></script>
|
8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
+
<script>
|
10 |
+
ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/';
|
11 |
+
</script>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<main class="flex min-h-screen flex-col items-center justify-between p-24">
|
15 |
+
<div class="text-center">
|
16 |
+
<div id="status" class="text-4xl mb-4">π Not Listening</div>
|
17 |
+
<div id="audioList" class="space-y-4"></div>
|
18 |
+
</div>
|
19 |
+
</main>
|
20 |
+
|
21 |
+
<script type="module">
|
22 |
+
import { SpeechChunks } from './SpeechChunks.js';
|
23 |
+
|
24 |
+
let speechChunks;
|
25 |
+
|
26 |
+
function updateStatus(isListening) {
|
27 |
+
document.getElementById('status').textContent = isListening ? "ποΈ Listening..." : "π Not Listening";
|
28 |
+
}
|
29 |
+
|
30 |
+
function addAudioToList(blob) {
|
31 |
+
const audioList = document.getElementById('audioList');
|
32 |
+
const audio = document.createElement('audio');
|
33 |
+
audio.controls = true;
|
34 |
+
audio.src = URL.createObjectURL(blob);
|
35 |
+
audio.onended = () => URL.revokeObjectURL(audio.src);
|
36 |
+
audioList.appendChild(audio);
|
37 |
+
}
|
38 |
+
|
39 |
+
async function initializeSpeechChunks() {
|
40 |
+
try {
|
41 |
+
speechChunks = new SpeechChunks(
|
42 |
+
() => {
|
43 |
+
console.log("speech start");
|
44 |
+
updateStatus(true);
|
45 |
+
},
|
46 |
+
(blob) => {
|
47 |
+
console.log("speech end");
|
48 |
+
updateStatus(false);
|
49 |
+
addAudioToList(blob);
|
50 |
+
}
|
51 |
+
);
|
52 |
+
await speechChunks.start();
|
53 |
+
} catch (error) {
|
54 |
+
console.error("Error initializing SpeechChunks:", error);
|
55 |
+
updateStatus(false);
|
56 |
+
document.getElementById('status').textContent = "Error: " + error.message;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
initializeSpeechChunks();
|
61 |
+
</script>
|
62 |
+
</body>
|
63 |
+
</html>
|