Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Merge dev into PR #1557 and preserve integrated behavior

Bingxi Zhao (Frank)b83592a1072e
diff --cc deeptutor/services/voice/base.py
index dce58d63f,ba3590f93..b14c89657
--- a/deeptutor/services/voice/base.py
+++ b/deeptutor/services/voice/base.py
@@@ -156,28 -152,7 +156,26 @@@ _WHITESPACE = re.compile(r"[ \t]+"
_BLANK_LINES = re.compile(r"\n{3,}")
+def _unwrap_emphasis_for_speech(text: str) -> str:
+ """Turn Markdown bold/italic/strike into plain words.
+
+ Voice models otherwise speak ``*`` as "asterisk". Math must already have
+ been verbalized so TeX ``*`` / ``_`` inside ``$…$`` is not treated as
+ emphasis. Leftover unmatched ``**`` markers are dropped; a remaining
+ single ``*`` is turned into a space so "asterisk" is never read.
+ """
+ out = _BOLD_STARS.sub(r"\1", text)
+ out = _BOLD_UNDERS.sub(r"\1", out)
+ out = _STRIKE.sub(r"\1", out)
+ out = _ITALIC_STARS.sub(r"\1", out)
+ out = _ITALIC_UNDERS.sub(r"\1", out)
+ out = out.replace("**", "")
+ out = out.replace("__", "")
+ out = out.replace("*", " ")
+ return out
+
+
- def strip_markdown_for_speech(
- text: str, *, max_chars: int = 0, math_speak: bool = True
- ) -> str:
+ def strip_markdown_for_speech(text: str, *, max_chars: int = 0, math_speak: bool = True) -> str:
"""Reduce Markdown to plain prose suitable for TTS.
Drops code blocks and tables outright (they read terribly), unwraps links