diff --git a/MANIFEST.in b/MANIFEST.in index bb910ebb6..48577371f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include README.md include LICENSE include requirements.txt +include discord/bin/*.dll diff --git a/discord/bin/libopus-0.x64.dll b/discord/bin/libopus-0.x64.dll new file mode 100644 index 000000000..a962869fd Binary files /dev/null and b/discord/bin/libopus-0.x64.dll differ diff --git a/discord/bin/libopus-0.x86.dll b/discord/bin/libopus-0.x86.dll new file mode 100644 index 000000000..a9eec802c Binary files /dev/null and b/discord/bin/libopus-0.x86.dll differ diff --git a/discord/opus.py b/discord/opus.py index 089a735e9..a5f81486e 100644 --- a/discord/opus.py +++ b/discord/opus.py @@ -29,6 +29,8 @@ import ctypes.util import array from .errors import DiscordException import logging +import sys +import os.path log = logging.getLogger(__name__) c_int_ptr = ctypes.POINTER(ctypes.c_int) @@ -75,8 +77,14 @@ def libopus_loader(name): return lib try: - _lib = libopus_loader(ctypes.util.find_library('opus')) -except: + if sys.platform == 'win32': + _basedir = os.path.dirname(os.path.abspath(__file__)) + _bitness = 'x64' if sys.maxsize > 2**32 else 'x86' + _filename = os.path.join(_basedir, 'bin', 'libopus-0.{}.dll'.format(_bitness)) + _lib = libopus_loader(_filename) + else: + _lib = libopus_loader(ctypes.util.find_library('opus')) +except Exception as e: _lib = None def load_opus(name): diff --git a/discord/voice_client.py b/discord/voice_client.py index 4079138fc..5da25684d 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -54,10 +54,9 @@ import nacl.secret log = logging.getLogger(__name__) -from . import utils +from . import utils, opus from .gateway import * from .errors import ClientException, InvalidArgument -from .opus import Encoder as OpusEncoder class StreamPlayer(threading.Thread): def __init__(self, stream, encoder, connected, player, after, **kwargs): @@ -176,7 +175,7 @@ class VoiceClient: self.endpoint = data.get('endpoint') self.sequence = 0 self.timestamp = 0 - self.encoder = OpusEncoder(48000, 2) + self.encoder = opus.Encoder(48000, 2) log.info('created opus encoder with {0.__dict__}'.format(self.encoder)) @property @@ -496,7 +495,7 @@ class VoiceClient: if channels not in (1, 2): raise InvalidArgument('Channels must be either 1 or 2.') - self.encoder = OpusEncoder(sample_rate, channels) + self.encoder = opus.Encoder(sample_rate, channels) log.info('created opus encoder with {0.__dict__}'.format(self.encoder)) def create_stream_player(self, stream, *, after=None):