Files
readest/apps/readest-app/src/utils/ttsMetadata.ts
T
Huang Xin b71b246601 feat(settings): add TTS settings tab and highlight opacity, closes #3661 (#3712)
Add a new TTS tab in settings with media metadata update frequency control
(sentence/paragraph/chapter) to reduce Bluetooth notification spam, and move
TTS highlight settings from Color tab to the new TTS tab. Also add a highlight
opacity setting with live preview in the Color tab.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 06:35:26 +02:00

54 lines
1.2 KiB
TypeScript

import { TTSMediaMetadataMode } from '@/services/tts/types';
interface BuildTTSMediaMetadataOptions {
markText: string;
markName: string;
sectionLabel: string;
title: string;
author: string;
ttsMediaMetadata: TTSMediaMetadataMode;
previousSectionLabel?: string;
}
interface TTSMediaMetadataResult {
title: string;
artist: string;
album: string;
shouldUpdate: boolean;
}
export function buildTTSMediaMetadata(
options: BuildTTSMediaMetadataOptions,
): TTSMediaMetadataResult {
const {
markText,
markName,
sectionLabel,
title,
author,
ttsMediaMetadata,
previousSectionLabel,
} = options;
if (ttsMediaMetadata === 'chapter') {
const shouldUpdate =
previousSectionLabel === undefined || previousSectionLabel !== sectionLabel;
return {
title: sectionLabel || title,
artist: author,
album: title,
shouldUpdate,
};
}
// sentence and paragraph share the same metadata mapping;
// paragraph only updates on the first sentence of each block (markName "0")
const shouldUpdate = ttsMediaMetadata === 'sentence' || markName === '0';
return {
title: markText,
artist: sectionLabel || title,
album: author,
shouldUpdate,
};
}