aboutsummaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/producer/cli.py54
-rw-r--r--lib/src/producer/engines/denoise_dfn.py19
2 files changed, 67 insertions, 6 deletions
diff --git a/lib/src/producer/cli.py b/lib/src/producer/cli.py
index 745b797..476adf3 100644
--- a/lib/src/producer/cli.py
+++ b/lib/src/producer/cli.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import argparse
+import itertools
import sys
from pathlib import Path
@@ -128,13 +129,54 @@ def _resolve_output(inp: Path, opts: Options, single: bool) -> Path:
if single:
return o if o.suffix else o.with_suffix("." + ext)
o.mkdir(parents=True, exist_ok=True)
- return o / f"{inp.stem}_master.{ext}"
- return inp.with_name(f"{inp.stem}_master.{ext}")
-
-
-def process_one(inp: Path, opts: Options, single: bool, quiet: bool = False) -> Path:
- x, sr = pio.decode(inp)
+ return o / f"{inp.stem}_processed.{ext}"
+ return inp.with_name(f"{inp.stem}_processed.{ext}")
+
+
+def _next_free(path: Path) -> Path:
+ for i in itertools.count(1):
+ cand = path.with_name(f"{path.stem}_{i}{path.suffix}")
+ if not cand.exists():
+ return cand
+
+
+def _resolve_output_conflict(out_path: Path, interactive: bool) -> Path | None:
+ """Returns the path to write, or None when the user cancels."""
+ if not out_path.exists():
+ return out_path
+ alt = _next_free(out_path)
+ if not interactive:
+ print(f"[producer] {out_path} exists, writing {alt.name} instead")
+ return alt
+ while True:
+ try:
+ ans = (
+ input(
+ f"[producer] {out_path} exists "
+ f"([o]verwrite / [r]ename to {alt.name} / [c]ancel): "
+ )
+ .strip()
+ .lower()
+ )
+ except EOFError:
+ print()
+ return None
+ if ans in ("o", "overwrite"):
+ return out_path
+ if ans in ("r", "rename"):
+ return alt
+ if ans in ("c", "cancel"):
+ return None
+ print("[producer] please answer o, r, or c")
+
+
+def process_one(inp: Path, opts: Options, single: bool, quiet: bool = False) -> Path | None:
out_path = _resolve_output(inp, opts, single)
+ out_path = _resolve_output_conflict(out_path, sys.stdin.isatty())
+ if out_path is None:
+ print(f"[producer] skipped {inp}")
+ return None
+ x, sr = pio.decode(inp)
target_sr = opts.out_sample_rate()
if not quiet:
print(f"[producer] {inp} ({sr} Hz, {len(x) / sr:.1f}s)")
diff --git a/lib/src/producer/engines/denoise_dfn.py b/lib/src/producer/engines/denoise_dfn.py
index 66a8cf6..6b7d1d5 100644
--- a/lib/src/producer/engines/denoise_dfn.py
+++ b/lib/src/producer/engines/denoise_dfn.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import sys
import types
import urllib.request
+import warnings
import zipfile
from pathlib import Path
@@ -21,6 +22,12 @@ BASE_URL = f"https://raw.githubusercontent.com/Rikorose/DeepFilterNet/{TAG}"
def _shim_torchaudio_backend() -> None:
+ warnings.filterwarnings(
+ "ignore",
+ message=r".*AudioMetaData.*has been moved.*",
+ category=UserWarning,
+ module=r"df[./]io",
+ )
try:
import torchaudio.backend # noqa: F401
except Exception:
@@ -32,6 +39,17 @@ def _shim_torchaudio_backend() -> None:
pkg.backend = stub
+def _shim_df_git() -> None:
+ import df.io
+ import df.logger
+ import df.utils
+
+ for mod in (df.utils, df.logger, df.io):
+ for name in ("get_git_root", "get_commit_hash", "get_branch_name"):
+ if hasattr(mod, name):
+ setattr(mod, name, lambda: None)
+
+
def ensure_model(model: str) -> Path:
target = MODELS_DIR / model
if (target / "config.ini").is_file():
@@ -61,6 +79,7 @@ def denoise(
lazy.ensure(["deepfilternet==0.5.6"], purpose="DeepFilterNet")
lazy.ensure_torch()
_shim_torchaudio_backend()
+ _shim_df_git()
model_name = "DeepFilterNet3"
try:
model_dir = ensure_model(model_name)