Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(tts): normalize emphasized image descriptions
Afloat1d7001387c0c
diff --git a/server/routes/tts.test.ts b/server/routes/tts.test.tsindex 4d9785cd16..bb00498b56 100644--- a/server/routes/tts.test.ts+++ b/server/routes/tts.test.ts@@ -57,6 +57,12 @@ describe("voice routes", () => {]);});+ it("prepares image descriptions without speaking emphasis markers or changing identifiers", async () => {+ const { answers } = await call("POST", "/api/tts/prepare", { text: "See  and ." });+ expect(answers[0]![0]).toBe(200);+ expect((answers[0]![1] as { utterances: string[] }).utterances.join(" ")).toBe("See. (image: diagram) and. (image: API_KEY).");+ });+it("list no voices, and say why, when no voice provider is set up", async () => {const { answers } = await call("GET", "/api/tts/voices?q=calm");expect(answers).toHaveLength(1);diff --git a/server/tts/speech-text.test.ts b/server/tts/speech-text.test.tsindex 74029491e9..a1b5e4df61 100644--- a/server/tts/speech-text.test.ts+++ b/server/tts/speech-text.test.ts@@ -69,6 +69,15 @@ describe("speakable", () => {expect(speakable(input)).toBe(expected);});+ it.each([+ ["See .", "See. (image: diagram)."],+ ["See .", "See. (image: API_KEY)."],+ ["See .", "See. (image: API_KEY)."],+ ["See .", "See. (an image)."],+ ])("prepares the image description in %j", (input, expected) => {+ expect(speakable(input)).toBe(expected);+ });+it("gives a heading a full stop so the voice breathes", () => {expect(speakable("## Results\nAll green")).toBe("Results. All green");});diff --git a/server/tts/speech-text.ts b/server/tts/speech-text.tsindex 17b4f156dc..e643d0049e 100644--- a/server/tts/speech-text.ts+++ b/server/tts/speech-text.ts@@ -69,7 +69,10 @@ export function speakable(input: string): string {text = stripEmphasis(text);// Images before links: the syntax differs by one character.- text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, (_m, alt: string) => (alt ? `. (image: ${alt}) ` : ". (an image) "));+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, (_m, alt: string) => {+ const description = stripEmphasis(alt);+ return description ? `. (image: ${description}) ` : ". (an image) ";+ });text = text.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1");text = text.replace(/<https?:\/\/[^>\s]+>/g, " a link ");text = text.replace(/\bhttps?:\/\/\S+/g, " a link ");