-
-
Notifications
You must be signed in to change notification settings - Fork 477
voice_client receiving voice errors / not working ? #2644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@borick Could you please share the full error traceback ? |
I have a similar error that's been plaguing me as well. I believe it's the same thing @borick is experiencing. It always happens every 3-20 seconds when receiving audio. I've been going crazy on this one, turning on/off various snippets in my own code to no avail. I'll attach my code as well for propriety--as it's only five small files--but I think this is an issue with the library itself, as my portion is never referenced in the call stack + keeps occurring no matter what I've tried. Exception
|
By my testing it seems to be when the audio is short, and nothing is being said / no actual sound is occurring. (keep in mind I'm using MP3Sink not WAVSink / your custom SilenceDetectionSink) I'm currently just modify the code snippet and putting it in a try-except block for Index errors but this is a really messy solution so hopefully we get a fix soon. @staticmethod
def strip_header_ext(data):
try:
if data[0] == 0xBE and data[1] == 0xDE and len(data) > 4:
_, length = struct.unpack_from(">HH", data)
offset = 4 + length * 4
data = data[offset:]
except IndexError as e:
print(f"The IndexError occurred but we will ignore it! Just means this part of the data probably is 0 bytes.. Data: {data}")
return data |
I want to mention I'm also getting this error. I wasn't getting it in the past, but since downgrading from Windows 10 to Windows 11 with a new PC, I started getting this error when I have multiple people speaking at the same time. |
@AboveAphid 's 'temporary' solution seems fine for me until we get a proper fix ~ wonder if anyone found another solution |
@bot.slash_command(description="test")
async def record(ctx):
voice = ctx.author.voice
if not voice:
await ctx.respond("You aren't in a voice channel!")
return
vc = await voice.channel.connect()
connections[ctx.guild.id] = vc
sink = discord.sinks.MP3Sink()
vc.start_recording(sink, once_done, ctx.channel)
await ctx.respond("Started recording!")
async def once_done(sink: discord.sinks, channel: discord.TextChannel, *args):
recorded_users = [f"<@{user_id}>" for user_id in sink.audio_data.keys()]
await sink.vc.disconnect()
files = []
for user_id, audio in sink.audio_data.items():
try:
cleaned_audio = strip_header_ext(audio.file.read())
if cleaned_audio:
file = discord.File(audio.file, f"{user_id}.{sink.encoding}")
files.append(file)
else:
print(f"Skipping empty or corrupted audio file for user {user_id}.")
except Exception as e:
print(f"Error {user_id}: {e}")
if files:
await channel.send(f"Finished recording audio for: {', '.join(recorded_users)}.", files=files)
else:
await channel.send("Recording finished, but no valid audio was detected. Bruh.")
@bot.slash_command(description="test2")
async def stop_recording(ctx):
if ctx.guild.id in connections:
vc = connections.pop(ctx.guild.id, None)
if vc:
vc.stop_recording()
await ctx.respond("Stopped recording.")
else:
await ctx.respond("I am currently not recording here.")
@staticmethod
def strip_header_ext(data):
try:
if len(data) > 4 and data[0] == 0xBE and data[1] == 0xDE:
_, length = struct.unpack_from(">HH", data)
offset = 4 + length * 4
return data[offset:]
except IndexError:
print("IndexError: Skipping malformed or empty packet.")
return data Hi, I'm currently experiencing the same issue reported by others regarding MP3Sink recordings in Pycord. When recording a voice channel, everything works fine for short durations (10–20 seconds), but for longer sessions (e.g., 2 minutes or more), the resulting MP3 files are often corrupted or completely empty (0 bytes). I attempted to implement the suggested temporary fix using strip_header_ext(data) to handle malformed packets. However, this does not resolve the issue—recordings still produce empty MP3 files, I also wrapped the decoding process in a try-except block to catch IndexError, but this only prevents crashes and does not fix the underlying problem.
Additionally, after the recording completes, the generated MP3 files are either:
Would appreciate any other fixes for this issue. |
I just put the length check before the byte checks, and it seems to keep audio data intact and prevent any crashes, as I didn't really modify logic, just reorder an if statement. |
Summary
trying to use voice_client getting errors
Reproduction Steps
talk to bot using discord voice and it errors out for me i'm not sure why, i'm trying to get the voice to respond to voice automatically without having to start a command is this possible?
Minimal Reproducible Code
Expected Results
it works, responds to voice
Actual Results
errors out , or does nothing
Intents
the default
System Information
intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
intents.voice_states = True
Checklist
Additional Context
n/a
The text was updated successfully, but these errors were encountered: