Add libopus DLLs for ease of use.

This commit is contained in:
Rapptz 2016-05-06 12:22:03 -04:00
parent 7efabce4b2
commit 2fc496304c
5 changed files with 14 additions and 6 deletions

View File

@ -1,3 +1,4 @@
include README.md
include LICENSE
include requirements.txt
include discord/bin/*.dll

Binary file not shown.

Binary file not shown.

View File

@ -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):

View File

@ -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):