From 1a00be825dfe32a80c66dbdb9a8c1ea7aa9c4586 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 13 Dec 2021 20:47:46 -0700 Subject: [PATCH] save when running out of lines in voice track --- .gitignore | 3 ++- projects/hollywoo/scripts/cut-voice-track.py | 27 ++++++++++++-------- projects/hollywoo/scripts/requirements.txt | 6 ++++- projects/hollywoo/scripts/util.py | 4 ++- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 62465364..6de18e06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin/ externLog.txt -*.memoized \ No newline at end of file +*.memoized +*.pyc diff --git a/projects/hollywoo/scripts/cut-voice-track.py b/projects/hollywoo/scripts/cut-voice-track.py index fd5e4f1e..be298cd8 100644 --- a/projects/hollywoo/scripts/cut-voice-track.py +++ b/projects/hollywoo/scripts/cut-voice-track.py @@ -35,6 +35,18 @@ _, data = wavfile.read(wav_filename) new_data = data[0:1] new_json = {} +def save(): + suffix = "0" + new_wav = wav_filename.replace(".wav", f"-cut{suffix}.wav") + while exists(new_wav): + new_suffix = str(int(suffix) + 1) + new_wav = new_wav.replace(f"-cut{suffix}.wav", f"-cut{new_suffix}.wav") + suffix = new_suffix + wavfile.write(new_wav, framerate, new_data) + with open(new_wav.replace(".wav", ".json"), 'w') as f: + json.dump(new_json, f) + sys.exit(0) + current_sec = 0 searching_for = None for (audio_guess, possible_sections) in timestamps.items(): @@ -74,16 +86,7 @@ for (audio_guess, possible_sections) in timestamps.items(): searching_for = phrase break elif choice == 'q': - suffix = "0" - new_wav = wav_filename.replace(".wav", f"-cut{suffix}.wav") - while exists(new_wav): - new_suffix = str(int(suffix) + 1) - new_wav = new_wav.replace(f"-cut{suffix}.wav", f"-cut{new_suffix}.wav") - suffix = new_suffix - wavfile.write(new_wav, framerate, new_data) - with open(new_wav.replace(".wav", ".json"), 'w') as f: - json.dump(new_json, f) - sys.exit(0) + save() elif choice == 'u': choice = getch() if choice != '/' and choice in takes: @@ -102,4 +105,6 @@ for (audio_guess, possible_sections) in timestamps.items(): print(f'{choice} is not a valid option') if searching_for != None: - print(f"{searching_for} not found") \ No newline at end of file + print(f"{searching_for} not found") + +save() \ No newline at end of file diff --git a/projects/hollywoo/scripts/requirements.txt b/projects/hollywoo/scripts/requirements.txt index ef1d7c03..ca6c0c68 100644 --- a/projects/hollywoo/scripts/requirements.txt +++ b/projects/hollywoo/scripts/requirements.txt @@ -1,3 +1,7 @@ requests vosk -scipy \ No newline at end of file +numpy +scipy +simpleaudio +wheel +getch \ No newline at end of file diff --git a/projects/hollywoo/scripts/util.py b/projects/hollywoo/scripts/util.py index 59b7c4e1..90565e3b 100644 --- a/projects/hollywoo/scripts/util.py +++ b/projects/hollywoo/scripts/util.py @@ -1,9 +1,11 @@ import sys -def arg(num, usage): +def arg(num, usage, default=None): val = '' if len(sys.argv) > num: val = sys.argv[num] else: + if default != None: + return default raise ValueError(usage) return val \ No newline at end of file