MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / main

Function main

tests/chatterbox/chatterbox_python_warm_bench.py:94–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92
93
94def main() -> int:
95 args = parse_args()
96 texts = args.texts or ["The benchmark request should produce clear cloned speech for comparison."]
97
98 language = args.language.lower()
99 ChatterboxTTS = load_reference_chatterbox_tts(language)
100 import torch
101
102 torch.set_num_threads(max(1, args.threads))
103 if args.backend == "cuda":
104 torch.cuda.set_device(args.device)
105 device = f"cuda:{args.device}"
106 else:
107 device = "cpu"
108
109 model = ChatterboxTTS.from_local(args.model, device=device)
110 model.s3gen.flow.inference_cfg_rate = args.s3gen_cfg_rate
111
112 def run_once(text: str) -> tuple[np.ndarray, int, float]:
113 torch.manual_seed(args.seed)
114 if args.backend == "cuda":
115 torch.cuda.manual_seed_all(args.seed)
116 started = time.perf_counter()
117 if language == "en":
118 wav = model.generate(
119 text,
120 audio_prompt_path=str(args.clone_audio),
121 exaggeration=args.exaggeration,
122 cfg_weight=args.cfg_weight,
123 temperature=args.temperature,
124 repetition_penalty=args.repetition_penalty,
125 min_p=args.min_p,
126 top_p=args.top_p,
127 )
128 else:
129 wav = model.generate(
130 text,
131 language_id=language,
132 audio_prompt_path=str(args.clone_audio),
133 exaggeration=args.exaggeration,
134 cfg_weight=args.cfg_weight,
135 temperature=args.temperature,
136 repetition_penalty=args.repetition_penalty,
137 min_p=args.min_p,
138 top_p=args.top_p,
139 )
140 if args.backend == "cuda":
141 torch.cuda.synchronize(args.device)
142 ended = time.perf_counter()
143 audio = wav.detach().cpu().numpy().astype(np.float32).reshape(-1)
144 return audio, int(model.sr), (ended - started) * 1000.0
145
146 args.timing_file.parent.mkdir(parents=True, exist_ok=True)
147 with args.timing_file.open("w", encoding="utf-8") as timing:
148 timing.write(f"chatterbox.python_reference_src {REFERENCE_SRC}\n")
149 warmup_outputs: list[tuple[np.ndarray, int, float]] = []
150 for _ in range(max(0, args.warmup)):
151 result = run_once(args.warmup_text)

Callers 1

Calls 10

maxFunction · 0.85
printFunction · 0.85
set_num_threadsMethod · 0.80
openMethod · 0.80
parse_argsFunction · 0.70
run_onceFunction · 0.70
summary_jsonFunction · 0.70
write_wavFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected