Fixed bug

This commit is contained in:
2024-09-15 01:50:45 -04:00
parent 2fbca72f63
commit f369e09a0c

View File

@@ -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: