Added logging
This commit is contained in:
@@ -9,6 +9,8 @@ voice_connection = None
|
||||
|
||||
LOGGER = logging.getLogger("Discord_Radio_Bot.NoiseGateV2")
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class AudioStream:
|
||||
def __init__(self, _channels: int = 2, _sample_rate: int = 48000, _frames_per_buffer: int = 1024,
|
||||
_input_device_index: int = None, _output_device_index: int = None, _input: bool = True,
|
||||
@@ -27,14 +29,14 @@ class AudioStream:
|
||||
self.paInstance_kwargs['input_device_index'] = _input_device_index
|
||||
else:
|
||||
LOGGER.warning(f"[AudioStream.__init__]:\tInput was not enabled."
|
||||
f" Reinitialize with '_input=True'")
|
||||
f" Reinitialize with '_input=True'")
|
||||
|
||||
if _output_device_index:
|
||||
if _output:
|
||||
self.paInstance_kwargs['output_device_index'] = _output_device_index
|
||||
else:
|
||||
LOGGER.warning(f"[AudioStream.__init__]:\tOutput was not enabled."
|
||||
f" Reinitialize with '_output=True'")
|
||||
f" Reinitialize with '_output=True'")
|
||||
|
||||
if _init_on_startup:
|
||||
# Init PyAudio instance
|
||||
@@ -56,14 +58,14 @@ class AudioStream:
|
||||
self.paInstance_kwargs['input_device_index'] = _new_input_device_index
|
||||
else:
|
||||
LOGGER.warning(f"[AudioStream.init_stream]:\tInput was not enabled when initialized."
|
||||
f" Reinitialize with '_input=True'")
|
||||
f" Reinitialize with '_input=True'")
|
||||
|
||||
if _new_output_device_index:
|
||||
if self.paInstance_kwargs['output']:
|
||||
self.paInstance_kwargs['output_device_index'] = _new_output_device_index
|
||||
else:
|
||||
LOGGER.warning(f"[AudioStream.init_stream]:\tOutput was not enabled when initialized."
|
||||
f" Reinitialize with '_output=True'")
|
||||
f" Reinitialize with '_output=True'")
|
||||
|
||||
self.close_if_open()
|
||||
|
||||
@@ -108,6 +110,7 @@ class AudioStream:
|
||||
self.paInstance.terminate()
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class NoiseGate(AudioStream):
|
||||
def __init__(self, _voice_connection, _noise_gate_threshold: int, **kwargs):
|
||||
super(NoiseGate, self).__init__(_init_on_startup=True, **kwargs)
|
||||
@@ -119,22 +122,27 @@ class NoiseGate(AudioStream):
|
||||
def run(self) -> None:
|
||||
global voice_connection
|
||||
# Start the audio stream
|
||||
LOGGER.debug(f"Starting stream")
|
||||
self.stream.start_stream()
|
||||
LOGGER.debug(f"Playing stream to discord")
|
||||
voice_connection.play(self.NGStream)
|
||||
|
||||
async def close(self):
|
||||
LOGGER.debug(f"Closing")
|
||||
await voice_connection.disconnect()
|
||||
if self.stream.is_active:
|
||||
self.stream.stop_stream()
|
||||
LOGGER.debug(f"Stopping stream")
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class NoiseGateStream(discord.AudioSource):
|
||||
def __init__(self, _stream):
|
||||
super(NoiseGateStream, self).__init__()
|
||||
self.stream = _stream # The actual audio stream object
|
||||
self.NG_fadeout = 240/20 # Fadeout value used to hold the noisegate after de-triggering
|
||||
self.NG_fadeout_count = 0 # A count set when the noisegate is triggered and was de-triggered
|
||||
self.process_set_count = 0 # Counts how many processes have been made in order to limit the prints
|
||||
self.process_set_count = 0 # Counts how many processes have been made
|
||||
|
||||
def read(self):
|
||||
try:
|
||||
@@ -161,6 +169,7 @@ class NoiseGateStream(discord.AudioSource):
|
||||
if curr_buffer:
|
||||
if self.NG_fadeout_count == 0:
|
||||
voice_connection.stop()
|
||||
LOGGER.debug(f"Fadeout concluded, stopping voice")
|
||||
return bytes(curr_buffer)
|
||||
|
||||
except OSError as e:
|
||||
|
||||
Reference in New Issue
Block a user