fix: prevent duplicate speech synthesis fallback in recording.js

This commit is contained in:
Paul Gauthier (aider) 2025-03-14 19:07:53 -07:00
parent b86d8099f1
commit 7cee3aa1f1

View file

@ -211,17 +211,26 @@ document.addEventListener('DOMContentLoaded', function() {
// Create and play audio // Create and play audio
const audio = new Audio(audioPath); const audio = new Audio(audioPath);
// Flag to track if we've already used the TTS fallback
let fallbackUsed = false;
// Error handling with fallback to browser TTS // Error handling with fallback to browser TTS
audio.onerror = () => { audio.onerror = () => {
console.warn(`Failed to load audio: ${audioPath}`); console.warn(`Failed to load audio: ${audioPath}`);
useBrowserTTS(text); if (!fallbackUsed) {
fallbackUsed = true;
useBrowserTTS(text);
}
}; };
// Play the audio // Play the audio
audio.play().catch(e => { audio.play().catch(e => {
console.warn(`Error playing audio: ${e.message}`); console.warn(`Error playing audio: ${e.message}`);
// Also fall back to browser TTS if play() fails // Also fall back to browser TTS if play() fails
useBrowserTTS(text); if (!fallbackUsed) {
fallbackUsed = true;
useBrowserTTS(text);
}
}); });
} }