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