"""Vevo-Timbre (zero-shot voice conversion) with TensorRT engines: the same pipeline as pipeline.py (the official inference_fm: content tokens of the source and the reference, the condition, 32 flow-matching steps with the reference's mel as the prompt, the vocoder; resampling, mel and iSTFT in numpy), with each graph run as an engine: - content.engine: wave [1, N] (16 kHz, up to 30 s) -> tokens; - cond.engine: tokens [1, 50 - 2500] (reference + source) -> cond [1, L, 1024]; - estimator.engine: x [1, 50 - 2500, 128], t [1], cond [1, 50 - 2500, 1024] -> flow; - vocoder.engine: mel [1, 128, 50 - 1500] -> real, imag. Built from the int8 ONNX build (int8 weights, fp32 math). Limits: a source of up to 30 s, a voice reference of up to 20 s. Needs numpy, soundfile, soxr, tensorrt-cu12 / tensorrt-lean-cu12 10.x and polygraphy. Non-commercial licence (CC BY-NC 4.0). python int8/pipeline_trt.py source.wav voice.wav out.wav [--steps 32] [--seed 0] """ from __future__ import annotations import json import sys from pathlib import Path import numpy as np HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) from pipeline import VevoTimbre # noqa: E402 from trt_runner import OrtLike # noqa: E402 OUTS = {"content": ["tokens"], "cond": ["cond"], "estimator": ["flow"], "vocoder": ["real", "imag"]} SOURCE_SECONDS, REF_SECONDS = 30, 20 class VevoTimbreTrt(VevoTimbre): def __init__(self, folder=HERE): folder = Path(folder) self.s = {n: OrtLike(folder / f"{n}.engine", o) for n, o in OUTS.items()} self.basis = np.load(folder / "mel_basis.npy") self.cfg = json.loads((folder / "config.json").read_text()) def __call__(self, src, src_sr, ref, ref_sr, steps=32, seed=0, rng=None): if len(src) / src_sr > SOURCE_SECONDS or len(ref) / ref_sr > REF_SECONDS: raise ValueError(f"the engines take a source of up to {SOURCE_SECONDS} s and a reference of up to " f"{REF_SECONDS} s") return super().__call__(src, src_sr, ref, ref_sr, steps, seed, rng) if __name__ == "__main__": import argparse import soundfile as sf ap = argparse.ArgumentParser() ap.add_argument("source"); ap.add_argument("voice"); ap.add_argument("output") ap.add_argument("--steps", type=int, default=32); ap.add_argument("--seed", type=int, default=0) a = ap.parse_args() s, ssr = sf.read(a.source, dtype="float32", always_2d=True) v, vsr = sf.read(a.voice, dtype="float32", always_2d=True) y, sr = VevoTimbreTrt()(s.mean(1), ssr, v.mean(1), vsr, a.steps, a.seed) sf.write(a.output, y, sr)