Skip to content

feat(voice): real-time voice calls with /voz - #45

Merged
Zeptiny merged 2 commits into
mainfrom
feat/voice-calls
Nov 13, 2026
Merged

Zeptiny merged 2 commits into
mainfrom
feat/voice-calls

Conversation

@Zeptiny

@Zeptiny Zeptiny commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

What this adds

/voz entrar brings the bot into the caller's voice channel and talks with the call in real time through Qwen-Audio realtime (qwen-audio-3.0-realtime-plus, speech in and speech out). /voz sair ends the call.

  • Hearing the call: discord.py can send voice but not receive it, and Discord has required DAVE end-to-end encryption since March 2026. core/voice_receive.py adds receive on discord.py's own hooks. The voice websocket maps each RTP ssrc to a user, and every UDP packet loses, in order, its transport encryption (aead_xchacha20_poly1305_rtpsize), its RTP padding, the DAVE layer (using discord.py's live davey session) and opus.
  • The call (core/voice_call.py):
    • Everyone except bots is mixed into one 16 kHz stream. The stream never pauses, because the server's turn detection measures silence on it.
    • The model's audio plays back through VoiceClient.play.
    • Someone talking over the bot for VOICE_BARGE_IN_MS (default 700 ms, 0 = never) cuts it off and cancels the response. This is measured on our side from Discord's voice activity. The server's speech_started doesn't cut on its own, because smart_turn_v2 also sends it for side talk it later rejects. A new answer starting while the last one is still playing cuts what's left of it.
    • Transcripts go to the call's text chat in conversation order, credited to whoever was talking at the time. A bot line that gets talked over is marked or edited with ….
    • A watchdog leaves when everyone has left, nobody has talked for VOICE_IDLE_MINUTES, the call hits VOICE_MAX_MINUTES, or the voice connection is lost.
  • Prompt: the server's <personalidade> block plus voice rules: short spoken sentences, no markdown, and no addressing people by name, since the model can't tell voices apart. The prompt also gives the bot's name. The only tool is the silence one below.
  • Choosing when to answer:
    • smart_turn_v2 already passes over most side talk: it ends those turns as turn_invalid and creates no response.
    • VOICE_CAN_STAY_SILENT (on by default) gives the model a ficar_em_silencio tool to call instead of speaking. Live under server_vad, it called the tool for every line aimed at someone else, within about 50 ms and with no audio. Qwen-Audio 3.0 can't combine tools with web search, so VOICE_WEB_SEARCH turns this off, with a startup warning.
    • VOICE_WAKE_WORDS (optional, e.g. Quill,Quil,Kill) answers only turns whose transcript names the bot. Each answer is held until its transcript arrives, about 0.3 s after the audio starts. It is then either played, or cancelled, left unposted, and deleted from the conversation (conversation.item.delete) so the model doesn't remember an answer nobody heard. The greeting and the join message tell people the name.
  • Opt-in, twice: /voz only loads with VOICE_ENABLED, VOICE_API_KEY, VOICE_REALTIME_URL and libopus present. Each server must also turn on the new voice setting (/config servidor), since a call's audio goes to Alibaba Cloud. On joining, the bot says it is listening and posts that disclosure.

Dependencies

  • discord.py[voice]>=2.7.0,<2.8 and davey>=0.1.7,<0.2. davey 0.2, released Nov 2, breaks discord.py 2.7's DAVE handling: the bot joins but nobody hears it (discord.py#10549, fix pending in #10548). The discord.py cap is there because the receive path uses its voice internals.
  • The Dockerfile and CI install libopus0.

Key choice

VOICE_API_KEY and VOICE_REALTIME_URL are explicit, and .env.example and the README document both endpoints. Token Plan Personal Edition keys (sk-sp-…) are restricted by their terms to one person's interactive use, with no production services and no key sharing. A community bot is both, so a pay-as-you-go key is the safe choice for production.

Testing

  • 69 new tests, 291 in total, passing on Python 3.11 (the version CI and the image use) and 3.14; ruff check . is clean. They cover:
    • resampling quality, the per-speaker mixer and the playback buffer;
    • RTP decryption, including discord.py's own packets, header extensions and padding;
    • the DAVE layer and opus decoding;
    • the realtime client against a local fake server;
    • the call logic: barge-in and its setting, a new answer cutting the last, the silence tool, wake words (held, released, dropped and deleted), transcript ordering and edits, the watchdog and shutdown;
    • the cog's join checks.
  • Live, against the real model: the full pipeline ran with only Discord faked. Two synthetic speakers fed 48 kHz frames at real-time pace. The greeting, Portuguese replies, transcripts credited to the right speaker, interrupting, and ignoring a music bot all worked. A second set of live runs mixed lines for the bot with side talk, across three setups: wake words on server_vad, wake words with the silence tool off (forcing real cancels), and plain smart_turn_v2. Only the lines addressed to the bot were answered in every run, with 0 errors.
  • Not tested yet: a real Discord call. The UDP/DAVE receive path has only seen packets built in tests. If the first call hears nothing, look for the [voice] … packets … but none decoded warning (it includes the DAVE state), or the receive= counts in the call ended log line.

Known limitations

  • The model hears one mixed stream. With wake words on, every sentence has to name the bot; there's no follow-up window after an answer yet.
  • No memory, docs or history tools during calls.
  • Transcripts come from speech recognition, can be wrong, and are public; VOICE_TRANSCRIPTS=false turns them off.

🤖 Generated with Claude Code

/voz entrar brings the bot into the caller's voice channel and connects it
to Qwen-Audio realtime (speech in, speech out); /voz sair ends the call.

discord.py sends voice but can't receive it, and Discord has required DAVE
end-to-end encryption since March 2026. core/voice_receive.py adds receive
on discord.py's own hooks: the voice websocket maps each RTP ssrc to a user,
every UDP packet loses its transport encryption and RTP padding, then the
DAVE layer (discord.py's davey session), then opus.

core/voice_call.py runs a call: everyone but bots mixed into one 16 kHz
stream that never pauses (the server's turn detection measures silence on
it), the model's audio played back, barge-in after ~0.7 s of someone talking
over the bot (smart_turn_v2 only reports speech once the turn is over),
transcripts in the call's chat in conversation order with who spoke, and a
watchdog for empty, idle, over-long or disconnected calls. The idle default
(2.5 min) stays under the model's 180 s no-response limit.

Off unless VOICE_ENABLED, VOICE_API_KEY and VOICE_REALTIME_URL are set, and
each server opts in with the `voice` setting. davey stays below 0.2 and
discord.py below 2.8 (davey 0.2 breaks discord.py 2.7's voice:
Rapptz/discord.py#10549). The image and CI install libopus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6bc4166b-b24a-4fa3-a3c7-1c5ea43f75da
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…n setting

- VOICE_BARGE_IN_MS: how long talking over the bot stops it (0 = never).
  The server's speech_started no longer cuts by itself (smart_turn reports
  side talk it later rejects); a new answer starting still cuts the last.
- VOICE_WAKE_WORDS: answer only turns whose transcript names the bot. The
  answer is held until that transcript arrives, then played or cancelled,
  unposted and deleted from the conversation.
- VOICE_CAN_STAY_SILENT: a ficar_em_silencio tool the model calls instead
  of speaking; the prompt no longer tells it to always reply. Off when web
  search is on (Qwen-Audio 3.0 can't combine them).
- The prompt names the bot; the greeting and join message give the wake word.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Zeptiny
Zeptiny merged commit f51c897 into main Nov 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant