Added a function to allow users to change the noisegate threshold
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user