mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 15:41:40 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user