Expand common German abbreviations in central TTS preparation

This commit is contained in:
Mikei386 committed 2026-10-19 22:50:16 +02:00
1 parent b2722744ae
commit 9439230887
6 files changed
+139 -4

No files matched your search

+8
View File
@@ -1,3 +1,11 @@
## German TTS abbreviations · 19 October 2026
Central expansion of u.a., z.B., d.h., i.d.R., bzw., ggf. and other common
abbreviations deployed; shared endpoint/Qwen rules, no Mac app changes.
29 tests pass. Actual user-sentence TTS→STT confirms “unter anderem”; proper-name
pronunciation and streaming playback remain separate concerns.
[Verification and restore notes](maintenance/2026-10-19-tts-abbreviations.md).
## TTS throughput · 19 October 2026 evening
Deck CPU budget increased live6→8 and persisted as cpu_limit:8; Qwen0.6B Q8,
@@ -0,0 +1,65 @@
# German TTS abbreviation expansion · 19 October 2026
Central speech-only normalization now expands 14 multi-part and 19 single-word
abbreviations, including u.a./u. a., z.B./z. B., d.h., i.d.R., u.U., m.E., m.W.,
i.A., i.V., o.g., s.o., s.u., v.a., z.T., bzw., ggf., evtl., usw., usf., ca.,
max., inkl., exkl., zzgl., bzgl., bspw., sog., vgl., Nr., Abs., Abb., Dr., Prof.
Matching supports capitalization and ordinary/nonbreaking spaces between parts.
Ambiguous St., S., Bd., min. remain unchanged. This is a bounded list, not an
exhaustive German pronunciation engine. Existing km/h and other rules remain.
`speech_text.expand_german_abbreviations` is shared by Qwen speech preparation
and the optional endpoint-wide `tts_text_enhancer.prepare`. The endpoint enhancer
remains enabled. Other backends receive these expansions when that toggle is on;
Qwen also prepares its input before sentence splitting. URLs, absolute paths,
email addresses and abbreviation fragments in filenames are preserved by this
new function. Other pre-existing speech rules may still speak paths/URLs.
Chat text and model-generated answers are untouched. No Mac application changes,
silence prefix, playback buffer or Hermes gateway changes were made.
## Verification
29 tests passed:
```sh
python3 -m unittest test_speech_text test_tts_text_enhancer test_speech_mp3 test_speech_reference
```
Tests include spaced/unspaced forms, protected strings, ambiguous forms,
non-German passthrough, idempotence, existing units and endpoint backend routing.
Actual authenticated neutral TTS endpoint request, model=tts, voice=default,
PCM output, original user sentence including `u.a.` (not pre-expanded by the
test client):
> 1. Produziert wurde u.a. von KCSM-TV, WITF (Pennsylvania) und KTEH San Jose – mitten im Silicon Valley, Cheifet Productions bis zum Schluss.
Result: 24 kHz mono PCM16, 11.28 seconds, request wall time 9.00 seconds.
Existing local STT endpoint returned:
> Erstens, produziert wurde unter anderem von KCS MTV OVITF Pennsylvania und KTEH San Jose mitten im Silicon Valley Schafe Productions bis zum Schluss.
The target phrase is present as **unter anderem**. Sender/personal names differ
in ASR; this is not a listening acceptance or proof of their pronunciation.
Streaming crackles and first-word clipping are outside this fix.
Local listening artifact:
`work/tts-abbreviations-20261019/Anna-Abkuerzungen.wav` (not committed).
## Deployment, native operation and rollback
Active image: `athena-deck-standalone:e473d5c42108f306`, healthy after normal
installer update, previous `athena-deck-standalone:6460872535b77f97` retained.
Checked endpoint idle before restart. CPU budget remains 8, enhancer enabled.
Canonical host source `/opt/athena-deck-dev/source` contains both changed modules.
Installed using `deploy/install.py --update --directory
/opt/athena-deck-dev/runtime --reuse-runtime` after building the app image.
No weights, profile parameters, dependencies or credentials were changed.
Both modules are already in the installer's explicit file allowlist. A native
Debian service needs the same two source modules and its usual application restart;
Python standard library only, no additional packages, model downloads or private
state. Existing endpoint.json toggle and audio profiles remain part of the normal
state restore. Rebuild from this Git revision; restore existing state unchanged.
For the present container deployment, use the normal installer --rollback with
the same directory if needed. Full fresh-Debian end-to-end restore remains an
existing unqualified platform task, not tested by this speech normalization change.
+41 -3
View File
@@ -105,11 +105,49 @@ def _normalize_aspect_ratios(text: str) -> str:
)
def expand_german_abbreviations(text: str) -> str:
"""Expand unambiguous prose abbreviations, preserving URLs and filenames.
Do not guess ambiguous forms such as St., S., Bd., or standalone min.
Shared by the optional endpoint enhancer and Qwen's speech preparation.
"""
dotted = {
'u.a.': 'unter anderem', 'u.U.': 'unter Umständen',
'z.B.': 'zum Beispiel', 'd.h.': 'das heißt',
'i.d.R.': 'in der Regel', 'i.A.': 'im Auftrag',
'i.V.': 'in Vertretung', 'm.E.': 'meines Erachtens',
'm.W.': 'meines Wissens', 'o.g.': 'oben genannt',
's.o.': 'siehe oben', 's.u.': 'siehe unten',
'v.a.': 'vor allem', 'z.T.': 'zum Teil',
}
words = {
'bzw': 'beziehungsweise', 'ggf': 'gegebenenfalls',
'evtl': 'eventuell', 'usw': 'und so weiter',
'usf': 'und so fort', 'ca': 'circa', 'max': 'maximal',
'inkl': 'inklusive', 'exkl': 'exklusive', 'zzgl': 'zuzüglich',
'bzgl': 'bezüglich', 'bspw': 'beispielsweise',
'sog': 'sogenannt', 'vgl': 'vergleiche',
'Nr': 'Nummer', 'Abs': 'Absatz', 'Abb': 'Abbildung',
'Dr': 'Doktor', 'Prof': 'Professor',
}
# Work on prose spans only: replacing z.B. inside a URL/path/mail is unsafe.
protected = r'(https?://[^\s<>]+|[\w.+-]+@[\w.-]+|(?<!\w)/[^\s<>]+)'
rules = [(r'(?<![\w./@-])' + r'[ \t\u00a0\u202f]*'.join(re.escape(c) for c in key)
+ r'(?![\w/@-])', value) for key, value in dotted.items()]
rules += [(r'(?<![\w./@-])' + re.escape(key) + r'\.(?![\w/@-])', value)
for key, value in words.items()]
# Boundaries also prevent matching abbreviation fragments in filenames.
def prose(value):
for pattern, replacement in rules:
value = re.sub(pattern, replacement, value, flags=re.IGNORECASE)
return value
spans = re.split(protected, text)
return ''.join(value if i % 2 else prose(value) for i, value in enumerate(spans))
def normalize_for_german_speech(text: str) -> str:
"""Turn common visual notation into unambiguous spoken German."""
text = re.sub(r"\bv\.\s*a\.", "vor allem", text, flags=re.IGNORECASE)
text = re.sub(r"\bca\.", "circa", text, flags=re.IGNORECASE)
text = re.sub(r"\bmax\.", "maximal", text, flags=re.IGNORECASE)
text = expand_german_abbreviations(text)
# Run these before the date rule: otherwise 192.168.1.5 could be partly
# interpreted as a visual date.
text = re.sub(
+19 -1
View File
@@ -1,9 +1,27 @@
import unittest
from speech_text import prepare_for_speech
from speech_text import prepare_for_speech, expand_german_abbreviations
from tts_worker import spoken_chunks
class SpeechPreparationTests(unittest.TestCase):
def test_common_german_abbreviations(self):
cases={'u.a.':'unter anderem','u. a.':'unter anderem','u.\u00a0a.':'unter anderem',
'z.B.':'zum Beispiel','z. B.':'zum Beispiel','d.h.':'das heißt',
'i. d. R.':'in der Regel','u.U.':'unter Umständen','m.E.':'meines Erachtens',
'bzw.':'beziehungsweise','ggf.':'gegebenenfalls','evtl.':'eventuell',
'usw.':'und so weiter','inkl.':'inklusive','zzgl.':'zuzüglich',
'Nr.':'Nummer','Dr.':'Doktor','Prof.':'Professor'}
for raw,spoken in cases.items():
with self.subTest(raw=raw):self.assertEqual(expand_german_abbreviations(raw),spoken)
def test_abbreviations_preserve_identifiers_and_ambiguous_forms(self):
raw='https://example.org/u.a./Dr. /config/u.a.txt mike@bspw.de foo.bzw.txt St. S. min. KCSM-TV WITF KTEH'
self.assertEqual(expand_german_abbreviations(raw),raw)
def test_user_production_example(self):
raw='1. Produziert wurde u.a. von KCSM-TV, WITF (Pennsylvania) und KTEH San Jose – mitten im Silicon Valley, Cheifet Productions bis zum Schluss.'
spoken=prepare_for_speech(raw)
self.assertEqual(spoken,raw.replace('u.a.','unter anderem'))
self.assertNotIn('u.a.', ' '.join(spoken_chunks(dict(text=raw,language='German'))))
self.assertEqual(expand_german_abbreviations(spoken),spoken)
def test_weather_units_and_ranges(self):
text=prepare_for_speech('15°–23 °C, 93 %, ca. 12 mm, v.a. um 05–06 Uhr, Wind max. 16 km/h.')
for expected in ('15 bis 23 Grad','93 Prozent','circa 12 mm','vor allem','5 bis 6 Uhr','Wind maximal 16 Kilometer pro Stunde'):
+4
View File
@@ -6,6 +6,10 @@ from endpoint import APIHandler,Endpoint,APIError
from tts_text_enhancer import prepare
class PreparationTests(unittest.TestCase):
def test_abbreviations_shared_by_endpoint_backends(self):
self.assertEqual(prepare('Produziert wurde u.a. von KCSM-TV, z. B. mit WITF.'),
'Produziert wurde unter anderem von KCSM-TV, zum Beispiel mit WITF.')
self.assertEqual(prepare('u.a. z.B.', 'English'),'u.a. z.B.')
def test_meaning_and_markup(self):
self.assertEqual(prepare('- **Hinweis:** KI-Bild ≠ echtes Foto'),'Hinweis: Künstliche Intelligenz-Bild ist nicht gleich echtes Foto')
def test_paths_and_urls(self):
+2
View File
@@ -4,6 +4,7 @@ Changes speech input only, never the displayed answer. No model or network calls
This is normalization, not a guarantee of faithful audio synthesis.
"""
import re
from speech_text import expand_german_abbreviations
def prepare(text, language='German'):
@@ -32,6 +33,7 @@ def prepare(text, language='German'):
text = re.sub(r'\bHTTP\b', 'Ha Te Te Pe', text)
text = re.sub(r'\b403\b', 'vierhundertdrei', text)
text = text.replace('Labeling', 'Kennzeichnung').replace('User-Agent', 'User Agent')
text = expand_german_abbreviations(text)
for i, value in enumerate(protected):
text = text.replace(f'\x00URL{i}\x00', value)
return re.sub(r'\s+', ' ', text).strip()