bug fix
This commit is contained in:
@@ -176,7 +176,12 @@ function initRecognition() {
|
|||||||
checkBtn.disabled = !display.trim();
|
checkBtn.disabled = !display.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
r.onend = () => { if (state.isRecording) stopRecording(); };
|
r.onend = () => {
|
||||||
|
if (state.isRecording) {
|
||||||
|
// Android stops recognition on its own after silence — restart it
|
||||||
|
try { r.start(); } catch (_) {}
|
||||||
|
}
|
||||||
|
};
|
||||||
r.onerror = (e) => { if (e.error !== 'no-speech') stopRecording(); };
|
r.onerror = (e) => { if (e.error !== 'no-speech') stopRecording(); };
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -207,21 +212,24 @@ async function startRecording() {
|
|||||||
clearTimeout(recordingTimer);
|
clearTimeout(recordingTimer);
|
||||||
recordingTimer = setTimeout(stopRecording, MAX_RECORD_SECONDS * 1000);
|
recordingTimer = setTimeout(stopRecording, MAX_RECORD_SECONDS * 1000);
|
||||||
|
|
||||||
// MediaRecorder for audio download — best-effort, after recognition starts
|
// MediaRecorder for audio download — desktop only; on mobile it conflicts with SpeechRecognition
|
||||||
try {
|
const isMobile = /Android|iPhone|iPad/i.test(navigator.userAgent);
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
if (!isMobile) {
|
||||||
const mimeType = MediaRecorder.isTypeSupported('audio/webm;codecs=opus')
|
try {
|
||||||
? 'audio/webm;codecs=opus' : 'audio/webm';
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
mediaRecorder = new MediaRecorder(stream, { mimeType });
|
const mimeType = MediaRecorder.isTypeSupported('audio/webm;codecs=opus')
|
||||||
mediaRecorder.ondataavailable = e => { if (e.data.size > 0) audioChunks.push(e.data); };
|
? 'audio/webm;codecs=opus' : 'audio/webm';
|
||||||
mediaRecorder.onstop = () => {
|
mediaRecorder = new MediaRecorder(stream, { mimeType });
|
||||||
audioBlob = new Blob(audioChunks, { type: mimeType });
|
mediaRecorder.ondataavailable = e => { if (e.data.size > 0) audioChunks.push(e.data); };
|
||||||
stream.getTracks().forEach(t => t.stop());
|
mediaRecorder.onstop = () => {
|
||||||
if (audioBlob.size > 0) downloadBtn.disabled = false;
|
audioBlob = new Blob(audioChunks, { type: mimeType });
|
||||||
};
|
stream.getTracks().forEach(t => t.stop());
|
||||||
mediaRecorder.start();
|
if (audioBlob.size > 0) downloadBtn.disabled = false;
|
||||||
} catch (e) {
|
};
|
||||||
console.warn('MediaRecorder unavailable:', e);
|
mediaRecorder.start();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('MediaRecorder unavailable:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user