From b9a173331d60225ad45fe348e65046621b6e6e33 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Thu, 13 Oct 2022 13:44:20 -0700 Subject: [PATCH] Enabled eprint() throughout code. Enabled both CUDA and CPU modes. --- tcd.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tcd.py b/tcd.py index 7134e73..7b857e1 100644 --- a/tcd.py +++ b/tcd.py @@ -13,6 +13,17 @@ tcd_record = re.compile("R(\d{8}-\d{6}).WAV$", re.IGNORECASE) CACHE_PATH = os.path.join(os.path.expanduser("~"), ".cache", "tcd") CACHE_FILE = os.path.join(CACHE_PATH, "lastfile") +# https://stackoverflow.com/questions/5574702/how-do-i-print-to-stderr-in-python +def maybe_eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + + +def maybe_not_eprint(*args, **kwargs): + pass + + +eprint = maybe_not_eprint + def converttcdfilename(filename): g = tcd_record.search(filename) @@ -28,7 +39,11 @@ def converttcdfilename(filename): def transcribe(filename: str): - model = whisper.load_model("small") # .cuda() + model = whisper.load_model("small") + try: + model = whisper.load_model("small").cuda() + except: + eprint("Initializing CUDA failed. Falling back to CPU mode.") result = model.transcribe(filename, language="en", temperature=0.0) assert result["language"] == "en" return result["text"].strip() @@ -58,19 +73,8 @@ def writelast(filename: str): lf.write("\n") -# https://stackoverflow.com/questions/5574702/how-do-i-print-to-stderr-in-python -def maybe_eprint(*args, **kwargs): - print(*args, file=sys.stderr, **kwargs) - - -def maybe_not_eprint(*args, **kwargs): - pass - - -eprint = maybe_not_eprint - - def main(): + global eprint parser = argparse.ArgumentParser( description="Process Elf's Thought Capture Device" )