Skip to content
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

Voice data stops receiving after ~10 seconds #2310

Open
3 tasks done
kimjammer opened this issue Jan 5, 2024 · 4 comments
Open
3 tasks done

Voice data stops receiving after ~10 seconds #2310

kimjammer opened this issue Jan 5, 2024 · 4 comments
Labels
bug Something isn't working on hold

Comments

@kimjammer
Copy link

Summary

The UDP socket for receiving voice data becomes stuck in not ready state.

Reproduction Steps

  1. Bot joins voice channel
  2. Bot starts recording
  3. Talk for 10+ seconds.
  4. Stop bot recording
  5. Listen to recorded audio.

Minimal Reproducible Code

examples/audio_recording_merged.py

Expected Results

The UDP socket continues to become ready when more data is available, and the recorded audio file contains the full duration of audio.

Actual Results

The UDP socket becomes stuck in the not ready state, and the audio file cuts off after ~10 seconds.

discord/voice_client.py Line 833 (on main)

# After ~10 seconds, the ready variable is always False
ready, _, err = select.select([self.socket], [], [self.socket], 0.01) 

Intents

All

System Information

  • Python v3.10.10-final
  • py-cord v2.4.1-final (main branch on github, not 2.4.1 release. But also reproducible on 2.4.1 stable)
  • aiohttp v3.9.1
  • system info: Windows 10 10.0.22635

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

For the first ~10 seconds, the socket cycles between ready and not ready as more voice data is streamed in. However, the socket suddenly becomes stuck in the not ready state for no apparent reason.

@kimjammer kimjammer added the unconfirmed bug A bug report that needs triaging label Jan 5, 2024
@lukaskuhn-lku
Copy link

I tried it with multiple sinks and logged it in multiple ways. The voice data just stops recording after roughly 14s-15s.

@lukaskuhn-lku
Copy link

Also replicated on MacOS

@JustaSqu1d JustaSqu1d added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels Jan 11, 2024
@aipowertmk
Copy link

Replicated on Linux Debian.

@AWeirdDev
Copy link

AWeirdDev commented Jul 3, 2024

Replicated on Windows.

I tried to maintain the connection by sending audio packets like \xf8\xff\xfe (frames of silence) when an audio sample was received and it seemed to receive data as normal ever since.

            ...  # existing code from discord/voice_client.py
            try:
                data = self.socket.recv(4096)
            except OSError:
                self.stop_recording()
                continue

            self.unpack_audio(data)

            # == ADDED ==
            self.empty_socket()
            self.send_audio_packet(b"\xf8\xff\xfe")
            # ===========

        # ...existing code below
        self.stopping_time = time.perf_counter()
        ...

However, there'd be a background noise when the user is speaking. Therefore, my approach was to mute the bot itself in my code:

await ctx.guild.change_voice_state(channel=channel, self_mute=True)

I could neither understand the socket connection details from the documentation nor had an experience with sockets, but I assumed it was due to improper connection maintenance handling.

Best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on hold
Projects
None yet
Development

No branches or pull requests

6 participants