jarvis.py aktualisiert
This commit is contained in:
24
jarvis.py
24
jarvis.py
@@ -539,7 +539,7 @@ async def listen_to_user():
|
||||
# JARVIS OUTPUT
|
||||
# ====================================================
|
||||
|
||||
def speak_to_user(text):
|
||||
async def speak_to_user(text):
|
||||
print(f"\n{JARVIS_COLOR}🤖 J.A.R.V.I.S.{RESET}")
|
||||
print(f"{JARVIS_COLOR}{'-'*60}{RESET}")
|
||||
print(text)
|
||||
@@ -554,11 +554,6 @@ def speak_to_user(text):
|
||||
OUTPUT_FILE = "/tmp/jarvis_response.mp3"
|
||||
LOCK_FILE = "/tmp/.jarvis_speaking"
|
||||
|
||||
# Innerer asynchroner Task für den Cloud-Abruf
|
||||
async def generate_audio():
|
||||
communicate = edge_tts.Communicate(text, VOICE)
|
||||
await communicate.save(OUTPUT_FILE)
|
||||
|
||||
try:
|
||||
# 1. Erstelle die Lock-Datei, damit das Mikrofon im Wakeword-Skript stummschaltet
|
||||
with open(LOCK_FILE, "w") as f:
|
||||
@@ -566,15 +561,18 @@ def speak_to_user(text):
|
||||
|
||||
print(f"🔊 J.A.R.V.I.S. spricht: {text}")
|
||||
|
||||
# 2. Audio aus der Cloud abrufen
|
||||
asyncio.run(generate_audio())
|
||||
# 2. Audio aus der Cloud abrufen (Jetzt sauber mit direktem await!)
|
||||
communicate = edge_tts.Communicate(text, VOICE)
|
||||
await communicate.save(OUTPUT_FILE)
|
||||
|
||||
# 3. Audio ressourcenschonend abspielen (stdout/err unterdrücken)
|
||||
subprocess.run(
|
||||
["mpv", "--no-video", OUTPUT_FILE],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
# 3. Audio ressourcenschonend & asynchron abspielen
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"mpv", "--no-video", OUTPUT_FILE,
|
||||
stdout=asyncio.subprocess.DEVNULL,
|
||||
stderr=asyncio.subprocess.DEVNULL
|
||||
)
|
||||
# Warten, bis mpv fertig gesprochen hat
|
||||
await proc.wait()
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler bei der Sprachausgabe: {e}")
|
||||
|
||||
Reference in New Issue
Block a user