Add OpusNotLoaded exception and opus.is_loaded utility function.
This commit is contained in:
parent
9e36047ffb
commit
72f355bb64
@ -1879,6 +1879,8 @@ class Client:
|
|||||||
Could not connect to the voice channel in time.
|
Could not connect to the voice channel in time.
|
||||||
ClientException
|
ClientException
|
||||||
You are already connected to a voice channel.
|
You are already connected to a voice channel.
|
||||||
|
OpusNotLoaded
|
||||||
|
The opus library has not been loaded.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
|
@ -111,13 +111,37 @@ def load_opus(name):
|
|||||||
global _lib
|
global _lib
|
||||||
_lib = libopus_loader(name)
|
_lib = libopus_loader(name)
|
||||||
|
|
||||||
|
def is_loaded():
|
||||||
|
"""Function to check if opus lib is successfully loaded either
|
||||||
|
via the ``ctypes.util.find_library`` call of :func:`load_opus`.
|
||||||
|
|
||||||
|
This must return ``True`` for voice to work.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
Indicates if the opus library has been loaded.
|
||||||
|
"""
|
||||||
|
global _lib
|
||||||
|
return _lib is not None
|
||||||
|
|
||||||
class OpusError(DiscordException):
|
class OpusError(DiscordException):
|
||||||
"""An exception that is thrown for libopus related errors."""
|
"""An exception that is thrown for libopus related errors.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
code : int
|
||||||
|
The error code returned.
|
||||||
|
"""
|
||||||
def __init__(self, code):
|
def __init__(self, code):
|
||||||
self.code = code
|
self.code = code
|
||||||
msg = _lib.opus_strerror(self.code).decode('utf-8')
|
msg = _lib.opus_strerror(self.code).decode('utf-8')
|
||||||
log.info('"{}" has happened'.format(msg))
|
log.info('"{}" has happened'.format(msg))
|
||||||
super(DiscordException, self).__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
class OpusNotLoaded(DiscordException):
|
||||||
|
"""An exception that is thrown for when libopus is not loaded."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Some constants...
|
# Some constants...
|
||||||
@ -137,6 +161,9 @@ class Encoder:
|
|||||||
self.samples_per_frame = int(self.sampling_rate / 1000 * self.frame_length)
|
self.samples_per_frame = int(self.sampling_rate / 1000 * self.frame_length)
|
||||||
self.frame_size = self.samples_per_frame * self.sample_size
|
self.frame_size = self.samples_per_frame * self.sample_size
|
||||||
|
|
||||||
|
if not is_loaded():
|
||||||
|
raise OpusNotLoaded()
|
||||||
|
|
||||||
self._state = self._create_state()
|
self._state = self._create_state()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
@ -33,6 +33,8 @@ Opus Library
|
|||||||
|
|
||||||
.. autofunction:: opus.load_opus
|
.. autofunction:: opus.load_opus
|
||||||
|
|
||||||
|
.. autofunction:: opus.is_loaded
|
||||||
|
|
||||||
.. _discord-api-events:
|
.. _discord-api-events:
|
||||||
|
|
||||||
Event Reference
|
Event Reference
|
||||||
@ -457,4 +459,6 @@ The following exceptions are thrown by the library.
|
|||||||
|
|
||||||
.. autoexception:: GatewayNotFound
|
.. autoexception:: GatewayNotFound
|
||||||
|
|
||||||
.. autoexception:: OpusError
|
.. autoexception:: opus.OpusError
|
||||||
|
|
||||||
|
.. autoexception:: opus.OpusNotLoaded
|
||||||
|
Loading…
x
Reference in New Issue
Block a user