fix: guard TTS after markdown stripping (openclaw#13237) thanks @danielwanwx

This commit is contained in:
Sebastian
2026-02-12 10:43:47 -05:00
parent 6923b007b8
commit 163c68539f
2 changed files with 30 additions and 1 deletions

View File

@@ -471,6 +471,31 @@ describe("tts", () => {
process.env.OPENCLAW_TTS_PREFS = prevPrefs;
});
it("skips auto-TTS when markdown stripping leaves text too short", async () => {
const prevPrefs = process.env.OPENCLAW_TTS_PREFS;
process.env.OPENCLAW_TTS_PREFS = `/tmp/tts-test-${Date.now()}.json`;
const originalFetch = globalThis.fetch;
const fetchMock = vi.fn(async () => ({
ok: true,
arrayBuffer: async () => new ArrayBuffer(1),
}));
globalThis.fetch = fetchMock as unknown as typeof fetch;
const payload = { text: "### **bold**" };
const result = await maybeApplyTtsToPayload({
payload,
cfg: baseCfg,
kind: "final",
inboundAudio: true,
});
expect(result).toBe(payload);
expect(fetchMock).not.toHaveBeenCalled();
globalThis.fetch = originalFetch;
process.env.OPENCLAW_TTS_PREFS = prevPrefs;
});
it("attempts auto-TTS when inbound audio gating is on and the message is audio", async () => {
const prevPrefs = process.env.OPENCLAW_TTS_PREFS;
process.env.OPENCLAW_TTS_PREFS = `/tmp/tts-test-${Date.now()}.json`;

View File

@@ -1522,7 +1522,11 @@ export async function maybeApplyTtsToPayload(params: {
}
}
textForAudio = stripMarkdown(textForAudio); // strip markdown for TTS (### → "hashtag" etc.)
textForAudio = stripMarkdown(textForAudio).trim(); // strip markdown for TTS (### → "hashtag" etc.)
if (textForAudio.length < 10) {
return nextPayload;
}
const ttsStart = Date.now();
const result = await textToSpeech({
text: textForAudio,