mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 17:36:15 +00:00
Update voice code to vws V4
- Update internals to be compatible with v4 - Adds multiple encryption mode support. Previously only `xsalsa20_poly1305` was supported. Now `xsalsa20_poly1305_suffix` is also supported. Note: There is no (nice) way to manually select a mode. The user needn't worry about this however. - Fixed speaking state bug. When you disconnected from a voice channel while a bot was playing, upon reconnect you would be unable to hear the bot. This was caused by bots not sending their speaking state while transmitting. Bots will now set their speaking state properly when transmitting. Note: This does not account for sending actual silence, the speaking indicator will still be active.
This commit is contained in:
@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
import threading
|
||||
import subprocess
|
||||
import audioop
|
||||
import asyncio
|
||||
import logging
|
||||
import shlex
|
||||
import time
|
||||
@ -261,6 +262,7 @@ class AudioPlayer(threading.Thread):
|
||||
|
||||
# getattr lookup speed ups
|
||||
play_audio = self.client.send_audio_packet
|
||||
self._speak(True)
|
||||
|
||||
while not self._end.is_set():
|
||||
# are we paused?
|
||||
@ -309,14 +311,19 @@ class AudioPlayer(threading.Thread):
|
||||
def stop(self):
|
||||
self._end.set()
|
||||
self._resumed.set()
|
||||
self._speak(False)
|
||||
|
||||
def pause(self):
|
||||
def pause(self, *, update_speaking=True):
|
||||
self._resumed.clear()
|
||||
if update_speaking:
|
||||
self._speak(False)
|
||||
|
||||
def resume(self):
|
||||
def resume(self, *, update_speaking=True):
|
||||
self.loops = 0
|
||||
self._start = time.time()
|
||||
self._resumed.set()
|
||||
if update_speaking:
|
||||
self._speak(True)
|
||||
|
||||
def is_playing(self):
|
||||
return self._resumed.is_set() and not self._end.is_set()
|
||||
@ -326,6 +333,12 @@ class AudioPlayer(threading.Thread):
|
||||
|
||||
def _set_source(self, source):
|
||||
with self._lock:
|
||||
self.pause()
|
||||
self.pause(update_speaking=False)
|
||||
self.source = source
|
||||
self.resume()
|
||||
self.resume(update_speaking=False)
|
||||
|
||||
def _speak(self, speaking):
|
||||
try:
|
||||
asyncio.run_coroutine_threadsafe(self.client.ws.speak(speaking), self.client.loop)
|
||||
except Exception as e:
|
||||
log.info("Speaking call in player failed: %s", e)
|
||||
|
Reference in New Issue
Block a user