Skip to content

Commit 1030c5b

Browse files
committed
use _speech_lock to prefent espeak and piper speaks the same time
1 parent 2714c37 commit 1030c5b

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py
12
import os
23
import random
34
import re
@@ -7,8 +8,11 @@
78
import datetime
89
import sys
910
import urllib.request
11+
import threading
12+
1013
from pathlib import Path
1114
import subprocess # Added for espeak support
15+
# config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py
1216

1317
# --- METADATA ---
1418
VERSION = "1.1.0"
@@ -27,6 +31,7 @@
2731
# Go up to the repository root
2832
REPO_ROOT = SCRIPT_DIR.parents[4]
2933

34+
_speech_lock = threading.Lock()
3035

3136
def init_db():
3237
"""
@@ -179,29 +184,29 @@ def save_to_aura_db(question, answer, file_path):
179184
PIPER_SERVER_URL = f"https://{PIPER_SERVER_HOST}:{PIPER_SERVER_PORT}/speak"
180185
PIPER_SPEAK_FILE = os.path.expanduser("~/projects/py/TTS/speak_file.py")
181186

182-
import threading
183187

184188
def speak(text, voice="de-de", pitch=50, blocking=False, use_espeak=False):
185189
if not text or not globals().get('SPEECH_ENABLED', True):
186190
return None
187191

188192
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
190206
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])
197208
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}")
205210

206211
t = threading.Thread(target=_do_speak, args=(use_espeak,))
207212
t.start()

scripts/py/func/checks/integrity_rules.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@
187187

188188

189189

190+
"config/maps/plugins/z_fallback_llm/de-DE/radio_deep_dive.py": [
191+
'espeak-ng',
192+
'lstrip("/docs/',
193+
],
194+
190195
# should_remove_zips_after_unpack=true It's eventually useful to have it sometimes longer but maybe not online and not at costumers
191196

192197
# --- Start of Ensures language selection is included ---

0 commit comments

Comments
 (0)