mirror of
https://github.com/rudy3333/eversync.git
synced 2025-07-01 16:46:02 +00:00
fixed note transcrption being timed out
This commit is contained in:
parent
e65e33c210
commit
0bc1a8dc90
1 changed files with 37 additions and 11 deletions
48
notes.html
48
notes.html
|
@ -90,8 +90,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let recognition;
|
let recognition;
|
||||||
|
let userManuallyStopped = false;
|
||||||
|
|
||||||
|
|
||||||
function startVoiceRecognition() {
|
function startVoiceRecognition() {
|
||||||
|
userManuallyStopped = false;
|
||||||
if (!('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)) {
|
if (!('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)) {
|
||||||
alert("Your browser does not support speech recognition.");
|
alert("Your browser does not support speech recognition.");
|
||||||
return;
|
return;
|
||||||
|
@ -102,26 +105,49 @@
|
||||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||||
recognition = new SpeechRecognition();
|
recognition = new SpeechRecognition();
|
||||||
recognition.lang = 'en-US';
|
recognition.lang = 'en-US';
|
||||||
recognition.interimResults = false;
|
recognition.continuous = true;
|
||||||
|
recognition.interimResults = true;
|
||||||
recognition.maxAlternatives = 1;
|
recognition.maxAlternatives = 1;
|
||||||
|
let finalTranscript = '';
|
||||||
|
|
||||||
|
|
||||||
recognition.onresult = function(event) {
|
recognition.onresult = function(event) {
|
||||||
const transcript = event.results[0][0].transcript;
|
let finalTranscript = '';
|
||||||
document.getElementById('content').value += transcript;
|
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
||||||
closeVoiceModal();
|
if (event.results[i].isFinal) {
|
||||||
};
|
finalTranscript += event.results[i][0].transcript + ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (finalTranscript) {
|
||||||
|
document.getElementById('content').value += finalTranscript;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
recognition.onerror = function(event) {
|
recognition.onerror = function(event) {
|
||||||
console.error("Speech recognition error", event.error);
|
console.warn("Speech recognition error:", event.error);
|
||||||
alert("Speech recognition error: " + event.error);
|
if (!userManuallyStopped && event.error === "no-speech") {
|
||||||
closeVoiceModal();
|
setTimeout(() => recognition.start(), 500); // retry after brief pause
|
||||||
};
|
} else {
|
||||||
|
closeVoiceModal();
|
||||||
recognition.start();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
recognition.onend = function() {
|
||||||
|
if (!userManuallyStopped) {
|
||||||
|
console.log("Recognition ended. Restarting...");
|
||||||
|
recognition.start(); // Keep listening forever
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
recognition.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function stopVoiceRecognition() {
|
function stopVoiceRecognition() {
|
||||||
if (recognition) {
|
if (recognition) {
|
||||||
|
userManuallyStopped = true;
|
||||||
recognition.stop();
|
recognition.stop();
|
||||||
closeVoiceModal();
|
closeVoiceModal();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue