Skip to content

Voice: TTS text is not shaped for speech — markdown, file paths, URLs and code fences read aloud #13102

Closed

Description

@mrveiss

Problem

Text sent to TTS is not shaped for speech. Assistant replies routinely contain
markdown, file paths, URLs, and fenced code blocks — read aloud these are symbol
soup ("autobot dash backend slash l l c slash adapters slash base dot p y").

This is worst exactly where voice matters most: replies from coding agents, which
are dense with paths and code.

Evidence

autobot-frontend/src/composables/useVoiceConversation.ts:146-167 —
_sanitizeForSpeech() removes [THOUGHT]/[PLANNING]/[DEBUG]/[SOURCES]
markers, <TOOL_CALL> tags, and all HTML, then truncates at a sentence boundary.

It does not touch:

  • markdown syntax (*, _, #, >, list bullets, numbered lists, link syntax)
  • fenced code blocks
  • file paths and filenames
  • URLs

Proposed approach

New pure helper in autobot-frontend/src/utils/ttsSentences.ts (next to the
existing sentence logic — pure, no browser deps, unit-testable).
_sanitizeForSpeech() delegates to it; the logic does not go into
useVoiceConversation.ts, which is already carrying too much.

Transformations:

  • links → their text; inline code → its contents; strip *_~#> and list markers
  • URLs → a spoken placeholder
  • path-shaped tokens and known code-file extensions → a spoken placeholder
  • fenced code blocks dropped entirely, with state carried across streaming
    deltas — the ``` marker can split across two chunks, so a held-back trailing
    backtick buffer is required or a fence leaks through
  • repair a missing space at a sentence join (now.Right → now. Right)

Constraints

  • Conservative matching. Ordinary prose must survive — "and/or", "24/7",
    "e.g.", decimals, and arr[0] in a legitimately spoken context.
  • i18n: the replacement strings are user-visible and need all 11 locales.
    This is the real cost of this issue, not the regex.
  • The written transcript must be unaffected — this shapes the spoken stream
    only.

Acceptance criteria

  • Pure, unit-tested helper in utils/ttsSentences.ts
  • Fence stripping is correct when the ``` marker splits across two streamed
    deltas (explicit test)
  • Prose false-positive cases covered by tests
  • Replacement strings localized in all 11 locales
  • Displayed transcript unchanged — verified by test

Activity

  1. mrveiss commented on Jul 31, 2026

    @mrveiss
    OwnerAuthor

    Parent: #13096 (capability audit umbrella).

  2. mrveiss commented on Jul 31, 2026

    @mrveiss
    OwnerAuthor

    Consolidation note — the HTML half already exists; only the speech half is new.

    _sanitizeForSpeech() (useVoiceConversation.ts:146-167) hand-rolls HTML stripping — a script-tag regex plus a while (prev !== clean) tag-stripping loop, carrying two codeql[js/incomplete-multi-character-sanitization] suppressions.

    Meanwhile autobot-frontend/src/utils/sanitize.ts already provides sanitizeHtml(), sanitizeChatHtml(), and sanitizeKnowledgeHtml().

    So this issue splits cleanly in two:

    1. Delegate the HTML-stripping half to the existing sanitize.ts — removes hand-rolled sanitization and its CodeQL suppressions rather than porting them to a new file.
    2. Add only the genuinely new speech-shaping logic (markdown, paths, URLs, fenced code) in utils/ttsSentences.ts.

    Moving the hand-rolled version into ttsSentences.ts as-is would relocate the duplication instead of removing it.

  3. modified the milestones: Backlog, v0.13.0 on Sep 12, 2026
  4. mrveiss commented on Oct 4, 2026

    @mrveiss
    OwnerAuthor

    Delivered by #17954 (merge 7f8e7385db). Verified against origin/main:

    • Pure, unit-tested helper in utils/ttsSentences.ts
      • createSpeechShaper / shapeForSpeech, with openingFence / closesFence (CommonMark line-start rules).
      • No browser dependencies; placeholders are passed in.
      • Tests are in utils/__tests__/ttsSpeechShaping.test.ts.
    • Fence stripping is correct when the ``` marker splits across two streamed deltas (explicit test)
      • Case drops the block when the ``` marker splits across two streamed deltas.
      • Also keeps fence state across slices, keeps a four-backtick block closed against an inner ``` line, and does not treat ``` in the middle of a line as a fence.
    • Prose false-positive cases covered by tests
      • it.each over 11 prose sentences: "and/or", "24/7", "e.g.", "3.14", arr[0], "Node.js", my_var/2 * 3, a bare "/etc", a date, "he/she/they", "TCP/IP/UDP". Each is asserted unchanged.
    • Replacement strings localized in all 11 locales
      • voice.speech.url / voice.speech.path are translated in ar, de, en, es, fa, fr, he, lv, pl, pt, ur ("a link" / "a file path", "ein Link" / "ein Dateipfad", …).
    • Displayed transcript unchanged — verified by test
      • Case advances the streaming cursor over the RAW text while only the spoken copy is shaped. The raw transcript is unchanged, consumed === transcript.length, and spans.join('') === transcript.slice(0, consumed).
      • Shaping happens only on the TTS copy: ChatInterface.vue _speechShaper.push(span), and useVoiceConversation._sanitizeForSpeech, which runs after the bubble stores the raw response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions