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:
parent
831f91e585
commit
d996a1351b
1 changed files with 10 additions and 3 deletions
13
src/ui.js
13
src/ui.js
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue