#Unable to process audio from stage channels

1 messages · Page 1 of 1 (latest)

valid mesa
#

When I attempt to process audio after my bot joins a stage channel, I get this error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/project/lib/python3.8/site-packages/discord/voice_client.py", line 863, in recv_audio
    self.unpack_audio(data)
  File "/home/ubuntu/project/lib/python3.8/site-packages/discord/voice_client.py", line 740, in unpack_audio
    data = RawData(data, self)
  File "/home/ubuntu/project/lib/python3.8/site-packages/discord/sinks/core.py", line 115, in __init__
    self.decrypted_data = getattr(self.client, f"_decrypt_{self.client.mode}")(
  File "/home/ubuntu/project/lib/python3.8/site-packages/discord/voice_client.py", line 611, in _decrypt_xsalsa20_poly1305_lite
    return self.strip_header_ext(box.decrypt(bytes(data), bytes(nonce)))
  File "/home/ubuntu/project/lib/python3.8/site-packages/nacl/secret.py", line 149, in decrypt
    plaintext = nacl.bindings.crypto_secretbox_open(
  File "/home/ubuntu/project/lib/python3.8/site-packages/nacl/bindings/crypto_secretbox.py", line 79, in crypto_secretbox_open
    ensure(
  File "/home/ubuntu/project/lib/python3.8/site-packages/nacl/exceptions.py", line 88, in ensure
    raise raising(*args)
nacl.exceptions.CryptoError: Decryption failed. Ciphertext failed verification

I see an open but unresolved github issue about it: https://github.com/Pycord-Development/pycord/issues/2033.

I tested the same code when joining a regular voice channel, and it works. Just a stage channel. I've also experimented with making the bot a speaker, muting, etc. Nothing seems to work.

Note: I've tried upgrading python version and pycord version to 2.6.1, but it doesn't change the error.

GitHub

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python - Issues · Pycord-Development/pycord

valid mesa
tight haven
#

The support for 3.8 got dropped

valid mesa
#

It's unrelated

tight haven
#

the Error you send it 3.8

valid mesa
#

Seems to be an open issue so I'm not sure why this is but looks like it is isolated to stage channels

unborn herald
valid mesa
#

I get the exact same error

unborn herald
#

"no matter if its related or not"

#

read my message too

valid mesa
#

I'm using 3.10 now

unborn herald
#

which is also 3 years old by now

valid mesa
#

what version should I use

scenic aurora
#

at this point it is not a python version problem. And pycord does support 3.10 so the bug should be fixed regardless

valid mesa
#

If anyone has any suggestions would greatly appreciate it

#

It's weird that it works on regular voice channels

unborn herald
scenic aurora
#

Does this happen immediately or only after a long time of listening like in the github issue?

unborn herald
#

but 3.12 currently because theres a bug with pycord on 3.13

valid mesa
#

that's the other odd thing

#

It errors out immediately, if there's sound playing or even if there's nothing playing

unborn herald
#

im not sure if this is needed anymore but did you install pycord[voice] ?

valid mesa
#

No I didn't. I installed pycord=2.6.1

unborn herald
#

try pycord[voice]

valid mesa
#

Does this have anything to do with it? #discussion message

unborn herald
#

well its a nacl issue from what i can see

#

or at least nacl throws the error

valid mesa
unborn herald
#

well technically its only deprecated until tomorrow lol

scenic aurora
#

Thats what I am wondering, we nelo said we are fine but I wonder if that is wrong.
In any case that should still work until the 18th though.

unborn herald
#

or discord just said fuck it and removed it earlier

#

would fit discord

#

on an unrelated note i wonder why almost every python library targets voice API version 4
like thats so old, and they all do it, but only for python

#

surely just targeting the newest one would prevent such issues

#

my only idea would be to manually update the nacl package to the newest version

scenic aurora
unborn herald
#

lol
so whats the plan for tomorrow when its officially supposed to be removed?

#

like the 2 algorithms or whatever

scenic aurora
#

Nelo said it was fine because 4 is still supported. I dont think it is tho...

unborn herald
#

it is according to that message

#

just not those 2 whatever-it-is

scenic aurora
#

So from what I can tell it seems like the data is somehow malformed/changed so nacl cannot decrypt it.
The question is if discord is being weird or if pycord reads it wrong when receiving or something

valid mesa
scenic aurora
unborn herald
#

why do people not comment when they do seemingly nonsenical stuff like that

#

a simple "cutting off 12 bytes cause" wouldve helped already

scenic aurora
unborn herald
#

yea but its not nov 18 in any country

scenic aurora
#

they are already deprecated according to this and will be discontinued on Nov 18th. Unless that is a typo

unborn herald
#

yea but deprecated means it still works

scenic aurora
#

Oh, i read that wrong, they worded it weird.

#

nevermind

scenic aurora
#

To be honest. Everything looks fine. The only thing I can think of is that discord is sending a voice packet of more than 4096 bytes. I dont know if the max size is documented anywhere

scenic aurora
#

@valid mesa
Can you try putting this code before you define the voice client object in your code

VoiceClient.supported_modes = (
        "xsalsa20_poly1305",
    )

If that does not work try

VoiceClient.supported_modes = (
        "xsalsa20_poly1305_suffix",
    )
scenic aurora
#

Can you show me that section of the code. Just so I know you are doing it right (I dont want us to get confused

valid mesa
# scenic aurora Can you show me that section of the code. Just so I know you are doing it right ...
    @tasks.loop(seconds=10.0)  # Reduced interval for quicker detection
    async def search_for_live(self) -> None:
        if not self.is_in_stage:
            voice_client = await could_join_stage(self.bot)
            if voice_client:
                self.is_in_stage = True
                self.voice_client = voice_client
                self.voice_client.supported_modes = ("xsalsa20_poly1305",)
                await self.send_log_message(message="Joined stage!")
                await self.start_recording()

voice_client comes from the could_join_stage() function via this line:

...
voice_client = await channel.connect()
return voice_client
scenic aurora
#

I think you need to do it on the actuall VoiceClient class not an object

#

I think you could just import the class in your main file or something and just paste the 2 snippets I sent above in there one at a time

valid mesa
scenic aurora
valid mesa
# scenic aurora Could you paste the full traceback. I think this is going backwards though not f...
File "/home/ubuntu/project/lib/python3.10/site-packages/discord/voice_client.py", line 863, in recv_audio
    self.unpack_audio(data)
  File "/home/ubuntu/project/lib/python3.10/site-packages/discord/voice_client.py", line 740, in unpack_audio
    data = RawData(data, self)
  File "/home/ubuntu/project/lib/python3.10/site-packages/discord/sinks/core.py", line 115, in __init__
    self.decrypted_data = getattr(self.client, f"_decrypt_{self.client.mode}")(
  File "/home/ubuntu/project/lib/python3.10/site-packages/discord/voice_client.py", line 602, in _decrypt_xsalsa20_poly1305_suffix
    return self.strip_header_ext(box.decrypt(bytes(data[:-nonce_size]), nonce))
  File "/home/ubuntu/project/lib/python3.10/site-packages/nacl/secret.py", line 149, in decrypt
    plaintext = nacl.bindings.crypto_secretbox_open(
  File "/home/ubuntu/project/lib/python3.10/site-packages/nacl/bindings/crypto_secretbox.py", line 78, in crypto_secretbox_open
    res = lib.crypto_secretbox_open(plaintext, padded, len(padded), nonce, key)
TypeError: initializer for ctype 'unsigned char *' must be a cdata pointer, not bytearray
#

I don't know what type of data it's trying to pass here. Ignoring the exception doesn't seem to work but I'm still messing with it

scenic aurora
#

What is the output of

import nacl
print(nacl.secret.SecretBox.NONCE_SIZE)
valid mesa
#
>>> import nacl
>>> print(nacl.secret.SecretBox.NONCE_SIZE)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'nacl' has no attribute 'secret'
#

hmmmm

#

brb

scenic aurora
#

uhhh, try import nacl.secret?

scenic aurora
#

@valid mesa You can try using the PR for the new voice encodings.
pip install git+https://github.com/Pycord-Development/pycord.git@refs/pull/2651/head
This is going to be required tomorrow so no point trying to debug the old ones at this point

arctic pier
arctic pier
# remote python wdym?

Voice encoding changed. There's no point on debugging a bug on the old encodings methods.

scenic aurora
#

@remote python I think I fixed it and you can make the changes manually based on the diff here https://github.com/NeloBlivion/pycord/pull/2
The problem seemed to be that discord was sending non-opus packets that we need to ignore.

remote python
scenic aurora
#

Huh, I completely selected the wrong thread when sending this message.

remote python
#

all good

#

saw the message