forked from akai/readest
b71b246601
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>
54 lines
1.2 KiB
TypeScript
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,
|
|
};
|
|
}
|