unknown262007 commited on
Commit
7fb4a00
·
verified ·
1 Parent(s): 1639d97

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +116 -19
index.html CHANGED
@@ -1,19 +1,116 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Smart Earbud Volume Controller</title>
7
+ <!-- ONNX Runtime Web for running Silero VAD locally in browser -->
8
+ <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js"></script>
9
+ <!-- ONNX VAD Helper library -->
10
+ <script src="https://cdn.jsdelivr.net/npm/@vapi-ai/vads-web/dist/index.umd.js"></script>
11
+ <style>
12
+ body {
13
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14
+ background-color: #0f172a;
15
+ color: #f8fafc;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ min-height: 100vh;
20
+ margin: 0;
21
+ }
22
+ .card {
23
+ background-color: #1e293b;
24
+ padding: 2rem;
25
+ border-radius: 12px;
26
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
27
+ max-width: 450px;
28
+ width: 100%;
29
+ text-align: center;
30
+ }
31
+ button {
32
+ background-color: #3b82f6;
33
+ color: white;
34
+ border: none;
35
+ padding: 0.75rem 1.5rem;
36
+ font-size: 1rem;
37
+ font-weight: 600;
38
+ border-radius: 8px;
39
+ cursor: pointer;
40
+ margin-bottom: 1rem;
41
+ transition: background-color 0.2s;
42
+ }
43
+ button:hover { background-color: #2563eb; }
44
+ button:disabled { background-color: #64748b; cursor: not-allowed; }
45
+ .status-box {
46
+ margin-top: 1.5rem;
47
+ padding: 1rem;
48
+ border-radius: 8px;
49
+ background-color: #334155;
50
+ font-weight: 500;
51
+ }
52
+ .speaking { background-color: #991b1b; color: #fca5a5; }
53
+ .silent { background-color: #065f46; color: #a7f3d0; }
54
+ audio { width: 100%; margin-top: 1rem; }
55
+ </style>
56
+ </head>
57
+ <body>
58
+
59
+ <div class="card">
60
+ <h2>Auto-Ducking Earbud Simulator</h2>
61
+ <p>Play audio below, then start the microphone. When speech is detected, audio volume will automatically drop.</p>
62
+
63
+ <audio id="audioPlayer" controls loop src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"></audio>
64
+
65
+ <br/><br/>
66
+ <button id="startBtn">Start Voice Detection</button>
67
+
68
+ <div id="status" class="status-box silent">Status: Inactive</div>
69
+ </div>
70
+
71
+ <script>
72
+ let vad;
73
+ const audioPlayer = document.getElementById('audioPlayer');
74
+ const startBtn = document.getElementById('startBtn');
75
+ const statusDiv = document.getElementById('status');
76
+
77
+ let restoreTimeout;
78
+
79
+ startBtn.addEventListener('click', async () => {
80
+ try {
81
+ startBtn.disabled = true;
82
+ startBtn.innerText = "Initializing VAD...";
83
+
84
+ // Initialize VAD Engine
85
+ vad = await vad.MicVAD.new({
86
+ onSpeechStart: () => {
87
+ statusDiv.innerText = "Speech Detected: Lowering Volume";
88
+ statusDiv.className = "status-box speaking";
89
+ audioPlayer.volume = 0.2; // DUCK VOLUME (20%)
90
+ if (restoreTimeout) clearTimeout(restoreTimeout);
91
+ },
92
+ onSpeechEnd: () => {
93
+ statusDiv.innerText = "Silence: Restoring Volume soon...";
94
+ // Hold lower volume for 1.5s after speech stops
95
+ restoreTimeout = setTimeout(() => {
96
+ audioPlayer.volume = 1.0; // RESTORE VOLUME (100%)
97
+ statusDiv.innerText = "Monitoring Environment...";
98
+ statusDiv.className = "status-box silent";
99
+ }, 1500);
100
+ }
101
+ });
102
+
103
+ vad.start();
104
+ startBtn.innerText = "Listening...";
105
+ statusDiv.innerText = "Monitoring Environment...";
106
+ } catch (e) {
107
+ console.error(e);
108
+ alert("Microphone access denied or error loading model.");
109
+ startBtn.disabled = false;
110
+ startBtn.innerText = "Start Voice Detection";
111
+ }
112
+ });
113
+ </script>
114
+
115
+ </body>
116
+ </html>