Files
javis_bot/src/voice_worker/__main__.py
javis-bot b94e9dc112 feat(app): background collection frame for sites, search words and RSS feeds
Targets (none by default), interval and keep days on a new 백그라운드 수집 screen with the
results; the worker collects on its own thread through the web search's address check and
writes only to the data folder's collect/ (logs carry target names and counts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:29:49 +09:00

102 lines
3.9 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()
async def run() -> None:
worker = VoiceWorker(token, transcriber, vad.stream, tts, history=history, brain=brain)
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'}",
"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()
return 0
if __name__ == "__main__":
sys.exit(main())