Skip to content

Commit 2fc4963

Browse files
committed
Add libopus DLLs for ease of use.
1 parent 7efabce commit 2fc4963

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include README.md
22
include LICENSE
33
include requirements.txt
4+
include discord/bin/*.dll

discord/bin/libopus-0.x64.dll

256 KB
Binary file not shown.

discord/bin/libopus-0.x86.dll

266 KB
Binary file not shown.

discord/opus.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import array
3030
from .errors import DiscordException
3131
import logging
32+
import sys
33+
import os.path
3234

3335
log = logging.getLogger(__name__)
3436
c_int_ptr = ctypes.POINTER(ctypes.c_int)
@@ -75,8 +77,14 @@ def libopus_loader(name):
7577
return lib
7678

7779
try:
78-
_lib = libopus_loader(ctypes.util.find_library('opus'))
79-
except:
80+
if sys.platform == 'win32':
81+
_basedir = os.path.dirname(os.path.abspath(__file__))
82+
_bitness = 'x64' if sys.maxsize > 2**32 else 'x86'
83+
_filename = os.path.join(_basedir, 'bin', 'libopus-0.{}.dll'.format(_bitness))
84+
_lib = libopus_loader(_filename)
85+
else:
86+
_lib = libopus_loader(ctypes.util.find_library('opus'))
87+
except Exception as e:
8088
_lib = None
8189

8290
def load_opus(name):

discord/voice_client.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@
5454

5555
log = logging.getLogger(__name__)
5656

57-
from . import utils
57+
from . import utils, opus
5858
from .gateway import *
5959
from .errors import ClientException, InvalidArgument
60-
from .opus import Encoder as OpusEncoder
6160

6261
class StreamPlayer(threading.Thread):
6362
def __init__(self, stream, encoder, connected, player, after, **kwargs):
@@ -176,7 +175,7 @@ def __init__(self, user, main_ws, session_id, channel, data, loop):
176175
self.endpoint = data.get('endpoint')
177176
self.sequence = 0
178177
self.timestamp = 0
179-
self.encoder = OpusEncoder(48000, 2)
178+
self.encoder = opus.Encoder(48000, 2)
180179
log.info('created opus encoder with {0.__dict__}'.format(self.encoder))
181180

182181
@property
@@ -496,7 +495,7 @@ def encoder_options(self, *, sample_rate, channels=2):
496495
if channels not in (1, 2):
497496
raise InvalidArgument('Channels must be either 1 or 2.')
498497

499-
self.encoder = OpusEncoder(sample_rate, channels)
498+
self.encoder = opus.Encoder(sample_rate, channels)
500499
log.info('created opus encoder with {0.__dict__}'.format(self.encoder))
501500

502501
def create_stream_player(self, stream, *, after=None):

0 commit comments

Comments
 (0)