Download create_profile.py from Kremon96/Vi: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/spaces/Kremon96/Vi/resolve/main/create_profile.py
- Command line
-
hf download hf://spaces/Kremon96/Vi/create_profile.py
-
curl -L -o create_profile.py https://huggingface.co/spaces/Kremon96/Vi/resolve/main/create_profile.py
942 Bytes
| #!/usr/bin/env python3 | |
| """Create a voice profile from a reference clip (trimmed and saved as WAV).""" | |
| import argparse | |
| from pathlib import Path | |
| import soundfile as sf | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--id", required=True, help="profile name (filename stem)") | |
| ap.add_argument("--audio", required=True, help="reference audio file") | |
| ap.add_argument("--profiles-dir", default="profiles") | |
| ap.add_argument("--max-seconds", type=float, default=10.0) | |
| args = ap.parse_args() | |
| out = Path(args.profiles_dir) | |
| out.mkdir(parents=True, exist_ok=True) | |
| data, sr = sf.read(args.audio, dtype="float32", always_2d=False) | |
| if data.ndim > 1: | |
| data = data.mean(axis=1) | |
| data = data[: int(args.max_seconds * sr)] | |
| dst = out / f"{args.id}.wav" | |
| sf.write(str(dst), data, sr) | |
| print(f"Saved: {dst} ({len(data) / sr:.1f}s @ {sr} Hz)") | |
| if __name__ == "__main__": | |
| main() |