Skip to content

Commit 183c405

Browse files
authored
fix: missing changelog (#2900)
2 parents 0038661 + 93caac8 commit 183c405

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ These changes are available on the `master` branch, but have not yet been releas
1616

1717
### Fixed
1818

19+
- Manage silence for new SSRC with existing user_id.
20+
([#2808](https://github.com/Pycord-Development/pycord/pull/2808))
21+
1922
### Removed
2023

2124
## [2.7.0rc1] - 2025-08-30

discord/voice_client.py

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def __init__(self, client: Client, channel: abc.Connectable):
265265
self.sink = None
266266
self.starting_time = None
267267
self.stopping_time = None
268+
self.temp_queued_data: dict[int, list] = {}
268269

269270
warn_nacl = not has_nacl
270271
supported_modes: tuple[SupportedModes, ...] = (
@@ -890,7 +891,7 @@ def recv_audio(self, sink, callback, *args):
890891
# it by user, handles pcm files and
891892
# silence that should be added.
892893

893-
self.user_timestamps: dict[int, tuple[int, float]] = {}
894+
self.user_timestamps: dict[int, tuple[int, int, float]] = {}
894895
self.starting_time = time.perf_counter()
895896
self.first_packet_timestamp: float
896897
while self.recording:
@@ -918,7 +919,30 @@ def recv_audio(self, sink, callback, *args):
918919

919920
def recv_decoded_audio(self, data: RawData):
920921
# Add silence when they were not being recorded.
921-
if data.ssrc not in self.user_timestamps: # First packet from user
922+
data.user_id = self.ws.ssrc_map.get(data.ssrc, {}).get("user_id")
923+
924+
if data.user_id is None:
925+
_log.debug(
926+
f"DEBUG: received packet with SSRC {data.ssrc} not linked to a user_id."
927+
f"Queueing for later processing."
928+
)
929+
self.temp_queued_data.setdefault(data.ssrc, []).append(data)
930+
return
931+
elif data.ssrc in self.temp_queued_data:
932+
_log.debug(
933+
"DEBUG: We got %d packet(s) in queue for SSRC %d",
934+
len(self.temp_queued_data[data.ssrc]),
935+
data.ssrc,
936+
)
937+
queued_packets = self.temp_queued_data.pop(data.ssrc)
938+
for q_packet in queued_packets:
939+
q_packet.user_id = data.user_id
940+
self._process_audio_packet(q_packet)
941+
942+
self._process_audio_packet(data)
943+
944+
def _process_audio_packet(self, data: RawData):
945+
if data.user_id not in self.user_timestamps: # First packet from user
922946
if (
923947
not self.user_timestamps or not self.sync_start
924948
): # First packet from anyone
@@ -931,19 +955,33 @@ def recv_decoded_audio(self, data: RawData):
931955
) - 960
932956

933957
else: # Previously received a packet from user
934-
dRT = (
935-
data.receive_time - self.user_timestamps[data.ssrc][1]
936-
) * 48000 # delta receive time
937-
dT = data.timestamp - self.user_timestamps[data.ssrc][0] # delta timestamp
938-
diff = abs(100 - dT * 100 / dRT)
939-
if (
940-
diff > 60 and dT != 960
941-
): # If the difference in change is more than 60% threshold
942-
silence = dRT - 960
958+
prev_ssrc = self.user_timestamps[data.user_id][0]
959+
prev_timestamp = self.user_timestamps[data.user_id][1]
960+
prev_receive_time = self.user_timestamps[data.user_id][2]
961+
962+
if data.ssrc != prev_ssrc:
963+
_log.info(
964+
f"Received audio data from USER_ID {data.user_id} with a previous SSRC {prev_ssrc} and new "
965+
f"SSRC {data.ssrc}."
966+
)
967+
dRT = (data.receive_time - prev_receive_time) * 1000
968+
silence = max(0, int(dRT / (1000 / 48000))) - 960
943969
else:
944-
silence = dT - 960
970+
dRT = (
971+
data.receive_time - prev_receive_time
972+
) * 48000 # delta receive time
973+
dT = data.timestamp - prev_timestamp # delta timestamp
974+
diff = abs(100 - dT * 100 / dRT)
975+
if (
976+
diff > 60 and dT != 960
977+
): # If the difference in change is more than 60% threshold
978+
silence = dRT - 960
979+
else:
980+
silence = dT - 960
945981

946-
self.user_timestamps.update({data.ssrc: (data.timestamp, data.receive_time)})
982+
self.user_timestamps.update(
983+
{data.user_id: (data.ssrc, data.timestamp, data.receive_time)}
984+
)
947985

948986
data.decoded_data = (
949987
struct.pack("<h", 0) * max(0, int(silence)) * opus._OpusStruct.CHANNELS

0 commit comments

Comments
 (0)