Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make boolean flags store_true #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions auto_subtitle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
import warnings
import tempfile
from .utils import filename, str2bool, write_srt
from .utils import filename, write_srt


def main():
Expand All @@ -16,12 +16,12 @@ def main():
choices=whisper.available_models(), help="name of the Whisper model to use")
parser.add_argument("--output_dir", "-o", type=str,
default=".", help="directory to save the outputs")
parser.add_argument("--output_srt", type=str2bool, default=False,
help="whether to output the .srt file along with the video files")
parser.add_argument("--srt_only", type=str2bool, default=False,
parser.add_argument("--output_srt", action="store_true",
help="output the .srt file along with the video files")
parser.add_argument("--srt_only", action="store_true",
help="only generate the .srt file and not create overlayed video")
parser.add_argument("--verbose", type=str2bool, default=False,
help="whether to print out the progress and debug messages")
parser.add_argument("--verbose", action="store_true",
help="print out the progress and debug messages")

parser.add_argument("--task", type=str, default="transcribe", choices=[
"transcribe", "translate"], help="whether to perform X->X speech recognition ('transcribe') or X->English translation ('translate')")
Expand Down Expand Up @@ -87,7 +87,7 @@ def get_subtitles(audio_paths: list, output_srt: bool, output_dir: str, transcri
for path, audio_path in audio_paths.items():
srt_path = output_dir if output_srt else tempfile.gettempdir()
srt_path = os.path.join(srt_path, f"{filename(path)}.srt")

print(
f"Generating subtitles for {filename(path)}... This might take a while."
)
Expand Down
11 changes: 0 additions & 11 deletions auto_subtitle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
from typing import Iterator, TextIO


def str2bool(string):
string = string.lower()
str2val = {"true": True, "false": False}

if string in str2val:
return str2val[string]
else:
raise ValueError(
f"Expected one of {set(str2val.keys())}, got {string}")


def format_timestamp(seconds: float, always_include_hours: bool = False):
assert seconds >= 0, "non-negative timestamp expected"
milliseconds = round(seconds * 1000.0)
Expand Down