feat(reader): add TTS highlight granularity setting (word or sentence) (#4807)

This commit is contained in:
Huang Xin
2026-06-26 18:48:57 +08:00
committed by GitHub
parent dced42912f
commit 4874eb9ae7
42 changed files with 236 additions and 37 deletions
@@ -531,6 +531,12 @@ export const useTTSControl = ({ bookKey, onRequestHidePanel }: UseTTSControlProp
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [viewSettings?.ttsHighlightOptions, viewSettings?.isEink, getTTSHighlightOptions]);
useEffect(() => {
if (ttsControllerRef.current && viewSettings?.ttsHighlightGranularity) {
ttsControllerRef.current.setHighlightGranularity(viewSettings.ttsHighlightGranularity);
}
}, [viewSettings?.ttsHighlightGranularity]);
// handleStop (defined before handleTTSSpeak/handleTTSStop which reference it)
const handleStop = useCallback(
async (bookKey: string) => {
@@ -659,6 +665,7 @@ export const useTTSControl = ({ bookKey, onRequestHidePanel }: UseTTSControlProp
ttsController.updateHighlightOptions(
getTTSHighlightOptions(viewSettings.ttsHighlightOptions, viewSettings.isEink),
);
ttsController.setHighlightGranularity(viewSettings.ttsHighlightGranularity ?? 'word');
const ssml =
oneTime && ttsSpeakRange
? genSSMLRaw(ttsSpeakRange.toString().trim())