|
| 1 | +# config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py |
1 | 2 | import os |
2 | 3 | import random |
3 | 4 | import re |
|
7 | 8 | import datetime |
8 | 9 | import sys |
9 | 10 | import urllib.request |
| 11 | +import threading |
| 12 | + |
10 | 13 | from pathlib import Path |
11 | 14 | import subprocess # Added for espeak support |
| 15 | +# config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py |
12 | 16 |
|
13 | 17 | # --- METADATA --- |
14 | 18 | VERSION = "1.1.0" |
|
27 | 31 | # Go up to the repository root |
28 | 32 | REPO_ROOT = SCRIPT_DIR.parents[4] |
29 | 33 |
|
| 34 | +_speech_lock = threading.Lock() |
30 | 35 |
|
31 | 36 | def init_db(): |
32 | 37 | """ |
@@ -179,29 +184,29 @@ def save_to_aura_db(question, answer, file_path): |
179 | 184 | PIPER_SERVER_URL = f"https://{PIPER_SERVER_HOST}:{PIPER_SERVER_PORT}/speak" |
180 | 185 | PIPER_SPEAK_FILE = os.path.expanduser("~/projects/py/TTS/speak_file.py") |
181 | 186 |
|
182 | | -import threading |
183 | 187 |
|
184 | 188 | def speak(text, voice="de-de", pitch=50, blocking=False, use_espeak=False): |
185 | 189 | if not text or not globals().get('SPEECH_ENABLED', True): |
186 | 190 | return None |
187 | 191 |
|
188 | 192 | def _do_speak(use_espeak2): |
189 | | - if not use_espeak2: |
| 193 | + with _speech_lock: # 🔒 Nur eine Sprachausgabe gleichzeitig |
| 194 | + if not use_espeak2: |
| 195 | + try: |
| 196 | + with open('/tmp/speak_server_input.txt', 'w') as f: |
| 197 | + f.write(text) |
| 198 | + requests.post(PIPER_SERVER_URL, verify=False, timeout=60) |
| 199 | + return |
| 200 | + except requests.exceptions.ConnectionError: |
| 201 | + print(" !! Piper Server nicht erreichbar — Fallback zu espeak") |
| 202 | + except Exception as e: |
| 203 | + print(f" !! Piper Error: {e} — Fallback zu espeak-ng") |
| 204 | + |
| 205 | + # Fallback: espeak-ng |
190 | 206 | try: |
191 | | - with open('/tmp/speak_server_input.txt', 'w') as f: |
192 | | - f.write(text) |
193 | | - requests.post(PIPER_SERVER_URL, verify=False, timeout=60) |
194 | | - return |
195 | | - except requests.exceptions.ConnectionError: |
196 | | - print(" !! Piper Server nicht erreichbar — Fallback zu espeak") |
| 207 | + subprocess.run(["espeak-ng", "-v", voice, "-s", "150", "-p", str(pitch), text]) |
197 | 208 | except Exception as e: |
198 | | - print(f" !! Piper Error: {e} — Fallback zu espeak") |
199 | | - |
200 | | - # Fallback: espeak |
201 | | - try: |
202 | | - subprocess.run(["espeak", "-v", voice, "-s", "150", "-p", str(pitch), text]) |
203 | | - except Exception as e: |
204 | | - print(f" !! Speech Error (espeak): {e}") |
| 209 | + print(f" !! Speech Error (espeak-ng): {e}") |
205 | 210 |
|
206 | 211 | t = threading.Thread(target=_do_speak, args=(use_espeak,)) |
207 | 212 | t.start() |
|
0 commit comments