Improved opus loading system

This commit is contained in:
Logan Cusano
2023-05-18 01:17:45 -04:00
parent 18d84e9e3f
commit d3553f9e9d

57
main.py
View File

@@ -1,13 +1,34 @@
import argparse import argparse, platform, os
from sys import platform
from discord import Intents, Client, Member, opus from discord import Intents, Client, Member, opus
from discord.ext import commands from discord.ext import commands
from NoiseGatev2 import NoiseGate from NoiseGatev2 import NoiseGate
# Load the proper OPUS library for the device being used
async def load_opus():
# Check the system type and load the correct library
# Linux ARM AARCH64 running 32bit OS
processor = platform.machine()
print("Processor: ", processor)
if os.name == 'nt':
if processor == "AMD64":
print(f"Loaded OPUS library for AMD64")
opus.load_opus('./opus/libopus_amd64.dll')
return "AMD64"
else:
if processor == "aarch64":
print(f"Loaded OPUS library for aarch64")
opus.load_opus('./opus/libopus_aarcch64.so')
return "aarch64"
elif processor == "armv7l":
print(f"Loaded OPUS library for armv7l")
opus.load_opus('./opus/libopus_armv7l.so')
return "armv7l"
def main(clientId='OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY', channelId=367396189529833476, NGThreshold=50, deviceId=1): def main(clientId='OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY', channelId=367396189529833476, NGThreshold=50, deviceId=1):
intents = Intents.default() intents = Intents.default()
client = Client(intents=intents) client = commands.Bot(command_prefix='!', intents=intents)
@client.event @client.event
async def on_ready(): async def on_ready():
@@ -15,24 +36,20 @@ def main(clientId='OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY',
channelIdToJoin = client.get_channel(channelId) channelIdToJoin = client.get_channel(channelId)
print("Channel", channelIdToJoin) print("Channel", channelIdToJoin)
if platform == "linux" or platform == "linux2":
# linux
opus.load_opus('./opus/libopus_aarcch64.so')
elif platform == "win32":
# Windows...
opus.load_opus('./opus/libopus_amd64.dll')
channelConnection = await channelIdToJoin.connect(timeout=60.0, reconnect=True) print("Loading opus")
print("Joined voice") await load_opus()
streamHandler = NoiseGate(
_input_device_index=deviceId, if opus.is_loaded():
_voice_connection=channelConnection, channelConnection = await channelIdToJoin.connect(timeout=60.0, reconnect=True)
_noise_gate_threshold=NGThreshold) print("Joined voice")
# Start the audio stream streamHandler = NoiseGate(
streamHandler.run() _input_device_index=deviceId,
print("stream running") _voice_connection=channelConnection,
_noise_gate_threshold=NGThreshold)
# Start the audio stream
streamHandler.run()
print("stream running")
client.run(clientId) client.run(clientId)