Files
javis_bot/app/tests/fixtures/fake_engine_worker.py
javis-bot f892a1dce9 feat: answer calls in the voice channel through the response policy
- conversation.rs: the loop between the core's events and the rest.
  Finals go through call detection and the response policy; answers are
  asked of the brain and spoken from the app's queue, an interruption
  cancels only that answer, a voice stop silences everything, and missed
  requests are kept without text (last 100). Tested with a fake voice side.
- Core: answer(user, text) adopts a playback request the worker speaks
  under the same id, cancel(id) stops one request, ask_addressed and
  ask_rank pass the conversation's questions; new SpeakingStopped,
  Addressed and Ranked events.
- Worker client: reply, addressed and rank messages and their results; a
  reply with no answer, refused or not sent ends its speech as failed.
- Voice worker: addressed and rank messages on their own threads, beside
  a running reply; a spoken reply cancelled while the brain is answering
  is not spoken. judges.py holds the two short LLM judgements with the
  heard text fenced as data; eval evals/test_voice_judges.py.
- Specs (conversation, discord core, voice worker), docs/llm_contexts.md
  and the roadmap updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 22:26:47 +09:00

55 lines
1.6 KiB
Python

"""The real voice worker server with fake engines, for the app's protocol tests (no GPU, no models).
The fake VAD reads speech probability off the amplitude; the fake transcriber names a clip by its
pitch ("level 0.9" for a 900 Hz tone); the fake TTS makes 10 samples per character; the fake brain answers every reply with two sentences.
Run with the repo's src/ on PYTHONPATH: python fake_engine_worker.py <port>
"""
import asyncio
import os
import sys
import numpy as np
from voice_worker.server import VoiceWorker
class AmplitudeVad:
def prob(self, window):
return float(np.max(np.abs(window)))
class LevelTranscriber:
def transcribe(self, clips, opts):
return [f"level {np.argmax(np.abs(np.fft.rfft(c))) * 16000 / len(c) / 1000:.1f}" for c in clips]
class FakeBrain:
"""Answers with two sentences, says only "켜" (on) requests were said to it, ranks in reverse."""
def reply(self, user, text, history, chat=None):
return "첫 문장입니다. 둘째 문장입니다."
def addressed(self, user, text, names):
return "켜" in text
def rank(self, candidates):
return [c["id"] for c in reversed(candidates)]
class FakeTts:
def synthesize(self, text, rate):
return np.full(len(text) * 10, 1000, dtype=np.int16)
async def main(port: int) -> None:
worker = VoiceWorker(os.environ["JARVIS_VOICE_TOKEN"], LevelTranscriber(), AmplitudeVad, FakeTts(),
brain=FakeBrain())
server = await worker.serve("127.0.0.1", port)
print(f"READY 127.0.0.1:{port}", flush=True)
await server.serve_forever()
if __name__ == "__main__":
asyncio.run(main(int(sys.argv[1])))