mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Re-implement voice sending.
This is a complete redesign of the old voice code. A list of major changes is as follows: * The voice websocket will now automatically reconnect with exponential back-off just like the regular Client does. * Removal of the stream player concept. * Audio now gracefully pauses and resumes when a disconnect is found. * Introduce a discord.AudioSource concept to abstract streams * Flatten previous stream player functionality with the VoiceClient, e.g. player.stop() is now voice_client.stop() * With the above re-coupling this means you no longer have to store players anywhere. * The after function now requires a single parameter, the error, if any existed. This will typically be None. A lot of this design is experimental.
This commit is contained in:
@ -183,15 +183,16 @@ signal_ctl = {
|
||||
}
|
||||
|
||||
class Encoder:
|
||||
def __init__(self, sampling, channels, application=APPLICATION_AUDIO):
|
||||
self.sampling_rate = sampling
|
||||
self.channels = channels
|
||||
self.application = application
|
||||
SAMPLING_RATE = 48000
|
||||
CHANNELS = 2
|
||||
FRAME_LENGTH = 20
|
||||
SAMPLE_SIZE = 4 # (bit_rate / 8) * CHANNELS (bit_rate == 16)
|
||||
SAMPLES_PER_FRAME = int(SAMPLING_RATE / 1000 * FRAME_LENGTH)
|
||||
|
||||
self.frame_length = 20
|
||||
self.sample_size = 2 * self.channels # (bit_rate / 8) but bit_rate == 16
|
||||
self.samples_per_frame = int(self.sampling_rate / 1000 * self.frame_length)
|
||||
self.frame_size = self.samples_per_frame * self.sample_size
|
||||
FRAME_SIZE = SAMPLES_PER_FRAME * SAMPLE_SIZE
|
||||
|
||||
def __init__(self, application=APPLICATION_AUDIO):
|
||||
self.application = application
|
||||
|
||||
if not is_loaded():
|
||||
raise OpusNotLoaded()
|
||||
@ -210,7 +211,7 @@ class Encoder:
|
||||
|
||||
def _create_state(self):
|
||||
ret = ctypes.c_int()
|
||||
result = _lib.opus_encoder_create(self.sampling_rate, self.channels, self.application, ctypes.byref(ret))
|
||||
result = _lib.opus_encoder_create(self.SAMPLING_RATE, self.CHANNELS, self.application, ctypes.byref(ret))
|
||||
|
||||
if ret.value != 0:
|
||||
log.info('error has happened in state creation')
|
||||
|
Reference in New Issue
Block a user