From bb4de89d5ca612bb9e8e84dc16f00df1519e59d4 Mon Sep 17 00:00:00 2001 From: blord0 Date: Mon, 28 Jul 2025 19:20:31 +0100 Subject: [PATCH] Calculate correct number of points per sample --- discord/file.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/discord/file.py b/discord/file.py index 414eb876c..206f9d780 100644 --- a/discord/file.py +++ b/discord/file.py @@ -225,6 +225,8 @@ class File: return payload def generate_waveform(self) -> str: + if not self.voice: + raise TypeError("Cannot produce waveform for non voice file") self.reset() ogg = OggStream(self.fp) # type: ignore decoder = Decoder() @@ -254,9 +256,9 @@ class File: if waveform[i] < 0: waveform[i] = -waveform[i] - # TODO: Figure out how discord sets the sample count - # Voice message I've been using has 40 samples, so using that for now - points_per_sample = len(waveform) // 40 + point_count: int = self.duration * 10 # type: ignore + point_count = min(point_count, 255) + points_per_sample: int = len(waveform) // point_count sample_waveform: list[int] = [] total, count = 0, 0 @@ -274,4 +276,5 @@ class File: for i in range(len(sample_waveform)): sample_waveform[i] = int(sample_waveform[i] * mult) + print(len(sample_waveform)) return base64.b64encode(bytes(sample_waveform)).decode('utf-8')