voice-changer: always stream at 48kHz, redo interrupted example extraction

- Applio's realtime engine treats incoming audio as 48kHz; opening a 44.1kHz
  device at its default rate skewed pitch and timing. Streams now always open
  at 48kHz (MME/DirectSound resample, WASAPI auto_convert), with a clear error
  if a device refuses it.
- KSS/Zeroth example datasets write a completion marker (with minutes) last;
  a partial folder from an interrupted run is wiped and re-extracted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-11 14:41:06 +09:00
parent b0460fdff7
commit ab599c0751
3 changed files with 90 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ Zeroth 원본은 16kHz 라 KSS(44.1kHz)보다 고음이 덜 또렷하다. 그래
"""
import argparse
import io
import shutil
import sys
import tarfile
import urllib.request
@@ -46,11 +47,14 @@ def prepare_kss(minutes: float) -> Path:
import soundfile as sf
out = DATASETS / "example_kss" / "raw"
if out.is_dir() and any(out.iterdir()):
marker = out.parent / "done.txt" # 끝까지 뽑았을 때만 쓴다. 중간에 끊긴 폴더는 다시 뽑는다
if marker.is_file() and float(marker.read_text(encoding="utf-8").split()[0]) >= minutes:
return out
print("KSS 받기 (약 540MB)...")
pq_path = _download(KSS_URL, DATASETS / "_downloads" / "kss-00000.parquet")
out.mkdir(parents=True, exist_ok=True)
if out.exists():
shutil.rmtree(out)
out.mkdir(parents=True)
total = 0.0
n = 0
pf = pq.ParquetFile(pq_path)
@@ -61,8 +65,10 @@ def prepare_kss(minutes: float) -> Path:
sf.write(out / f"kss_{n:05d}.wav", data, sr)
total += len(data) / sr
if total >= minutes * 60:
print(f" KSS {total / 60:.1f}분 준비")
return out
break
if total >= minutes * 60:
break
marker.write_text(f"{total / 60!r} {n}", encoding="utf-8")
print(f" KSS {total / 60:.1f}분 준비")
return out
@@ -75,8 +81,8 @@ def prepare_zeroth(want: dict[str, int], minutes: float) -> list[tuple[str, str,
for d in sorted((DATASETS).glob("example_zeroth_*")):
meta = d / "speaker.txt"
if meta.is_file():
spk, sex = meta.read_text(encoding="utf-8").split()
if want.get(sex, 0) > 0:
spk, sex, *got = meta.read_text(encoding="utf-8").split()
if want.get(sex, 0) > 0 and float(got[0] if got else 0) >= minutes:
want[sex] -= 1
done.append((spk, sex, d / "raw"))
if not any(v > 0 for v in want.values()):
@@ -112,10 +118,13 @@ def prepare_zeroth(want: dict[str, int], minutes: float) -> list[tuple[str, str,
print(f"\r 읽은 녹음 {read / 1e6:,.0f}MB, 화자 {len(files)}명", end="", flush=True)
if secs[spk] >= minutes * 60:
d = DATASETS / f"example_zeroth_{spk}"
(d / "raw").mkdir(parents=True, exist_ok=True)
(d / "speaker.txt").unlink(missing_ok=True)
if (d / "raw").exists():
shutil.rmtree(d / "raw")
(d / "raw").mkdir(parents=True)
for fname, b in files.pop(spk):
(d / "raw" / fname).write_bytes(b)
(d / "speaker.txt").write_text(f"{spk} {sex}", encoding="utf-8")
(d / "speaker.txt").write_text(f"{spk} {sex} {secs[spk] / 60!r}", encoding="utf-8") # 다 쓴 뒤 마지막에
want[sex] -= 1
done.append((spk, sex, d / "raw"))
print(f"\n 화자 {spk}({'남' if sex == 'm' else '여'}) {secs[spk] / 60:.1f}분 준비")