Fix speech-to-text with Groq Whisper

This commit is contained in:
Chandu
2026-07-25 11:55:40 -04:00
parent 7a56c88907
commit 41429206ac
6 changed files with 160 additions and 26 deletions
+17 -5
View File
@@ -411,12 +411,23 @@ async function transcribeAudio(blob) {
body: blob
});
const data = await response.json().catch(() => null);
if (!response.ok) {
throw new Error('Transcription failed');
const errorMessage = data?.error || 'Voice transcription failed';
throw new Error(errorMessage);
}
const transcript = data?.transcript?.trim() || '';
if (!transcript) {
sourceText.value = 'No speech detected';
if (charCount) {
charCount.textContent = 0;
}
showStatus('No speech detected', 'error');
voiceStatus.textContent = '⚠️ No speech detected';
return;
}
const data = await response.json();
const transcript = data.transcript || '';
sourceText.value = transcript;
if (charCount) {
charCount.textContent = transcript.length;
@@ -428,8 +439,9 @@ async function transcribeAudio(blob) {
await translateText();
} catch (error) {
console.error('Voice transcription error:', error);
showStatus('Voice transcription failed', 'error');
voiceStatus.textContent = '❌ Voice transcription failed';
const errorMessage = error?.message || 'Voice transcription failed';
showStatus(errorMessage, 'error');
voiceStatus.textContent = `${errorMessage}`;
}
}