Skip to content

Commit

Permalink
added is_speaking function
Browse files Browse the repository at this point in the history
  • Loading branch information
Delyanskiiii committed Oct 18, 2023
1 parent 0f2685c commit d8e65ac
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,46 @@ def unpack_audio(self, data):

self.decoder.decode(data)

def is_speaking(self) -> bool:
"""Returns a :class:`bool` indicating whether any user is currently speaking in the current voice channel the bot is in.
Returns True if a user is speaking, False if package has arived but the frame is silent and None if there is no package.
Must be in a voice channel to use.
.. versionadded:: not yet
Raises
------
RecordingException
Not connected to a voice channel.
"""
if not self.is_connected():
raise RecordingException("Not connected to voice channel.")

self.empty_socket()

ready, _, err = select.select([self.socket], [], [self.socket], 0.01)
if not ready and err:
print(f"Socket error: {err}")

try:
data = self.socket.recv(4096)
except OSError:
return

if 200 <= data[1] <= 204:
# RTCP received.
# RTCP provides information about the connection
# as opposed to actual audio data, so it's not
# important at the moment.
return

data = RawData(data, self)

if data.decrypted_data == b"\xf8\xff\xfe": # Frame of silence
return False

return True

def start_recording(self, sink, callback, *args, sync_start: bool = False):
"""The bot will begin recording audio from the current voice channel it is in.
This function uses a thread so the current code line will not be stopped.
Expand Down

0 comments on commit d8e65ac

Please sign in to comment.