(
jsonl: str,
model_path: str,
output_dir: str,
data_name: str = "processd_data",
use_normalize: bool = True,
)
| 184 | |
| 185 | |
| 186 | def 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: |
no test coverage detected