From f369e09a0c82df65ba2ac629b7e2b6b5f3bd0536 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 15 Sep 2024 01:50:45 -0400 Subject: [PATCH] Fixed bug --- src/discordAudioBot/pdab-recorder.py | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/discordAudioBot/pdab-recorder.py b/src/discordAudioBot/pdab-recorder.py index 5fc9acb..b93a1e9 100644 --- a/src/discordAudioBot/pdab-recorder.py +++ b/src/discordAudioBot/pdab-recorder.py @@ -41,7 +41,7 @@ def record_transmissions(device_id: int): stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK, input_device_index=device_id ) - + frames = [] recording = False @@ -63,16 +63,21 @@ def record_transmissions(device_id: int): frames = [] # Reset frames to start fresh for this transmission elif recording and not nonsilent_chunks: - # Transmission has ended (silence detected for the required duration) - if len(frames) > 0: - # Save recording without leading/trailing silence - trimmed_audio = sound[nonsilent_chunks[0][0]:nonsilent_chunks[-1][1]] - filename = get_filename() - save_wave_file(filename, trimmed_audio) + # Check if there were valid nonsilent chunks before trimming + if len(nonsilent_chunks) > 0: + # Transmission has ended (silence detected for the required duration) + if len(frames) > 0: + # Save recording without leading/trailing silence + trimmed_audio = sound[nonsilent_chunks[0][0]:nonsilent_chunks[-1][1]] + filename = get_filename() + save_wave_file(filename, trimmed_audio) - recording = False - frames.clear() # Clear frames to prepare for the next transmission - print("Recording stopped, waiting for the next transmission...") + recording = False + frames.clear() # Clear frames to prepare for the next transmission + print("Recording stopped, waiting for the next transmission...") + + # Optionally: adjust silence threshold if needed + # E.g., try increasing silence_thresh to detect lower sounds def parse_arguments(): @@ -84,8 +89,8 @@ def parse_arguments(): if __name__ == "__main__": try: args = parse_arguments() - logger.info("Arguments: %s", args) - record_transmissions(device=args['device_id']) + print("Arguments: %s", args) + record_transmissions(args.device_id) except KeyboardInterrupt: print("Stopping...") finally: