Skip to content

Conversation

@aydiler
Copy link

@aydiler aydiler commented Jan 8, 2026

Summary

This PR fixes opus decode failures caused by incorrect 8-byte stripping in _decrypt_aead_xchacha20_poly1305_rtpsize.

PR #2925 added code to strip 8 bytes from decrypted audio data, but this corrupts the opus stream because the first byte is the opus TOC (Table of Contents) byte.

Testing Results

Offset Decode Success Audio Artifacts
8 bytes (current) ~80% 600+ clicks/second
0 bytes (this PR) 100% 0 clicks

Technical Details

  • The decrypted data is the opus packet directly
  • The first byte (e.g., 0x7c) is a valid opus TOC byte indicating config=15 stereo audio
  • Stripping 8 bytes removes the TOC byte and shifts all data, causing:
    • ~20% of packets fail to decode with OpusError: corrupted stream
    • Decoded audio has severe clicking/popping artifacts

Test Methodology

  1. Two Discord bots in the same voice channel
  2. Bot A plays audio, Bot B records with start_recording()
  3. Analyzed decoded PCM for sample discontinuities (>20k amplitude jumps)
  4. Compared decode success rates between stripped and non-stripped versions

Environment

  • py-cord 2.7.1.dev11
  • Python 3.13
  • Linux
  • Encryption mode: aead_xchacha20_poly1305_rtpsize

🤖 Generated with Claude Code

The `_decrypt_aead_xchacha20_poly1305_rtpsize` function was incorrectly
stripping 8 bytes from the decrypted audio data. This corrupts the opus
stream because the first byte is the opus TOC (Table of Contents) byte.

Testing results:
- With 8-byte stripping: ~80% decode success, 600+ audio clicks/second
- Without stripping: 100% decode success, 0 audio clicks

The decrypted data is the opus packet directly - the first byte (e.g.,
0x7c) is a valid opus TOC byte indicating config=15 stereo audio.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@pycord-app
Copy link

pycord-app bot commented Jan 8, 2026

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/3060/head:pr-3060
git checkout pr-3060

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3060/head

@Paillat-dev
Copy link
Member

Paillat-dev commented Jan 8, 2026

Hi, thank you for your pull request. Could you please provide clear and explicit reproduction steps AND code for this problem and open a related issue ? Thank you

@Paillat-dev Paillat-dev added voice Related to the voice chat feature priority: low Low Priority more info required More information is required to proceed hold: changelog This pull request is missing a changelog entry hold: testing This pull request requires further testing hold: discussion This pull request needs to be further discussed between maintainers labels Jan 8, 2026
@Lulalaby
Copy link
Member

Lulalaby commented Jan 8, 2026

This is incorrect according to discord docs and other library's implementation
Furthermore it won't be relevant anymore due to the switch to libdave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hold: changelog This pull request is missing a changelog entry hold: discussion This pull request needs to be further discussed between maintainers hold: testing This pull request requires further testing more info required More information is required to proceed priority: low Low Priority voice Related to the voice chat feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants