Spaces:
Paused
Paused
Update script1.js
Browse files- script1.js +8 -2
script1.js
CHANGED
|
@@ -14,6 +14,7 @@ let completeTranscript = '';
|
|
| 14 |
let isRequestInProgress = false;
|
| 15 |
let isUserSpeaking = false;
|
| 16 |
let isSpeechRecognitionActive = false;
|
|
|
|
| 17 |
let requestAbortController = null;
|
| 18 |
let partialTranscript = '';
|
| 19 |
let lastUserSpeechTimestamp = null;
|
|
@@ -442,17 +443,22 @@ if ('webkitSpeechRecognition' in window) {
|
|
| 442 |
completeTranscript = '';
|
| 443 |
}
|
| 444 |
|
| 445 |
-
if
|
|
|
|
|
|
|
|
|
|
| 446 |
};
|
| 447 |
|
| 448 |
startStopButton.addEventListener('click', () => {
|
| 449 |
if (isSpeechRecognitionActive) {
|
| 450 |
speechRecognizer.stop();
|
| 451 |
isSpeechRecognitionActive = false;
|
|
|
|
| 452 |
startStopButton.innerHTML = '<svg id="microphoneIcon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg> Start Listening';
|
| 453 |
} else {
|
| 454 |
speechRecognizer.start();
|
| 455 |
isSpeechRecognitionActive = true;
|
|
|
|
| 456 |
startStopButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 9h6v6h-6z"></path><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg> Stop Listening';
|
| 457 |
}
|
| 458 |
});
|
|
@@ -531,4 +537,4 @@ const updateLatency = () => {
|
|
| 531 |
}
|
| 532 |
};
|
| 533 |
|
| 534 |
-
setInterval(updateLatency, 100);
|
|
|
|
| 14 |
let isRequestInProgress = false;
|
| 15 |
let isUserSpeaking = false;
|
| 16 |
let isSpeechRecognitionActive = false;
|
| 17 |
+
let userManuallyStoppedRecognizer = false;
|
| 18 |
let requestAbortController = null;
|
| 19 |
let partialTranscript = '';
|
| 20 |
let lastUserSpeechTimestamp = null;
|
|
|
|
| 443 |
completeTranscript = '';
|
| 444 |
}
|
| 445 |
|
| 446 |
+
// Only restart if the user hasn't manually stopped the recognizer
|
| 447 |
+
if (isSpeechRecognitionActive && !userManuallyStoppedRecognizer) {
|
| 448 |
+
speechRecognizer.start();
|
| 449 |
+
}
|
| 450 |
};
|
| 451 |
|
| 452 |
startStopButton.addEventListener('click', () => {
|
| 453 |
if (isSpeechRecognitionActive) {
|
| 454 |
speechRecognizer.stop();
|
| 455 |
isSpeechRecognitionActive = false;
|
| 456 |
+
userManuallyStoppedRecognizer = true; // Set to true when manually stopped
|
| 457 |
startStopButton.innerHTML = '<svg id="microphoneIcon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg> Start Listening';
|
| 458 |
} else {
|
| 459 |
speechRecognizer.start();
|
| 460 |
isSpeechRecognitionActive = true;
|
| 461 |
+
userManuallyStoppedRecognizer = false; // Set to false when started
|
| 462 |
startStopButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 9h6v6h-6z"></path><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg> Stop Listening';
|
| 463 |
}
|
| 464 |
});
|
|
|
|
| 537 |
}
|
| 538 |
};
|
| 539 |
|
| 540 |
+
setInterval(updateLatency, 100);
|