diff --git a/discord/opus.py b/discord/opus.py index 63362b929a..3733b9d0ca 100644 --- a/discord/opus.py +++ b/discord/opus.py @@ -506,8 +506,8 @@ def decode(self, data, *, fec=False): frame_size = frames * samples_per_frame pcm = ( - ctypes.c_int16 - * (frame_size * channel_count * ctypes.sizeof(ctypes.c_int16)) + ctypes.c_int16 + * (frame_size * channel_count * ctypes.sizeof(ctypes.c_int16)) )() pcm_ptr = ctypes.cast(pcm, c_int16_ptr) @@ -556,11 +556,22 @@ def run(self): self.client.recv_decoded_audio(data) def stop(self): + start_time = time.time() # Capture the start time of the loop + timeout_duration = 5 # Timeout duration in seconds + while self.decoding: + elapsed_time = time.time() - start_time + if elapsed_time > timeout_duration: + _log.error( + f"Timeout exceeded while waiting for the decoder to stop. " + f"Discarding the {len(self.decode_queue)} remaining in the queue. Decoder Process Killed") + break + time.sleep(0.1) self.decoder = {} gc.collect() - print("Decoder Process Killed") + + print("Decoder Process Killed") self._end_thread.set() def get_decoder(self, ssrc): diff --git a/discord/voice_client.py b/discord/voice_client.py index 7d5161501d..1e9e336197 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -812,9 +812,9 @@ def stop_recording(self): """ if not self.recording: raise RecordingException("Not currently recording audio.") - self.decoder.stop() self.recording = False self.paused = False + self.decoder.stop() def toggle_pause(self): """Pauses or unpauses the recording.