49 lines
1.3 KiB
Python

import argparse
import os
from dnd_transcribe.inference import DEFAULT_MODEL
def build_argument_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Utility to transcribe DND audio recordings."
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="Enable verbose logging"
)
parser.add_argument(
"-q", "--quiet", action="store_true", help="Only display errors"
)
parser.add_argument(
"--no-gpu",
dest="use_gpu",
action="store_false",
help="Disable using the GPU with CUDA",
)
parser.add_argument(
"-m",
"--model",
type=str,
help="ASR model",
default=DEFAULT_MODEL,
)
parser.add_argument(
"-f",
"--audio-file",
type=argparse.FileType(mode="rb"),
help="Audio file to process, for long audo see --stream-audio-file",
)
parser.add_argument(
"-s",
"--stream-audio-file",
type=valid_file_path,
help="Audio file to process by streaming",
)
return parser
def valid_file_path(path: str) -> str:
path = os.path.realpath(path)
if os.path.isfile(path):
return path
raise argparse.ArgumentTypeError("{} is not a valid file".format(path))