freddyaboulton HF staff commited on
Commit
d75ee3c
·
verified ·
1 Parent(s): adc5c1c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +90 -6
index.html CHANGED
@@ -104,6 +104,49 @@
104
  opacity: 0.9;
105
  transform: translateY(-1px);
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  </style>
108
  </head>
109
 
@@ -166,6 +209,26 @@
166
  boxContainer.appendChild(box);
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  async function setupWebRTC() {
170
  const config = __RTC_CONFIGURATION__;
171
  peerConnection = new RTCPeerConnection(config);
@@ -175,11 +238,34 @@
175
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
176
  stream.getTracks().forEach(track => peerConnection.addTrack(track, stream));
177
 
 
178
  audioContext = new AudioContext();
179
- analyser = audioContext.createAnalyser();
180
- analyser.fftSize = 64;
181
- analyser.smoothingTimeConstant = 0.8;
182
- dataArray = new Uint8Array(analyser.frequencyBinCount);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
  // Handle incoming audio
185
  peerConnection.addEventListener('track', (evt) => {
@@ -283,11 +369,9 @@
283
  startButton.addEventListener('click', () => {
284
  if (!isRecording) {
285
  setupWebRTC();
286
- startButton.textContent = 'Stop Recording';
287
  startButton.classList.add('recording');
288
  } else {
289
  stopWebRTC();
290
- startButton.textContent = 'Start Recording';
291
  startButton.classList.remove('recording');
292
  }
293
  isRecording = !isRecording;
 
104
  opacity: 0.9;
105
  transform: translateY(-1px);
106
  }
107
+
108
+ .icon-with-spinner {
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: center;
112
+ gap: 12px;
113
+ min-width: 180px;
114
+ }
115
+
116
+ .spinner {
117
+ width: 20px;
118
+ height: 20px;
119
+ border: 2px solid white;
120
+ border-top-color: transparent;
121
+ border-radius: 50%;
122
+ animation: spin 1s linear infinite;
123
+ flex-shrink: 0;
124
+ }
125
+
126
+ @keyframes spin {
127
+ to {
128
+ transform: rotate(360deg);
129
+ }
130
+ }
131
+
132
+ .pulse-container {
133
+ display: flex;
134
+ align-items: center;
135
+ justify-content: center;
136
+ gap: 12px;
137
+ min-width: 180px;
138
+ }
139
+
140
+ .pulse-circle {
141
+ width: 20px;
142
+ height: 20px;
143
+ border-radius: 50%;
144
+ background-color: white;
145
+ opacity: 0.2;
146
+ flex-shrink: 0;
147
+ transform: translateX(-0%) scale(var(--audio-level, 1));
148
+ transition: transform 0.1s ease;
149
+ }
150
  </style>
151
  </head>
152
 
 
209
  boxContainer.appendChild(box);
210
  }
211
 
212
+ function updateButtonState() {
213
+ if (peerConnection && (peerConnection.connectionState === 'connecting' || peerConnection.connectionState === 'new')) {
214
+ startButton.innerHTML = `
215
+ <div class="icon-with-spinner">
216
+ <div class="spinner"></div>
217
+ <span>Connecting...</span>
218
+ </div>
219
+ `;
220
+ } else if (peerConnection && peerConnection.connectionState === 'connected') {
221
+ startButton.innerHTML = `
222
+ <div class="pulse-container">
223
+ <div class="pulse-circle"></div>
224
+ <span>Stop Recording</span>
225
+ </div>
226
+ `;
227
+ } else {
228
+ startButton.innerHTML = 'Start Recording';
229
+ }
230
+ }
231
+
232
  async function setupWebRTC() {
233
  const config = __RTC_CONFIGURATION__;
234
  peerConnection = new RTCPeerConnection(config);
 
238
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
239
  stream.getTracks().forEach(track => peerConnection.addTrack(track, stream));
240
 
241
+ // Update audio visualization setup
242
  audioContext = new AudioContext();
243
+ analyser_input = audioContext.createAnalyser();
244
+ const source = audioContext.createMediaStreamSource(stream);
245
+ source.connect(analyser_input);
246
+ analyser_input.fftSize = 64;
247
+ dataArray_input = new Uint8Array(analyser_input.frequencyBinCount);
248
+
249
+ function updateAudioLevel() {
250
+ analyser_input.getByteFrequencyData(dataArray_input);
251
+ const average = Array.from(dataArray_input).reduce((a, b) => a + b, 0) / dataArray_input.length;
252
+ const audioLevel = average / 255;
253
+
254
+ const pulseCircle = document.querySelector('.pulse-circle');
255
+ if (pulseCircle) {
256
+ console.log("audioLevel", audioLevel);
257
+ pulseCircle.style.setProperty('--audio-level', 1 + audioLevel);
258
+ }
259
+
260
+ animationId = requestAnimationFrame(updateAudioLevel);
261
+ }
262
+ updateAudioLevel();
263
+
264
+ // Add connection state change listener
265
+ peerConnection.addEventListener('connectionstatechange', () => {
266
+ console.log('connectionstatechange', peerConnection.connectionState);
267
+ updateButtonState();
268
+ });
269
 
270
  // Handle incoming audio
271
  peerConnection.addEventListener('track', (evt) => {
 
369
  startButton.addEventListener('click', () => {
370
  if (!isRecording) {
371
  setupWebRTC();
 
372
  startButton.classList.add('recording');
373
  } else {
374
  stopWebRTC();
 
375
  startButton.classList.remove('recording');
376
  }
377
  isRecording = !isRecording;