Skip to content

Commit

Permalink
Removed part that adds silence to beginning of audio
Browse files Browse the repository at this point in the history
- Added an informative comment to my last change too
  • Loading branch information
baribarton committed May 28, 2024
1 parent fbdf6a6 commit aa8c524
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ async def poll_voice_ws(self, reconnect: bool) -> None:
"Disconnected from voice by force... potentially"
" reconnecting."
)
# I removed this part because discord suggests not reconnecting on a 4014 code
# successful = await self.potential_reconnect()
# if successful:
# continue
Expand Down Expand Up @@ -872,37 +873,37 @@ def recv_audio(self, sink, callback, *args):

def recv_decoded_audio(self, data: RawData):
# Add silence when they were not being recorded.
if data.ssrc not in self.user_timestamps: # First packet from user
if (
not self.user_timestamps or not self.sync_start
): # First packet from anyone
self.first_packet_timestamp = data.receive_time
silence = 0

else: # Previously received a packet from someone else
silence = (
(data.receive_time - self.first_packet_timestamp) * 48000
) - 960

else: # Previously received a packet from user
dRT = (
data.receive_time - self.user_timestamps[data.ssrc][1]
) * 48000 # delta receive time
dT = data.timestamp - self.user_timestamps[data.ssrc][0] # delta timestamp
diff = abs(100 - dT * 100 / dRT)
if (
diff > 60 and dT != 960
): # If the difference in change is more than 60% threshold
silence = dRT - 960
else:
silence = dT - 960
# if data.ssrc not in self.user_timestamps: # First packet from user
# if (
# not self.user_timestamps or not self.sync_start
# ): # First packet from anyone
# self.first_packet_timestamp = data.receive_time
# silence = 0
#
# else: # Previously received a packet from someone else
# silence = (
# (data.receive_time - self.first_packet_timestamp) * 48000
# ) - 960
#
# else: # Previously received a packet from user
# dRT = (
# data.receive_time - self.user_timestamps[data.ssrc][1]
# ) * 48000 # delta receive time
# dT = data.timestamp - self.user_timestamps[data.ssrc][0] # delta timestamp
# diff = abs(100 - dT * 100 / dRT)
# if (
# diff > 60 and dT != 960
# ): # If the difference in change is more than 60% threshold
# silence = dRT - 960
# else:
# silence = dT - 960

self.user_timestamps.update({data.ssrc: (data.timestamp, data.receive_time)})

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

while data.ssrc not in self.ws.ssrc_map:
time.sleep(0.05)
Expand Down

0 comments on commit aa8c524

Please sign in to comment.