diff --git a/CHANGELOG.md b/CHANGELOG.md index dceebd4d14..4f74299ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2577](https://github.com/Pycord-Development/pycord/pull/2577)) - Fixed `codec` option for `FFmpegOpusAudio` class to make it in line with documentation. ([#2581](https://github.com/Pycord-Development/pycord/pull/2581)) +- Fixed a possible bug where audio would play too fast at the beginning of audio files. + ([#2584](https://github.com/Pycord-Development/pycord/pull/2584)) ### Changed diff --git a/discord/player.py b/discord/player.py index d7631907f0..508bf906ae 100644 --- a/discord/player.py +++ b/discord/player.py @@ -729,6 +729,9 @@ def __init__(self, source: AudioSource, client: VoiceClient, *, after=None): raise TypeError('Expected a callable for the "after" parameter.') def _do_run(self) -> None: + # attempt to read first audio segment from source before starting + # some sources can take a few seconds and may cause problems + first_data = self.source.read() self.loops = 0 self._start = time.perf_counter() @@ -752,7 +755,13 @@ def _do_run(self) -> None: self._start = time.perf_counter() self.loops += 1 - data = self.source.read() + # Send the data read from the start of the function if it is not None + if first_data is not None: + data = first_data + first_data = None + # Else read the next bit from the source + else: + data = self.source.read() if not data: self.stop()