Added a function to allow users to change the noisegate threshold

This commit is contained in:
Logan Cusano
2022-03-27 01:15:17 -04:00
parent 24adc47109
commit 22d6d5d3d7
2 changed files with 14 additions and 4 deletions

View File

@@ -4,7 +4,6 @@ import pyaudio
import discord
import numpy
THRESHOLD = 50
voice_connection = None
@@ -108,10 +107,11 @@ class AudioStream:
class NoiseGate(AudioStream):
def __init__(self, _voice_connection, **kwargs):
def __init__(self, _voice_connection, _noise_gate_threshold: int = 50, **kwargs):
super(NoiseGate, self).__init__(_init_on_startup=True, **kwargs)
global voice_connection
voice_connection = _voice_connection
self.THRESHOLD = _noise_gate_threshold
self.NGStream = NoiseGateStream(self)
def run(self) -> None:
@@ -141,10 +141,10 @@ class NoiseGateStream(discord.AudioSource):
if buffer_rms > 0:
buffer_decibel = 20 * math.log10(buffer_rms)
if self.process_set_count % 25 == 0:
if self.process_set_count % 10 == 0:
print(f"{buffer_decibel} db")
if buffer_decibel >= THRESHOLD:
if buffer_decibel >= self.stream.THRESHOLD:
self.NG_fadeout_count = self.NG_fadeout
self.process_set_count += 1

10
bot.py
View File

@@ -156,6 +156,16 @@ class Bot(commands.Bot):
else:
await ctx.send(f"{str(member).capitalize()}, I'm not in a channel")
# Add command to change the NoiseGate threshold
@self.command(help="Use this command to change the threshold of the noisegate",
brief="Change noisegate sensitivity")
async def chngth(ctx, _threshold: int, member: discord.Member = None):
member = member or ctx.author.display_name
print(f"Change of NoiseGate threshold requested by {member}")
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the threshold from "
f"{self.streamHandler.THRESHOLD} to {_threshold}")
self.streamHandler.THRESHOLD = _threshold
# Add commands for GQRX and OP25
if self.Handler in BotResources.PDB_ACCEPTABLE_HANDLERS.keys():
# Command to display the current config