atlury commited on
Commit
a483b2a
·
verified ·
1 Parent(s): 0eb6a81

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +16 -5
index.html CHANGED
@@ -187,6 +187,7 @@
187
  let dataArray;
188
  let bars;
189
  let animationId;
 
190
 
191
  function createVisualizer() {
192
  const barCount = 64;
@@ -265,6 +266,16 @@
265
  source.start();
266
  }
267
 
 
 
 
 
 
 
 
 
 
 
268
  async function startListening() {
269
  try {
270
  audioContext = new (window.AudioContext || window.webkitAudioContext)();
@@ -290,7 +301,7 @@
290
 
291
  await myvad.start();
292
  startButton.textContent = 'End Call';
293
- startButton.onclick = stopListening;
294
  addLog('System: Listening...');
295
  } catch (error) {
296
  console.error('Error starting VAD:', error);
@@ -298,18 +309,18 @@
298
  }
299
  }
300
 
301
- function stopListening() {
302
  if (myvad) {
303
- myvad.pause();
304
  startButton.textContent = 'Begin Call';
305
- startButton.onclick = startListening;
306
  addLog('System: Stopped listening.');
307
  cancelAnimationFrame(animationId);
308
  addLog('websocket closed');
309
  }
310
  }
311
 
312
- startButton.addEventListener('click', startListening);
313
  clearLogsButton.addEventListener('click', () => {
314
  logsDiv.innerHTML = '';
315
  });
 
187
  let dataArray;
188
  let bars;
189
  let animationId;
190
+ let isListening = false;
191
 
192
  function createVisualizer() {
193
  const barCount = 64;
 
266
  source.start();
267
  }
268
 
269
+
270
+ async function toggleListening() {
271
+ if (isListening) {
272
+ await stopListening();
273
+ } else {
274
+ await startListening();
275
+ }
276
+ }
277
+
278
+
279
  async function startListening() {
280
  try {
281
  audioContext = new (window.AudioContext || window.webkitAudioContext)();
 
301
 
302
  await myvad.start();
303
  startButton.textContent = 'End Call';
304
+ isListening = true;
305
  addLog('System: Listening...');
306
  } catch (error) {
307
  console.error('Error starting VAD:', error);
 
309
  }
310
  }
311
 
312
+ async function stopListening() {
313
  if (myvad) {
314
+ await myvad.pause();
315
  startButton.textContent = 'Begin Call';
316
+ isListening = false;
317
  addLog('System: Stopped listening.');
318
  cancelAnimationFrame(animationId);
319
  addLog('websocket closed');
320
  }
321
  }
322
 
323
+ startButton.addEventListener('click', toggleListening);
324
  clearLogsButton.addEventListener('click', () => {
325
  logsDiv.innerHTML = '';
326
  });