Files
javis_bot/src/voice_worker/__main__.py
javis-bot cbe898d3d0 feat(app): log screen saves (shown lines, conversation, voice recordings), stop-or-finish on a new request, video pages that play
- 로그 screen: "보이는 글 txt로 저장" (logs_save_text), a 대화 view that saves the days'
  conversation with every trace in full (history_export), and a 목소리 view with the
  voice.record switch and the days' recordings as a zip with an index (voice_export).
- Voice worker: with JARVIS_RECORDINGS_DIR (voice.record, off by default) each final and each
  spoken answer is kept as a WAV with an index line; day folders older than 7 days removed.
- response.interrupt (default on): off, latest/important finish the running answer first.
- Bot browser: Chrome lets pages start video and sound; botBrowser reports each page's media
  state, waits for a player to start after open/click, and presses play on a video page a click
  led to when its player stayed paused (live: a clicked YouTube video stayed paused).
- webSearch reads `query` when `search_query` is missing (live: both searches of an answer failed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:27:57 +09:00

111 lines
4.2 KiB
Python

"""``JARVIS_VOICE_TOKEN=... python -m voice_worker`` (see voice_worker.spec.md)."""
from __future__ import annotations
import argparse
import asyncio
import os
import sys
from .log import debug_log
def main() -> int:
ap = argparse.ArgumentParser(prog="voice_worker")
ap.add_argument("--host", default="127.0.0.1")
ap.add_argument("--port", type=int, default=8771)
ap.add_argument("--stt-model", default="large-v3-turbo")
ap.add_argument("--stt-device", default="cuda")
ap.add_argument("--stt-compute", default="int8_float16")
ap.add_argument("--melo-python", default=None, help="python of the MeloTTS venv; no TTS without it")
ap.add_argument("--melo-device", default="cuda")
ap.add_argument("--melo-speed", type=float, default=1.5)
ap.add_argument("--melo-language", default="KR")
ap.add_argument("--history", default=None, help="conversation history SQLite file; no history without it")
ap.add_argument("--brain", action="store_true",
help="answer reply requests with the jarvis reply engine (needs --history)")
ap.add_argument("--reply-language", default="Korean",
help="answers come in this language unless the asker asks for another; '' for the asker's")
ap.add_argument("--tool-language", default="ko", help="ISO code tools get (e.g. the Wikipedia host)")
args = ap.parse_args()
if args.brain and not args.history:
print("--brain needs --history", file=sys.stderr)
return 2
token = os.environ.get("JARVIS_VOICE_TOKEN", "")
if not token:
print("JARVIS_VOICE_TOKEN is not set", file=sys.stderr)
return 2
# The MCP servers' secrets leave the environment before any child process (MeloTTS) starts;
# only the brain gets them (voice_worker.spec.md, "Tools").
from .brain import take_mcp_env
mcp_env = take_mcp_env()
from .server import VoiceWorker, is_loopback
from .stt_whisper import WhisperTranscriber
from .vad import SileroVad
if not is_loopback(args.host):
print("the voice worker only listens on a loopback address", file=sys.stderr)
return 2
transcriber = WhisperTranscriber(args.stt_model, args.stt_device, args.stt_compute)
transcriber.warm_up()
vad = SileroVad()
tts = None
if args.melo_python:
from .tts_melo import MeloEngine
tts = MeloEngine(args.melo_python, args.melo_device, args.melo_speed, args.melo_language)
history = brain = None
if args.history:
from jarvis.memory.history import HistoryStore
history = HistoryStore(args.history)
if args.brain:
from .brain import JarvisBrain
brain = JarvisBrain(language=args.tool_language or None, reply_language=args.reply_language or None,
mcp_env=mcp_env)
# Background collection runs apart from the voice and the brain (voice_worker.spec.md).
collector = None
if os.environ.get("JARVIS_COLLECT_PATH"):
from .collect import Collector, load_config
collector = Collector(load_config(os.environ["JARVIS_COLLECT_PATH"]))
collector.start()
# Voice recordings for checking what was heard and said, only when the app turns them on.
recorder = None
from .recordings import RECORDINGS_ENV, Recorder
if os.environ.get(RECORDINGS_ENV):
recorder = Recorder(os.environ[RECORDINGS_ENV])
async def run() -> None:
worker = VoiceWorker(token, transcriber, vad.stream, tts, history=history, brain=brain, recorder=recorder)
server = await worker.serve(args.host, args.port)
debug_log(f"voice worker listening on {args.host}:{args.port} tts={'on' if tts else 'off'} "
f"history={'on' if history else 'off'} brain={'on' if brain else 'off'} "
f"recordings={'on' if recorder else 'off'}",
"voice_worker")
print(f"READY {args.host}:{args.port}", flush=True)
await server.serve_forever()
try:
asyncio.run(run())
except KeyboardInterrupt:
pass
finally:
if collector:
collector.stop()
if tts:
tts.close()
if history:
history.close()
if recorder:
recorder.close()
return 0
if __name__ == "__main__":
sys.exit(main())