duration_calculator
Author: Heli Qi Affiliation: NAIST Date: 2023.02
cal_duration_by_tg(tg_file_list, idx2punc_text, retain_stress)
Calculate the phoneme duration for each TextGrid file and return idx2text and idx2duration dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tg_file_list
|
List[str]
|
List of paths to TextGrid files. |
required |
retain_stress
|
bool
|
Whether to retain the stress indicators at the end of each vowel phonemes. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple[Dict, Dict]: A tuple containing two dictionaries: 1. idx2text: mapping file indices to tokenized text 2. idx2duration: mapping file indices to phoneme durations |
Source code in speechain/datasets/pyscripts/duration_calculator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
combine_subsets(subset_path_list, new_subset_name, save_path)
Combines the metadata of multiple subsets into a single new subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset_path_list
|
List[str]
|
A list of paths to the individual subset directories. |
required |
new_subset_name
|
str
|
The name of the new combined subset directory. |
required |
save_path
|
str
|
The path where the new combined subset directory will be saved. |
required |
This function computes the intersection of directories from the input subsets, merges their metadata, calculates the phoneme vocabulary, and saves the new combined metadata into the specified save path.
Source code in speechain/datasets/pyscripts/duration_calculator.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
convert_phns_to_vocab(phn_list)
Converts a list of phonemes to a vocabulary list, sorted by frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phn_list
|
List[str]
|
A list of phonemes. |
required |
Returns:
| Type | Description |
|---|---|
|
List[str]: A list of unique phonemes sorted by frequency, with additional tokens for special purposes. |
This function calculates the frequency of each phoneme in the input list, sorts them in descending order, and returns a new list with the unique phonemes along with some special tokens for compatibility with autoregressive TTS models.
Source code in speechain/datasets/pyscripts/duration_calculator.py
dump_subset_metadata(dataset_path, save_path, subset_name, retain_punc, retain_stress, idx2text, idx2duration)
Save the subset-specific idx2text and idx2duration dictionaries as metadata files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
str
|
The path to the dataset directory. |
required |
save_path
|
str
|
The path to save the metadata files. |
required |
subset_name
|
str
|
The name of the subset to process. |
required |
retain_stress
|
bool
|
Whether to retain the stress indicators at the end of each vowel phonemes. |
required |
idx2text
|
Dict
|
The dictionary mapping file indices to tokenized text. |
required |
idx2duration
|
Dict
|
The dictionary mapping file indices to phoneme durations. |
required |
Source code in speechain/datasets/pyscripts/duration_calculator.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
main(data_path, save_folder_name, dataset_name, subset_name=None, retain_punc=False, retain_stress=True, save_path=None, ncpu=8)
Main function to process TextGrid files and save metadata files for a given dataset and subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str
|
The path where you placed the dumped data. |
required |
save_folder_name
|
str
|
The name of the pretrained model you have used to get the .TextGrid files. |
required |
retain_stress
|
bool
|
bool Whether to retain the stress indicators at the end of each vowel phonemes. |
True
|
dataset_name
|
str
|
The name of the dataset you want to process. |
required |
subset_name
|
str
|
The name of the subset in your given dataset you want to process. |
None
|
save_path
|
str
|
The path where you want to save the duration metadata files. If not given, the files will be saved to {data_path}/mfa. Defaults to None. |
None
|
ncpu
|
int
|
The number of processes you want to use to calculate the phoneme duration. Defaults to 8. |
8
|
Source code in speechain/datasets/pyscripts/duration_calculator.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |