fix(cli): simplify determining output file
This commit is contained in:
+5
-13
@@ -25,22 +25,16 @@ DEFAULT_MODEL = os.environ.get("WHISPER_MODEL", "large-v3")
|
||||
DEFAULT_DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
|
||||
|
||||
def output_stem(video: Path, override: str | None) -> Path:
|
||||
if override:
|
||||
path = Path(override)
|
||||
return path.with_suffix("") if path.suffix == ".srt" else path
|
||||
return video.with_suffix("")
|
||||
|
||||
|
||||
def process(video: Path, model: Whisper, args: argparse.Namespace) -> None:
|
||||
out_stem = output_stem(video, args.output)
|
||||
srt = out_stem.with_suffix(".srt")
|
||||
srt = video.with_suffix(".srt")
|
||||
if args.output:
|
||||
srt = Path(args.output)
|
||||
|
||||
if srt.exists() and not args.force:
|
||||
print(f"skip: {srt} exists (use --force to overwrite)")
|
||||
return
|
||||
|
||||
out_stem.parent.mkdir(parents=True, exist_ok=True)
|
||||
srt.parent.mkdir(parents=True, exist_ok=True)
|
||||
print(f">> {video}")
|
||||
|
||||
result: stable_whisper.WhisperResult = model.transcribe( # type: ignore
|
||||
@@ -50,9 +44,7 @@ def process(video: Path, model: Whisper, args: argparse.Namespace) -> None:
|
||||
suppress_silence=True,
|
||||
denoiser="demucs" if args.denoiser else None,
|
||||
)
|
||||
result.to_srt_vtt(
|
||||
str(srt), word_level=False, segment_level=True
|
||||
)
|
||||
result.to_srt_vtt(str(srt), word_level=False, segment_level=True)
|
||||
|
||||
print(f"<< {srt}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user