MCPcopy
hub / github.com/OpenBMB/VoxCPM / cmd_batch

Function cmd_batch

src/voxcpm/cli.py:308–363  ·  view source on GitHub ↗
(args, parser)

Source from the content-addressed store, hash-verified

306
307
308def cmd_batch(args, parser):
309 import soundfile as sf
310
311 input_file = require_file_exists(args.input, parser, "input file")
312 output_dir = Path(args.output_dir)
313 output_dir.mkdir(parents=True, exist_ok=True)
314
315 with open(input_file, "r", encoding="utf-8") as f:
316 texts = [line.strip() for line in f if line.strip()]
317
318 if not texts:
319 sys.exit("Error: Input file is empty")
320
321 prompt_text = validate_batch_args(args, parser)
322 model = load_model(args)
323
324 prompt_audio_path = None
325 if args.prompt_audio:
326 prompt_audio_path = str(
327 require_file_exists(args.prompt_audio, parser, "prompt audio file")
328 )
329
330 reference_audio_path = None
331 if args.reference_audio:
332 reference_audio_path = str(
333 require_file_exists(args.reference_audio, parser, "reference audio file")
334 )
335
336 success_count = 0
337
338 for i, text in enumerate(texts, 1):
339 try:
340 final_text = build_final_text(text, args.control)
341 audio_array = model.generate(
342 text=final_text,
343 prompt_wav_path=prompt_audio_path,
344 prompt_text=prompt_text,
345 reference_wav_path=reference_audio_path,
346 cfg_value=args.cfg_value,
347 inference_timesteps=args.inference_timesteps,
348 normalize=args.normalize,
349 denoise=args.denoise
350 and (prompt_audio_path is not None or reference_audio_path is not None),
351 )
352
353 output_file = output_dir / f"output_{i:03d}.wav"
354 sf.write(str(output_file), audio_array, model.tts_model.sample_rate)
355
356 duration = len(audio_array) / model.tts_model.sample_rate
357 print(f"Saved: {output_file} ({duration:.2f}s)", file=sys.stderr)
358 success_count += 1
359
360 except Exception as e:
361 print(f"Failed on line {i}: {e}", file=sys.stderr)
362
363 print(f"\nBatch finished: {success_count}/{len(texts)} succeeded", file=sys.stderr)
364
365

Callers 2

_dispatch_legacyFunction · 0.85
mainFunction · 0.85

Calls 5

require_file_existsFunction · 0.85
validate_batch_argsFunction · 0.85
build_final_textFunction · 0.85
load_modelFunction · 0.70
generateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…