MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTSD / process_batch

Function process_batch

generation_utils.py:445–761  ·  view source on GitHub ↗

Process a batch of data items and generate audio, return audio data and metadata

(
    batch_items,
    tokenizer,
    model,
    spt,
    device,
    system_prompt,
    start_idx,
    use_normalize=False,
    silence_duration=0,
)

Source from the content-addressed store, hash-verified

443
444
445def process_batch(
446 batch_items,
447 tokenizer,
448 model,
449 spt,
450 device,
451 system_prompt,
452 start_idx,
453 use_normalize=False,
454 silence_duration=0,
455):
456 """Process a batch of data items and generate audio, return audio data and metadata"""
457 try:
458 # Prepare batch data
459 batch_size = len(batch_items)
460 texts = []
461 prompts = [system_prompt] * batch_size
462 prompt_audios = []
463 actual_texts_data = [] # Store actual text data used
464
465 print(f"Processing {batch_size} samples starting from index {start_idx}...")
466
467 # Extract text and audio from each sample
468 for i, item in enumerate(batch_items):
469 # Use new processing function
470 processed_item = process_jsonl_item(item)
471
472 text = processed_item["text"]
473 prompt_text = processed_item["prompt_text"]
474
475 # Merge text, if prompt_text is empty, full_text is just text
476 full_text = prompt_text + text if prompt_text else text
477 original_full_text = full_text # Save original text
478
479 # Apply text normalization based on parameter
480 if use_normalize:
481 full_text = normalize_text(full_text)
482
483 # Replace speaker tags
484 final_text = full_text.replace("[S1]", "<speaker1>").replace(
485 "[S2]", "<speaker2>"
486 )
487 texts.append(final_text)
488
489 # Save actual text information used
490 actual_texts_data.append(
491 {
492 "index": start_idx + i,
493 "original_text": original_full_text,
494 "normalized_text": (
495 normalize_text(original_full_text) if use_normalize else None
496 ),
497 "final_text": final_text,
498 "use_normalize": use_normalize,
499 }
500 )
501
502 # Get reference audio

Callers 3

process_input_to_audioFunction · 0.90
mainFunction · 0.90

Calls 12

process_jsonl_itemFunction · 0.85
load_audio_dataFunction · 0.85
shifting_inputsFunction · 0.85
rpaddingFunction · 0.85
find_max_valid_positionsFunction · 0.85
crossfade_concatFunction · 0.85
encodeMethod · 0.80
inference_detokenizeMethod · 0.80
normalize_textFunction · 0.70
process_inputsFunction · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected