enhance(tts): improve auto-play handling with browser policy support

- Add proper error handling for browser auto-play restrictions
- Set button text correctly based on auto-play success/failure
- Add console logging for debugging auto-play behavior
- Gracefully handle cases where auto-play is blocked
This commit is contained in:
Russell Ballestrini 2025-07-02 07:36:04 -04:00
parent 831f91e585
commit d996a1351b

View file

@ -2290,11 +2290,18 @@ export function openTTSModal() {
const result = await speakText(currentText, selectedVoice, selectedSpeed);
ttsAudio = result.audio;
ttsBlob = result.blob;
playButton.textContent = "Pause Text";
playButton.disabled = false;
// Auto-play the audio
ttsAudio.play();
// Auto-play the audio (handle browser auto-play policies)
try {
await ttsAudio.play();
console.log("TTS audio auto-playing");
playButton.textContent = "Pause Text";
} catch (error) {
console.log("Auto-play prevented by browser policy:", error.message);
playButton.textContent = "Play Text";
// Don't throw error, just log it - user can manually click play
}
// Add download button if not exists
let downloadButton = article.querySelector(".download-btn");