diff --git a/NoiseGatev2.py b/NoiseGatev2.py index 9655a6a..9a35957 100644 --- a/NoiseGatev2.py +++ b/NoiseGatev2.py @@ -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 diff --git a/bot.py b/bot.py index 1f080eb..dd74724 100644 --- a/bot.py +++ b/bot.py @@ -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