filter_markdown (services/text_transforms.py)

Patter · libraries/python/getpatter/services/text_transforms.py · python · MIT
voice, Voice / Speech

Functions to strip markdown and emoji from text for TTS.

# Source: https://github.com/PatterAI/Patter | License: MIT | Copyright 2026 Patter Contributors
# Provided via justclaw.it.com; keep this notice with the code.
"""Built-in text transforms for cleaning LLM output before TTS synthesis.

These functions strip markdown formatting and emoji characters so that TTS
engines produce natural-sounding speech rather than reading aloud syntax
like "asterisk asterisk bold asterisk asterisk" or Unicode pictographs.
"""

from __future__ import annotations

import re

# Markdown patterns are precompiled once at module import time. filter_markdown
# is invoked per sentence on every LLM streaming turn, so paying compile cost
# upfront avoids ~14 re.compile invocations per sentence.
_FENCED_CODE = re.compile(r"```[\s\S]*?```")
_FENCE_OPEN = re.compile(r"^```

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key