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

Function process_data

finetune/data_preprocess.py:186–379  ·  view source on GitHub ↗
(
    jsonl: str,
    model_path: str,
    output_dir: str,
    data_name: str = "processd_data",
    use_normalize: bool = True,
)

Source from the content-addressed store, hash-verified

184
185
186def process_data(
187 jsonl: str,
188 model_path: str,
189 output_dir: str,
190 data_name: str = "processd_data",
191 use_normalize: bool = True,
192):
193 # Create output directory if it doesn't exist
194 os.makedirs(output_dir, exist_ok=True)
195
196 device = "cuda" if torch.cuda.is_available() else "cpu"
197 print(f"Using device: {device}")
198
199 # Load models
200 print("Loading models...")
201 tokenizer, spt = load_tokenizer(model_path, SPT_CONFIG_PATH, SPT_CHECKPOINT_PATH)
202 spt = spt.to(device)
203
204 # Load the items from the JSONL file
205 try:
206 with open(jsonl, "r") as f:
207 items = [json.loads(line) for line in f.readlines()]
208 print(f"Loaded {len(items)} items from {jsonl}")
209 except FileNotFoundError:
210 print(f"Error: JSONL file '{jsonl}' not found")
211 return
212 except json.JSONDecodeError as e:
213 print(f"Error parsing JSONL file: {e}")
214 return
215
216 # Store all processed data and length information
217 all_data = []
218 offsets = []
219 tokens_lengths = [] # Added: store total token length
220 tims_lengths = [] # Added: store audio token length
221
222 for idx, item in enumerate(items):
223 # Support two JSONL formats
224 # Format 1: {"file_path": "path/to/audio.wav", "full_transcript": "speech content..."}
225 # Format 2: {"reference_audio": "path1", "reference_text": "text1", "audio": "path2", "text": "text2"}
226
227 if "file_path" in item and "full_transcript" in item:
228 # Original format
229 file_path = item["file_path"]
230 full_text = item["full_transcript"]
231
232 # Check if audio file exists
233 if not file_path:
234 print(f"Warning: Item {idx} has empty file_path, skipping...")
235 continue
236
237 if not os.path.exists(file_path):
238 print(
239 f"Warning: Audio file not found: {file_path}, skipping item {idx}..."
240 )
241 continue
242
243 try:

Callers 2

data_preprocess.pyFile · 0.85

Calls 4

load_audio_dataFunction · 0.90
normalize_textFunction · 0.90
load_tokenizerFunction · 0.85
process_inputsFunction · 0.70

Tested by

no test coverage detected