Repository navigation
feat(voice): real-time voice calls with /voz - #45
Merged
Merged
Conversation
/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>
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
/voz entrarbrings 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 sairends the call.core/voice_receive.pyadds 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 livedaveysession) and opus.core/voice_call.py):VoiceClient.play.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'sspeech_starteddoesn't cut on its own, becausesmart_turn_v2also 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.….VOICE_IDLE_MINUTES, the call hitsVOICE_MAX_MINUTES, or the voice connection is lost.<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.smart_turn_v2already passes over most side talk: it ends those turns asturn_invalidand creates no response.VOICE_CAN_STAY_SILENT(on by default) gives the model aficar_em_silenciotool to call instead of speaking. Live underserver_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, soVOICE_WEB_SEARCHturns 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./vozonly loads withVOICE_ENABLED,VOICE_API_KEY,VOICE_REALTIME_URLand libopus present. Each server must also turn on the newvoicesetting (/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.8anddavey>=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.libopus0.Key choice
VOICE_API_KEYandVOICE_REALTIME_URLare explicit, and.env.exampleand 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
ruff check .is clean. They cover:server_vad, wake words with the silence tool off (forcing real cancels), and plainsmart_turn_v2. Only the lines addressed to the bot were answered in every run, with 0 errors.[voice] … packets … but none decodedwarning (it includes the DAVE state), or thereceive=counts in thecall endedlog line.Known limitations
VOICE_TRANSCRIPTS=falseturns them off.🤖 Generated with Claude Code