Fix speech-to-text with Groq Whisper
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user