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