From 674819baeb385b2b662a98de4be246412dd35b52 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Tue, 8 Nov 2022 10:58:41 -0800 Subject: [PATCH] Wrap transcription attempt in a try/except If the audio file is empty or has no discernable human voices, the transcription may fail with an exception. Record that when it happens and move continue to the next file, rather than failing. --- tcd.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tcd.py b/tcd.py index 7b857e1..f0d603c 100644 --- a/tcd.py +++ b/tcd.py @@ -188,11 +188,23 @@ def main(): print("NOTICE: No new entries found to transcribe.") sys.exit(0) - eprint("Transcribing: {}".format(", ".join(files_to_transcribe))) + eprint( + "Transcribing {} files: {}".format( + str(len(files_to_transcribe)), ", ".join(files_to_transcribe) + ) + ) for index, f in enumerate(files_to_transcribe): - transcribe_with_timestamp(os.path.join(tcd_path, f)) - if index != len(files): - print("\n\n") + eprint( + "Transcribing file {}: {} ({})".format( + index + 1, f, converttcdfilename(f) + ) + ) + try: + transcribe_with_timestamp(os.path.join(tcd_path, f)) + if index != len(files): + print("\n\n") + except: + eprint("Transcription failed!") writelast(files_to_transcribe[-1]) sys.exit(0)