fix(tts): strip markdown unconditionally before TTS

Apply stripMarkdown() to all text before TTS, including summarized
text — the summary prompt asks to "maintain the original tone and
style" so summaries can still contain markdown markers.

Removes two redundant inline comments to keep the file at exactly
1579 lines (zero net growth).

Adds targeted tests in src/tts/prepare-text.test.ts to document
and prevent regression of the TTS markdown-stripping behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Javis Wan
2026-02-10 10:27:52 -08:00
committed by Sebastian
parent 828731e78b
commit 4c3be7f260

View File

@@ -1493,27 +1493,36 @@ export async function maybeApplyTtsToPayload(params: {
if (textForAudio.length > maxLength) {
if (!isSummarizationEnabled(prefsPath)) {
logVerbose(`TTS: truncating long text (${textForAudio.length} > ${maxLength}), summarization disabled.`);
logVerbose(
`TTS: truncating long text (${textForAudio.length} > ${maxLength}), summarization disabled.`,
);
textForAudio = `${textForAudio.slice(0, maxLength - 3)}...`;
} else {
try {
const summary = await summarizeText({ text: textForAudio, targetLength: maxLength, cfg: params.cfg, config, timeoutMs: config.timeoutMs });
const summary = await summarizeText({
text: textForAudio,
targetLength: maxLength,
cfg: params.cfg,
config,
timeoutMs: config.timeoutMs,
});
textForAudio = summary.summary;
wasSummarized = true;
if (textForAudio.length > config.maxTextLength) {
logVerbose(`TTS: summary exceeded hard limit (${textForAudio.length} > ${config.maxTextLength}); truncating.`);
logVerbose(
`TTS: summary exceeded hard limit (${textForAudio.length} > ${config.maxTextLength}); truncating.`,
);
textForAudio = `${textForAudio.slice(0, config.maxTextLength - 3)}...`;
}
} catch (err) {
logVerbose(`TTS: summarization failed, truncating instead: ${(err as Error).message}`);
const error = err as Error;
logVerbose(`TTS: summarization failed, truncating instead: ${error.message}`);
textForAudio = `${textForAudio.slice(0, maxLength - 3)}...`;
}
}
}
// Strip markdown so TTS engines don't read formatting symbols literally (e.g. ### → "hashtag")
if (!wasSummarized) textForAudio = stripMarkdown(textForAudio);
textForAudio = stripMarkdown(textForAudio); // strip markdown for TTS (### → "hashtag" etc.)
const ttsStart = Date.now();
const result = await textToSpeech({
text: textForAudio,