atlury commited on
Commit
a40f740
·
verified ·
1 Parent(s): b38b144

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +19 -9
index.html CHANGED
@@ -333,17 +333,27 @@
333
 
334
  async function stopListening() {
335
  if (myvad) {
336
- await myvad.stop();
337
- if (microphoneStream) {
338
- microphoneStream.getTracks().forEach(track => track.stop());
 
339
  }
340
- stopCurrentAudio();
341
- startButton.textContent = 'Begin Call';
342
- isListening = false;
343
- addLog('System: Stopped listening.');
344
- cancelAnimationFrame(animationId);
345
- addLog('System: Microphone closed');
346
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  }
348
 
349
  startButton.addEventListener('click', toggleListening);
 
333
 
334
  async function stopListening() {
335
  if (myvad) {
336
+ try {
337
+ await myvad.destroy();
338
+ } catch (error) {
339
+ console.error('Error stopping VAD:', error);
340
  }
341
+ myvad = null;
 
 
 
 
 
342
  }
343
+ if (microphoneStream) {
344
+ microphoneStream.getTracks().forEach(track => track.stop());
345
+ microphoneStream = null;
346
+ }
347
+ if (audioContext) {
348
+ await audioContext.close();
349
+ audioContext = null;
350
+ }
351
+ stopCurrentAudio();
352
+ startButton.textContent = 'Begin Call';
353
+ isListening = false;
354
+ addLog('System: Stopped listening.');
355
+ cancelAnimationFrame(animationId);
356
+ addLog('System: Microphone closed');
357
  }
358
 
359
  startButton.addEventListener('click', toggleListening);