From 53cbbb6b667489a1838899f44f8ae41ac55be8c3 Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Mon, 19 Oct 2026 22:58:02 +0200 Subject: [PATCH] Normalize technical German TTS vocabulary and distinguish byte and bit units --- docs/CURRENT_SYSTEM.md | 7 ++ docs/maintenance/2026-10-19-tts-technical.md | 81 +++++++++++++++++++ speech_text.py | 82 +++++++++++++++++++- test_speech_text.py | 24 +++++- test_tts_text_enhancer.py | 3 + tts_text_enhancer.py | 3 +- 6 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 docs/maintenance/2026-10-19-tts-technical.md diff --git a/docs/CURRENT_SYSTEM.md b/docs/CURRENT_SYSTEM.md index 82167da..fe5811b 100644 --- a/docs/CURRENT_SYSTEM.md +++ b/docs/CURRENT_SYSTEM.md @@ -1,3 +1,10 @@ +## Technical TTS vocabulary · 19 October 2026 + +Central speech preparation now distinguishes MB/MiB/Mbit and rate suffixes, +spells hardware/network acronyms and supplies Homelab pronunciation hints. +Activated at endpoint idle; 33 tests pass, no Mac or Hermes changes. +[Coverage, verification and restore](maintenance/2026-10-19-tts-technical.md). + ## German TTS abbreviations · 19 October 2026 Central expansion of u.a., z.B., d.h., i.d.R., bzw., ggf. and other common diff --git a/docs/maintenance/2026-10-19-tts-technical.md b/docs/maintenance/2026-10-19-tts-technical.md new file mode 100644 index 0000000..648ca09 --- /dev/null +++ b/docs/maintenance/2026-10-19-tts-technical.md @@ -0,0 +1,81 @@ +# Technical German speech preparation · 19 October 2026 + +`speech_text.prepare_technical_german` supplies shared, deterministic speech-only +technical normalization. The endpoint-wide enhancer invokes it before path +rendering; Qwen invokes it before sentence splitting. No model/network dependency. +German only; displayed messages, stored configuration and files are not rewritten. + +## Coverage + +| Input | Spoken text | +| --- | --- | +| MB / MiB | Megabyte / Mebibyte | +| GB / GiB | Gigabyte / Gibibyte | +| KB, kB, KiB, TB, TiB, PB, PiB | decimal/binary names, preserving numbers | +| MB/s / Mb/s / Mbit/s | Megabyte / Megabit / Megabit pro Sekunde | +| MiB/s, Gbit/s, Mbps | Mebibyte / Gigabit / Megabit pro Sekunde | +| kHz, MHz, GHz, Hz | Kilohertz, Megahertz, Gigahertz, Hertz | +| ms, µs, ns | Millisekunden, Mikrosekunden, Nanosekunden | +| numeric W, kW, Wh, kWh, V, mV, A, mA | electrical unit names | +| CPU, GPU, SSD, HDD, NVMe, USB, PCIe | explicit spoken letter sequences | +| RAM, VRAM | Arbeitsspeicher, Grafikspeicher | +| SSH, HTTP(S), API, DNS, DHCP, TCP, UDP, IP(v4/v6), VPN | letter sequences | +| NAS, LAN, WLAN | pronunciation hints | +| IOPS | Ein- und Ausgabeoperationen pro Sekunde | +| TTS, STT, MCP, LLM, SQL, CLI, GUI, UID, GID | letter sequences | +| ext4, XFS, ZFS, NTFS, FAT32 | filesystem pronunciation hints | +| Unraid / Sonarr / Radarr | Anraid / Sonar / Radar | +| Logfile(s), Logrotate / Log Rotate | Logdatei(en), Log Rotation | +| Filesystem(s), Home-Assistant, SmartHome | Dateisystem(e), Home Assistant, Smart Home | + +Docker, Home Assistant and Smart Home already have normal word spellings and +stay unchanged. No blanket phonetic respelling of every English product name. +Unit matching is **case sensitive**: bits must never become bytes. This only +expands names, with no numerical conversion (GB does not become GiB). +Ambiguous standalone m, s, A, W, B are not globally expanded. Numeric B/s and +bit/s are supported. Compound identifiers and unlisted forms remain unchanged. + +The new helper protects inline code, HTTP URLs, mail, absolute Linux/Windows +paths, filename fragments and dotted entity IDs. Tests include sensor.GPU, +RAM.log, CPU_LIMIT, /mnt/SSD, Windows paths and URLs. Existing downstream +speech formatting can still render paths or remove code markup; this is not a +promise that all literal code is spoken byte-for-byte by the whole pipeline. +The lexical rules are idempotent, allowing endpoint and Qwen preparation in series. + +## Verification and operation + +33 tests pass: + +```sh +python3 -m unittest test_speech_text test_tts_text_enhancer test_speech_mp3 test_speech_reference +``` + +Includes numeric spacing, rates, decimal commas/dots, punctuation, uppercase +byte vs lowercase bit, binary prefixes, protected identifiers, existing German +abbreviations, non-German passthrough, idempotence and API routing. + +Prepared test text and the live TTS/STT probe are kept in local +`work/tts-technical-20261019/`. Speech synthesis quality and proper-name +pronunciation require listening; ASR agreement alone is not listening acceptance. +The live audio probe was not started: renewed endpoint activity persisted during +its bounded 45-second idle wait. It exited without submitting a synthesis/STT +request. Thus this change has unit/routing and deployed text preparation checks, +but no new recorded audio acceptance. No probe remains running or scheduled. + +Deployment uses the existing installer --update --reuse-runtime against +/opt/athena-deck-dev/runtime after the endpoint becomes idle. Canonical host +source is /opt/athena-deck-dev/source. Both modules already belong to the build +allowlist; no new packages, services, weights or private data. The saved endpoint +enhancer toggle stays enabled. No Mac application or Hermes gateway modifications. + +Activated image `athena-deck-standalone:22f6b89a6d119cb3` after observing zero +active endpoint requests. Previous image `e473d5c42108f306` retained for rollback. +Actual deployed enhancer returns `Anraid: 32 Gibibyte Arbeitsspeicher, +120 Megabyte pro Sekunde, 1 Gigabit pro Sekunde.` for the raw example input. +Container is healthy. CPU budget remains 8. Profile/model parameters are unchanged. + +Native Debian operation uses the same modules and a normal application restart; +no container-only runtime requirement was added. Restore uses this Git revision +plus existing profiles/state, including endpoint.json. Present container rollback +uses the normal installer --rollback. Full fresh-Debian restore qualification +remains an existing open platform task. diff --git a/speech_text.py b/speech_text.py index 054d5b6..65c06cb 100644 --- a/speech_text.py +++ b/speech_text.py @@ -145,9 +145,89 @@ def expand_german_abbreviations(text: str) -> str: return ''.join(value if i % 2 else prose(value) for i, value in enumerate(spans)) +def prepare_technical_german(text: str) -> str: + """Speech-only technical vocabulary; byte/bit unit case is significant. + + Protect code, paths, addresses, file names and entity IDs before rewriting + prose. Product names without a known problematic spelling stay as written. + """ + protected = ( + r'(`[^`\n]+`|https?://[^\s<>]+|[\w.+-]+@[\w.-]+' + r'|(?]+' + r'|\b[A-Za-z]:[\\/][^\s<>]+' + r'|\b[A-Za-z_][\w-]*(?:[.\\][\w-]+)+)' + ) + units = { + 'KiB': 'Kibibyte', 'MiB': 'Mebibyte', 'GiB': 'Gibibyte', + 'TiB': 'Tebibyte', 'PiB': 'Pebibyte', + 'kB': 'Kilobyte', 'KB': 'Kilobyte', 'MB': 'Megabyte', + 'GB': 'Gigabyte', 'TB': 'Terabyte', 'PB': 'Petabyte', + 'Kibit': 'Kibibit', 'Mibit': 'Mebibit', 'Gibit': 'Gibibit', + 'kbit': 'Kilobit', 'Kbit': 'Kilobit', 'Mbit': 'Megabit', + 'Gbit': 'Gigabit', 'Tbit': 'Terabit', + 'kb': 'Kilobit', 'Mb': 'Megabit', 'Gb': 'Gigabit', + 'MBit': 'Megabit', 'GBit': 'Gigabit', + 'kHz': 'Kilohertz', 'MHz': 'Megahertz', 'GHz': 'Gigahertz', + 'Hz': 'Hertz', 'ms': 'Millisekunden', 'µs': 'Mikrosekunden', + 'μs': 'Mikrosekunden', 'ns': 'Nanosekunden', + } + vocab = { + 'CPU': 'Ce Pe U', 'GPU': 'Ge Pe U', 'RAM': 'Arbeitsspeicher', + 'VRAM': 'Grafikspeicher', 'SSD': 'Es Es De', 'HDD': 'Ha De De', + 'NVMe': 'En Vau Em E', 'USB': 'U Es Be', 'PCIe': 'Pe Ce I Express', + 'SSH': 'Es Es Ha', 'HTTP': 'Ha Te Te Pe', 'HTTPS': 'Ha Te Te Pe Es', + 'API': 'A Pe I', 'DNS': 'De En Es', 'DHCP': 'De Ha Ce Pe', + 'TCP': 'Te Ce Pe', 'UDP': 'U De Pe', 'IP': 'I Pe', + 'IPv4': 'I Pe Version vier', 'IPv6': 'I Pe Version sechs', + 'LAN': 'Lan', 'WLAN': 'We Lan', 'VPN': 'Vau Pe En', + 'NAS': 'Nas', 'IOPS': 'Ein- und Ausgabeoperationen pro Sekunde', + 'TTS': 'Te Te Es', 'STT': 'Es Te Te', 'MCP': 'Em Ce Pe', + 'LLM': 'El El Em', 'SQL': 'Es Ku El', 'CLI': 'Ce El I', + 'GUI': 'Ge U I', 'UID': 'U I De', 'GID': 'Ge I De', + 'ext4': 'Ext vier', 'Ext4': 'Ext vier', 'XFS': 'Iks Ef Es', + 'ZFS': 'Zett Ef Es', 'NTFS': 'En Te Ef Es', 'FAT32': 'Fat zweiunddreißig', + 'Unraid': 'Anraid', 'Sonarr': 'Sonar', 'Radarr': 'Radar', + 'Logfile': 'Logdatei', 'Logfiles': 'Logdateien', + 'Logrotate': 'Log Rotation', 'Log Rotate': 'Log Rotation', + 'Filesystem': 'Dateisystem', 'Filesystems': 'Dateisysteme', + 'Home-Assistant': 'Home Assistant', 'SmartHome': 'Smart Home', + } + for key in ('Unraid', 'Sonarr', 'Radarr', 'Logfile', 'Logfiles', + 'Logrotate', 'Log Rotate', 'Filesystem', 'Filesystems', + 'Home-Assistant', 'SmartHome'): + vocab[key.lower()] = vocab[key] + # B/s and bit/s are only meaningful as units after a numeric quantity. + unit_pattern = '|'.join(re.escape(k) for k in sorted(units, key=len, reverse=True)) + def prose(value): + value = re.sub( + r'(? str: """Turn common visual notation into unambiguous spoken German.""" text = expand_german_abbreviations(text) + text = prepare_technical_german(text) # Run these before the date rule: otherwise 192.168.1.5 could be partly # interpreted as a visual date. text = re.sub( @@ -255,7 +335,6 @@ def normalize_for_german_speech(text: str) -> str: def prepare_for_speech(text: str, language: str = "German") -> str: """Normalize technical display text without destroying Qwen's prosody.""" text = re.sub(r"```.*?```", " Codeblock. ", text, flags=re.DOTALL) - text = re.sub(r"`([^`]+)`", r"\1", text) text = re.sub(r"!\[([^]]*)\]\([^)]+\)", r"\1", text) text = re.sub(r"\[([^]]+)\]\([^)]+\)", r"\1", text) text = re.sub(r"(?m)^\s{0,3}#{1,6}\s*", "", text) @@ -264,6 +343,7 @@ def prepare_for_speech(text: str, language: str = "German") -> str: text = text.replace("→", ". ").replace("←", ". ") if language.lower() in ("de", "german", "deutsch"): text = normalize_for_german_speech(text) + text = re.sub(r"`([^`]+)`", r"\1", text) # Preserve slashes until after unit normalization so km/h becomes # "Kilometer pro Stunde" instead of the broken "Kilometer, h". text = text.replace("/", ", ") diff --git a/test_speech_text.py b/test_speech_text.py index 0311167..8aa4ad8 100644 --- a/test_speech_text.py +++ b/test_speech_text.py @@ -1,9 +1,31 @@ import unittest -from speech_text import prepare_for_speech, expand_german_abbreviations +from speech_text import prepare_for_speech, expand_german_abbreviations, prepare_technical_german from tts_worker import spoken_chunks class SpeechPreparationTests(unittest.TestCase): + def test_technical_units_distinguish_bits_bytes_and_binary(self): + cases={'32GB':'32 Gigabyte','32 GiB':'32 Gibibyte','512MiB':'512 Mebibyte', + '16 MB/s':'16 Megabyte pro Sekunde','16 Mb/s':'16 Megabit pro Sekunde', + '1 Gbit/s':'1 Gigabit pro Sekunde','100 Mbps':'100 Megabit pro Sekunde', + '12 MiB /s':'12 Mebibyte pro Sekunde','2,5 GB / s':'2,5 Gigabyte pro Sekunde', + '24 kHz':'24 Kilohertz','3.5 GHz':'3.5 Gigahertz','80 ms':'80 Millisekunden', + 'in MiB.':'in Mebibyte.','10 B/s':'10 Byte pro Sekunde', + '65 W':'65 Watt','2,5 kWh':'2,5 Kilowattstunden','12 V':'12 Volt'} + for raw,spoken in cases.items(): + with self.subTest(raw=raw):self.assertEqual(prepare_technical_german(raw),spoken) + def test_homelab_vocabulary_and_safe_boundaries(self): + self.assertEqual(prepare_technical_german('Unraid: Sonarr, Radarr, CPU, GPU, SSD und Logfiles.'), + 'Anraid: Sonar, Radar, Ce Pe U, Ge Pe U, Es Es De und Logdateien.') + raw='`docker logs CPU` /mnt/SSD https://host/CPU?q=32GB sensor.GPU RAM.log foo32GB 32GBfile CPU_LIMIT /config/logrotate.conf C:\\SSD\\RAM.txt' + self.assertEqual(prepare_technical_german(raw),raw) + for raw in ('Home Assistant, Docker und Smart Home.', 'MBX 1mb 5m 10s GB123'): + self.assertEqual(prepare_technical_german(raw),raw) + def test_technical_preparation_is_idempotent_and_german_only(self): + raw='Die SSD liefert 120 MiB/s; CPU bei 3,5 GHz, Logrotate auf Unraid.' + spoken=prepare_technical_german(raw) + self.assertEqual(prepare_technical_german(spoken),spoken) + self.assertEqual(prepare_for_speech('GPU 32 GiB', 'English'),'GPU 32 GiB') 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', diff --git a/test_tts_text_enhancer.py b/test_tts_text_enhancer.py index 5c10ba6..60a4494 100644 --- a/test_tts_text_enhancer.py +++ b/test_tts_text_enhancer.py @@ -6,6 +6,9 @@ from endpoint import APIHandler,Endpoint,APIError from tts_text_enhancer import prepare class PreparationTests(unittest.TestCase): + def test_technical_units_at_shared_endpoint(self): + self.assertEqual(prepare('Unraid: 32 GiB RAM, 120 MB/s, 1 Gbit/s.'), + 'Anraid: 32 Gibibyte Arbeitsspeicher, 120 Megabyte pro Sekunde, 1 Gigabit pro Sekunde.') 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.') diff --git a/tts_text_enhancer.py b/tts_text_enhancer.py index c73d146..2a7a4e8 100644 --- a/tts_text_enhancer.py +++ b/tts_text_enhancer.py @@ -4,7 +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 +from speech_text import expand_german_abbreviations, prepare_technical_german def prepare(text, language='German'): @@ -20,6 +20,7 @@ def prepare(text, language='German'): protected.append(match.group(0)) return f'\x00URL{len(protected)-1}\x00' text = re.sub(r'https?://[^\s`<>]+', protect, text) + text = prepare_technical_german(text) def path(match): return re.sub(r'[/_.-]', lambda m: { '/': ' Schrägstrich ', '_': ' Unterstrich ',