atlury commited on
Commit
5e1a7ec
·
verified ·
1 Parent(s): 50468cb

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +21 -3
index.html CHANGED
@@ -188,6 +188,8 @@
188
  let bars;
189
  let animationId;
190
  let isListening = false;
 
 
191
 
192
  function createVisualizer() {
193
  const barCount = 64;
@@ -295,9 +297,9 @@
295
  }
296
  });
297
 
298
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
299
- const source = audioContext.createMediaStreamSource(stream);
300
- source.connect(analyser);
301
 
302
  await myvad.start();
303
  startButton.textContent = 'End Call';
@@ -316,6 +318,22 @@
316
  isListening = false;
317
  addLog('System: Stopped listening.');
318
  cancelAnimationFrame(animationId);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  addLog('websocket closed');
320
  }
321
  }
 
188
  let bars;
189
  let animationId;
190
  let isListening = false;
191
+ let mediaStream;
192
+ let audioSource;
193
 
194
  function createVisualizer() {
195
  const barCount = 64;
 
297
  }
298
  });
299
 
300
+ mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
301
+ audioSource = audioContext.createMediaStreamSource(mediaStream);
302
+ audioSource.connect(analyser);
303
 
304
  await myvad.start();
305
  startButton.textContent = 'End Call';
 
318
  isListening = false;
319
  addLog('System: Stopped listening.');
320
  cancelAnimationFrame(animationId);
321
+
322
+ // Stop all tracks in the media stream
323
+ if (mediaStream) {
324
+ mediaStream.getTracks().forEach(track => track.stop());
325
+ }
326
+
327
+ // Disconnect the audio source from the analyser
328
+ if (audioSource) {
329
+ audioSource.disconnect();
330
+ }
331
+
332
+ // Close the audio context
333
+ if (audioContext) {
334
+ await audioContext.close();
335
+ }
336
+
337
  addLog('websocket closed');
338
  }
339
  }