Files
voice_copy/voice-changer/app/common.py
EJClaw 21b4278b77 voice-changer: one-click installer, mic APO instead of virtual cable, keep all files in install folder
- apo/: VoiceChangerAPO.dll (SFX APO on the real mic, built with mingw). When the app converts,
  the mic's own stream carries the converted voice; otherwise it passes the real voice through.
  Shared-memory protocol in vccore.h, Python side app/mic_bridge.py
- scripts/mic-apo.ps1: register/unregister on every capture endpoint with admin value rights only
  (no ACL changes unless FxProperties is missing), originals backed up and restored
- app: mic is the conversion target (WASAPI names), no output device, '마이크 다시 연결' button,
  44.1k<->48k streaming resample, caches/temp redirected into <install>/cache
- installer/VoiceChanger.iss (Inno Setup): choose install folder, register APO, download engine
  into that folder, uninstall restores mic settings and asks before deleting models
- install.ps1: uv python --no-bin --no-registry, temp/caches inside the folder, uv cache clean
- tests: C core compiled with gcc against the Python bridge; converter pump 44.1k round trip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:33:15 +09:00

81 lines
3.1 KiB
Python

"""경로와 Applio 엔진 불러오기. 다른 모듈은 이것부터 import 한다."""
import json
import os
import re
import sys
from pathlib import Path
ROOT = Path(os.environ.get("VC_ROOT") or Path(__file__).resolve().parent.parent)
ENGINE = Path(os.environ.get("VC_ENGINE") or ROOT / "engine")
MODELS = ROOT / "models"
TRAINING = ROOT / "training"
DATASETS = ROOT / "datasets"
CONFIG = ROOT / "config"
SETTINGS = CONFIG / "settings.json"
CACHE = ROOT / "cache"
def keep_files_in_root():
"""라이브러리가 사용자 폴더(%TEMP% · %USERPROFILE%\\.cache · %APPDATA%)에 쓰는 캐시와 임시 파일을
모두 설치 폴더 안 cache\\ 로 돌린다. 다른 import 보다 먼저 돌아야 해서 이 모듈을 불러올 때 바로 한다."""
dirs = {
"TEMP": "temp", "TMP": "temp", "TMPDIR": "temp",
"TORCH_HOME": "torch", "TORCHINDUCTOR_CACHE_DIR": "torch/inductor", "CUDA_CACHE_PATH": "cuda",
"HF_HOME": "huggingface", "XDG_CACHE_HOME": "xdg", "MPLCONFIGDIR": "matplotlib",
"NUMBA_CACHE_DIR": "numba", "PIP_CACHE_DIR": "pip", "UV_CACHE_DIR": "uv",
}
for var, sub in dirs.items():
p = CACHE / sub
p.mkdir(parents=True, exist_ok=True)
os.environ[var] = str(p)
os.environ["PYTHONNOUSERSITE"] = "1" # %APPDATA%\Python 의 패키지를 읽지도 쓰지도 않게
import tempfile
tempfile.tempdir = None # 위 TEMP 를 다시 읽게
keep_files_in_root()
def use_engine():
"""Applio 코드가 상대 경로(rvc/models/...)를 쓰므로 엔진 폴더로 옮겨 가서 import 한다."""
if not (ENGINE / "rvc").is_dir():
raise SystemExit(f"엔진이 없습니다: {ENGINE}\ninstall.bat 을 먼저 실행해 주세요.")
os.environ["APPLIO_LOGS_DIR"] = str(TRAINING)
os.environ["APPLIO_CONFIG_DIR"] = str(CONFIG / "applio")
# 학습·추출 하위 프로세스도 같은 엔진을 보도록
os.environ["PYTHONPATH"] = os.pathsep.join([str(ENGINE), os.environ.get("PYTHONPATH", "")]).strip(os.pathsep)
os.chdir(ENGINE)
if str(ENGINE) not in sys.path:
sys.path.insert(0, str(ENGINE))
def slug(name: str) -> str:
"""폴더·파일 이름용 영문 아이디. 한글 이름은 info.json 에만 둔다."""
s = re.sub(r"[^A-Za-z0-9_-]+", "_", name).strip("_").lower()
return s[:40]
def load_json(path: Path, default):
try:
return json.loads(path.read_text(encoding="utf-8"))
except (OSError, ValueError):
return default
def save_json(path: Path, data) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(path.suffix + ".tmp")
tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
os.replace(tmp, path)
def ffmpeg() -> str:
"""Windows 는 엔진이 받아 둔 ffmpeg.exe, 그 밖에는 PATH 의 ffmpeg."""
exe = ENGINE / "ffmpeg.exe"
return str(exe) if exe.is_file() else "ffmpeg"
# javis_bot · 겜녹이와 같은 기준: -18 LUFS 평준화 + 리미터 (consent-recorder export 와 같은 필터)
LOUDNORM = "loudnorm=I=-18:TP=-1.5:LRA=11,alimiter=limit=0.89"