"""Optional deterministic German speech preparation shared by API TTS backends. 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, prepare_technical_german def prepare(text, language='German'): if not isinstance(text, str): raise ValueError('TTS-Eingabetext muss Text sein.') if str(language).strip().lower() not in ('german', 'de', 'de-de', 'deutsch'): return text # Protect HTTP URLs from the Unix-path rule. Speak link labels, not targets. text = re.sub(r'!\[([^\]]*)\]\([^\n)]*\)', r'\1', text) text = re.sub(r'\[([^\]]+)\]\([^\n)]*\)', r'\1', text) protected = [] def protect(match): 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 ', '-': ' Bindestrich ', '.': ' Punkt ' }[m.group()], match.group(0)) text = re.sub(r'(?