From fe3ab011ca3d89c019d35dd6ef697059153e1fdc Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Fri, 27 Feb 2026 00:17:51 +0800 Subject: [PATCH] fix(tts): set document lang attribute when missing or invalid for TTS, closes #3291 (#3393) --- apps/readest-app/src/services/tts/TTSController.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/readest-app/src/services/tts/TTSController.ts b/apps/readest-app/src/services/tts/TTSController.ts index 9f0ab541..f1557ed3 100644 --- a/apps/readest-app/src/services/tts/TTSController.ts +++ b/apps/readest-app/src/services/tts/TTSController.ts @@ -9,6 +9,7 @@ import { NativeTTSClient } from './NativeTTSClient'; import { EdgeTTSClient } from './EdgeTTSClient'; import { TTSUtils } from './TTSUtils'; import { TTSClient } from './TTSClient'; +import { isValidLang } from '@/utils/lang'; type TTSState = | 'stopped' @@ -155,6 +156,12 @@ export class TTSController extends EventTarget { doc = currentSection.doc; } else { doc = await section.createDocument(); + const html = doc.querySelector('html'); + const lang = html?.getAttribute('lang') || html?.getAttribute('xml:lang') || ''; + if (html && !isValidLang(lang) && this.ttsLang) { + html.setAttribute('lang', this.ttsLang); + html.setAttribute('xml:lang', this.ttsLang); + } } if (this.view.tts && this.view.tts.doc === doc) {