feat(app): M2 Discord voice core in the Electron app
- app/ (Electron 45 + TypeScript): the core joins one voice channel, decodes each speaker's Opus to 48 kHz stereo and streams it to the voice worker, sends speaking_end and speaker_leave, and emits speech_start/partial/final with the speaker's display name. - Sentence playback from the worker's TTS, first come first served, with stop that silences the clip at once and cancels unfinished requests; slash command join/leave/stop (create-or-update by name). - Transcription notice posted on every join; other bots ignored by default; at most maxSpeakers people transcribed at once. - Registered chat channels: live message events, history reads, sends split at 2,000 characters with mentions disabled; Message Content intent checked before login. - The app starts the Python voice worker with a fresh token in the environment, restarts it with backoff, and the worker client reconnects and fails in-flight TTS on a lost connection. - Spec in app/src/core/discord_core.spec.md; Vitest unit tests, a protocol test against the real Python worker server with fake engines, and an opt-in live test with two bots on real Discord. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
40
app/test/fixtures/fake_engine_worker.py
vendored
Normal file
40
app/test/fixtures/fake_engine_worker.py
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"""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.
|
||||
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 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())
|
||||
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])))
|
||||
Reference in New Issue
Block a user