jarvis.py aktualisiert
This commit is contained in:
59
jarvis.py
59
jarvis.py
@@ -5,6 +5,7 @@ import asyncio
|
|||||||
import openai
|
import openai
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import edge_tts
|
||||||
|
|
||||||
from google import genai
|
from google import genai
|
||||||
from google.genai import types
|
from google.genai import types
|
||||||
@@ -544,28 +545,44 @@ async def speak_to_user(text):
|
|||||||
print(text)
|
print(text)
|
||||||
print(f"{JARVIS_COLOR}{'-'*60}{RESET}\n")
|
print(f"{JARVIS_COLOR}{'-'*60}{RESET}\n")
|
||||||
|
|
||||||
clean_text = re.sub(r'[^\w\s\d.,!?-]', '', text)
|
"""Generiert eine hochauflösende KI-Stimme via Edge-TTS und spielt sie ab."""
|
||||||
|
if not text.strip():
|
||||||
piper_path = "/home/meik/jarvis-ai/piper/piper"
|
return
|
||||||
model_path = "/home/meik/jarvis-ai/de_DE-thorsten-high.onnx"
|
|
||||||
lock_file = Path("/tmp/.jarvis_speaking") # Die Sperr-Datei
|
|
||||||
|
|
||||||
if os.path.exists(piper_path) and os.path.exists(model_path):
|
# Definition der Stimme (Killian und Conrad sind hervorragende deutsche Männerstimmen)
|
||||||
try:
|
VOICE = "de-DE-KillianNeural"
|
||||||
# 1. Sperre setzen
|
OUTPUT_FILE = "/tmp/jarvis_response.mp3"
|
||||||
lock_file.touch()
|
LOCK_FILE = "/tmp/.jarvis_speaking"
|
||||||
|
|
||||||
piper_cmd = f"echo '{clean_text}' | {piper_path} --model {model_path} --output_raw | aplay -r 22050 -f S16_LE -t raw -D pipewire >/dev/null 2>&1"
|
# Innerer asynchroner Task für den Cloud-Abruf
|
||||||
|
async def generate_audio():
|
||||||
proc = await asyncio.create_subprocess_shell(piper_cmd)
|
communicate = edge_tts.Communicate(text, VOICE)
|
||||||
await proc.wait()
|
await communicate.save(OUTPUT_FILE)
|
||||||
|
|
||||||
except Exception as e:
|
try:
|
||||||
print(f"⚠️ TTS Fehler: {e}")
|
# 1. Erstelle die Lock-Datei, damit das Mikrofon im Wakeword-Skript stummschaltet
|
||||||
finally:
|
with open(LOCK_FILE, "w") as f:
|
||||||
# 2. Sperre IMMER wieder aufheben, wenn Piper fertig ist
|
f.write("1")
|
||||||
if lock_file.exists():
|
|
||||||
lock_file.unlink()
|
print(f"🔊 J.A.R.V.I.S. spricht: {text}")
|
||||||
|
|
||||||
|
# 2. Audio aus der Cloud abrufen
|
||||||
|
asyncio.run(generate_audio())
|
||||||
|
|
||||||
|
# 3. Audio ressourcenschonend abspielen (stdout/err unterdrücken)
|
||||||
|
subprocess.run(
|
||||||
|
["mpv", "--no-video", OUTPUT_FILE],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Fehler bei der Sprachausgabe: {e}")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
# 4. Lock-Datei IMMER löschen, damit J.A.R.V.I.S. wieder zuhört
|
||||||
|
if os.path.exists(LOCK_FILE):
|
||||||
|
os.remove(LOCK_FILE)
|
||||||
|
|
||||||
# ====================================================
|
# ====================================================
|
||||||
# MAIN LOOP
|
# MAIN LOOP
|
||||||
|
|||||||
Reference in New Issue
Block a user