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"
|
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:
|
def process(video: Path, model: Whisper, args: argparse.Namespace) -> None:
|
||||||
out_stem = output_stem(video, args.output)
|
srt = video.with_suffix(".srt")
|
||||||
srt = out_stem.with_suffix(".srt")
|
if args.output:
|
||||||
|
srt = Path(args.output)
|
||||||
|
|
||||||
if srt.exists() and not args.force:
|
if srt.exists() and not args.force:
|
||||||
print(f"skip: {srt} exists (use --force to overwrite)")
|
print(f"skip: {srt} exists (use --force to overwrite)")
|
||||||
return
|
return
|
||||||
|
|
||||||
out_stem.parent.mkdir(parents=True, exist_ok=True)
|
srt.parent.mkdir(parents=True, exist_ok=True)
|
||||||
print(f">> {video}")
|
print(f">> {video}")
|
||||||
|
|
||||||
result: stable_whisper.WhisperResult = model.transcribe( # type: ignore
|
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,
|
suppress_silence=True,
|
||||||
denoiser="demucs" if args.denoiser else None,
|
denoiser="demucs" if args.denoiser else None,
|
||||||
)
|
)
|
||||||
result.to_srt_vtt(
|
result.to_srt_vtt(str(srt), word_level=False, segment_level=True)
|
||||||
str(srt), word_level=False, segment_level=True
|
|
||||||
)
|
|
||||||
|
|
||||||
print(f"<< {srt}")
|
print(f"<< {srt}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user