Enabled eprint() throughout code.

Enabled both CUDA and CPU modes.
This commit is contained in:
Elf M. Sternberg 2022-10-13 13:44:20 -07:00
parent cf52b3e293
commit b9a173331d
1 changed files with 17 additions and 13 deletions

30
tcd.py
View File

@ -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_PATH = os.path.join(os.path.expanduser("~"), ".cache", "tcd")
CACHE_FILE = os.path.join(CACHE_PATH, "lastfile") 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): def converttcdfilename(filename):
g = tcd_record.search(filename) g = tcd_record.search(filename)
@ -28,7 +39,11 @@ def converttcdfilename(filename):
def transcribe(filename: str): 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) result = model.transcribe(filename, language="en", temperature=0.0)
assert result["language"] == "en" assert result["language"] == "en"
return result["text"].strip() return result["text"].strip()
@ -58,19 +73,8 @@ def writelast(filename: str):
lf.write("\n") 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(): def main():
global eprint
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Process Elf's Thought Capture Device" description="Process Elf's Thought Capture Device"
) )