File size: 26,721 Bytes
a6054f9 69ce3af 6cf1094 69ce3af a6054f9 ab70cd4 a6054f9 0c08106 a6054f9 6cf1094 a6054f9 cfb8093 a6054f9 01a63c9 a6054f9 c44b871 69ce3af c44b871 a6054f9 c44b871 0c08106 a6054f9 c44b871 0c08106 a6054f9 c44b871 0c08106 a6054f9 c44b871 0c08106 a6054f9 956a6cf c44b871 956a6cf a6054f9 c44b871 0c08106 a6054f9 c44b871 72bb1b6 a6054f9 833e3d4 a6054f9 0c08106 c44b871 69ce3af c44b871 0c08106 a6054f9 0c08106 c44b871 0c08106 c44b871 0c08106 a6054f9 0c08106 a6054f9 0c08106 833e3d4 0c08106 6ac707e 0c08106 c44b871 6ac707e 833e3d4 0c08106 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 210 211 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 326 327 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 438 439 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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
# coding=utf-8
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Common Voice Dataset"""
import os
import warnings
import datasets
from datasets.tasks import AutomaticSpeechRecognition
_DATA_URL = "https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-6.1-2020-12-11/{}.tar.gz"
_CITATION = """\
@inproceedings{commonvoice:2020,
author = {Ardila, R. and Branson, M. and Davis, K. and Henretty, M. and Kohler, M. and Meyer, J. and Morais, R. and Saunders, L. and Tyers, F. M. and Weber, G.},
title = {Common Voice: A Massively-Multilingual Speech Corpus},
booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},
pages = {4211--4215},
year = 2020
}
"""
_DESCRIPTION = """\
Common Voice is Mozilla's initiative to help teach machines how real people speak.
The dataset currently consists of 7,335 validated hours of speech in 60 languages, but we’re always adding more voices and languages.
"""
_HOMEPAGE = "https://commonvoice.mozilla.org/en/datasets"
_LICENSE = "https://github.com/common-voice/common-voice/blob/main/LICENSE"
_LANGUAGES = {
"ab": {
"Language": "Abkhaz",
"Date": "2020-12-11",
"Size": "39 MB",
"Version": "ab_1h_2020-12-11",
"Validated_Hr_Total": 0.05,
"Overall_Hr_Total": 1,
"Number_Of_Voice": 14,
},
"ar": {
"Language": "Arabic",
"Date": "2020-12-11",
"Size": "2 GB",
"Version": "ar_77h_2020-12-11",
"Validated_Hr_Total": 49,
"Overall_Hr_Total": 77,
"Number_Of_Voice": 672,
},
"as": {
"Language": "Assamese",
"Date": "2020-12-11",
"Size": "21 MB",
"Version": "as_0.78h_2020-12-11",
"Validated_Hr_Total": 0.74,
"Overall_Hr_Total": 0.78,
"Number_Of_Voice": 17,
},
"br": {
"Language": "Breton",
"Date": "2020-12-11",
"Size": "444 MB",
"Version": "br_16h_2020-12-11",
"Validated_Hr_Total": 7,
"Overall_Hr_Total": 16,
"Number_Of_Voice": 157,
},
"ca": {
"Language": "Catalan",
"Date": "2020-12-11",
"Size": "19 GB",
"Version": "ca_748h_2020-12-11",
"Validated_Hr_Total": 623,
"Overall_Hr_Total": 748,
"Number_Of_Voice": 5376,
},
"cnh": {
"Language": "Hakha Chin",
"Date": "2020-12-11",
"Size": "39 MB",
"Version": "ab_1h_2020-12-11",
"Validated_Hr_Total": 0.05,
"Overall_Hr_Total": 1,
"Number_Of_Voice": 14,
},
"cs": {
"Language": "Czech",
"Date": "2020-12-11",
"Size": "39 MB",
"Version": "ab_1h_2020-12-11",
"Validated_Hr_Total": 0.05,
"Overall_Hr_Total": 1,
"Number_Of_Voice": 14,
},
"cv": {
"Language": "Chuvash",
"Date": "2020-12-11",
"Size": "419 MB",
"Version": "cv_16h_2020-12-11",
"Validated_Hr_Total": 4,
"Overall_Hr_Total": 16,
"Number_Of_Voice": 92,
},
"cy": {
"Language": "Welsh",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "cy_124h_2020-12-11",
"Validated_Hr_Total": 95,
"Overall_Hr_Total": 124,
"Number_Of_Voice": 1382,
},
"de": {
"Language": "German",
"Date": "2020-12-11",
"Size": "22 GB",
"Version": "de_836h_2020-12-11",
"Validated_Hr_Total": 777,
"Overall_Hr_Total": 836,
"Number_Of_Voice": 12659,
},
"dv": {
"Language": "Dhivehi",
"Date": "2020-12-11",
"Size": "515 MB",
"Version": "dv_19h_2020-12-11",
"Validated_Hr_Total": 18,
"Overall_Hr_Total": 19,
"Number_Of_Voice": 167,
},
"el": {
"Language": "Greek",
"Date": "2020-12-11",
"Size": "364 MB",
"Version": "el_13h_2020-12-11",
"Validated_Hr_Total": 6,
"Overall_Hr_Total": 13,
"Number_Of_Voice": 118,
},
"en": {
"Language": "English",
"Date": "2020-12-11",
"Size": "56 GB",
"Version": "en_2181h_2020-12-11",
"Validated_Hr_Total": 1686,
"Overall_Hr_Total": 2181,
"Number_Of_Voice": 66173,
},
"eo": {
"Language": "Esperanto",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "eo_102h_2020-12-11",
"Validated_Hr_Total": 90,
"Overall_Hr_Total": 102,
"Number_Of_Voice": 574,
},
"es": {
"Language": "Spanish",
"Date": "2020-12-11",
"Size": "15 GB",
"Version": "es_579h_2020-12-11",
"Validated_Hr_Total": 324,
"Overall_Hr_Total": 579,
"Number_Of_Voice": 19484,
},
"et": {
"Language": "Estonian",
"Date": "2020-12-11",
"Size": "732 MB",
"Version": "et_27h_2020-12-11",
"Validated_Hr_Total": 19,
"Overall_Hr_Total": 27,
"Number_Of_Voice": 543,
},
"eu": {
"Language": "Basque",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "eu_131h_2020-12-11",
"Validated_Hr_Total": 89,
"Overall_Hr_Total": 131,
"Number_Of_Voice": 1028,
},
"fa": {
"Language": "Persian",
"Date": "2020-12-11",
"Size": "8 GB",
"Version": "fa_321h_2020-12-11",
"Validated_Hr_Total": 282,
"Overall_Hr_Total": 321,
"Number_Of_Voice": 3655,
},
"fi": {
"Language": "Finnish",
"Date": "2020-12-11",
"Size": "48 MB",
"Version": "fi_1h_2020-12-11",
"Validated_Hr_Total": 1,
"Overall_Hr_Total": 1,
"Number_Of_Voice": 27,
},
"fr": {
"Language": "French",
"Date": "2020-12-11",
"Size": "18 GB",
"Version": "fr_682h_2020-12-11",
"Validated_Hr_Total": 623,
"Overall_Hr_Total": 682,
"Number_Of_Voice": 12953,
},
"fy-NL": {
"Language": "Frisian",
"Date": "2020-12-11",
"Size": "1 GB",
"Version": "fy-NL_46h_2020-12-11",
"Validated_Hr_Total": 14,
"Overall_Hr_Total": 46,
"Number_Of_Voice": 467,
},
"ga-IE": {
"Language": "Irish",
"Date": "2020-12-11",
"Size": "149 MB",
"Version": "ga-IE_5h_2020-12-11",
"Validated_Hr_Total": 3,
"Overall_Hr_Total": 5,
"Number_Of_Voice": 101,
},
"hi": {
"Language": "Hindi",
"Date": "2020-12-11",
"Size": "20 MB",
"Version": "hi_0.8h_2020-12-11",
"Validated_Hr_Total": 0.54,
"Overall_Hr_Total": 0.8,
"Number_Of_Voice": 31,
},
"hsb": {
"Language": "Sorbian, Upper",
"Date": "2020-12-11",
"Size": "76 MB",
"Version": "hsb_2h_2020-12-11",
"Validated_Hr_Total": 2,
"Overall_Hr_Total": 2,
"Number_Of_Voice": 19,
},
"hu": {
"Language": "Hungarian",
"Date": "2020-12-11",
"Size": "232 MB",
"Version": "hu_8h_2020-12-11",
"Validated_Hr_Total": 8,
"Overall_Hr_Total": 8,
"Number_Of_Voice": 47,
},
"ia": {
"Language": "InterLinguia",
"Date": "2020-12-11",
"Size": "216 MB",
"Version": "ia_8h_2020-12-11",
"Validated_Hr_Total": 6,
"Overall_Hr_Total": 8,
"Number_Of_Voice": 36,
},
"id": {
"Language": "Indonesian",
"Date": "2020-12-11",
"Size": "454 MB",
"Version": "id_17h_2020-12-11",
"Validated_Hr_Total": 9,
"Overall_Hr_Total": 17,
"Number_Of_Voice": 219,
},
"it": {
"Language": "Italian",
"Date": "2020-12-11",
"Size": "5 GB",
"Version": "it_199h_2020-12-11",
"Validated_Hr_Total": 158,
"Overall_Hr_Total": 199,
"Number_Of_Voice": 5729,
},
"ja": {
"Language": "Japanese",
"Date": "2020-12-11",
"Size": "146 MB",
"Version": "ja_5h_2020-12-11",
"Validated_Hr_Total": 3,
"Overall_Hr_Total": 5,
"Number_Of_Voice": 235,
},
"ka": {
"Language": "Georgian",
"Date": "2020-12-11",
"Size": "99 MB",
"Version": "ka_3h_2020-12-11",
"Validated_Hr_Total": 3,
"Overall_Hr_Total": 3,
"Number_Of_Voice": 44,
},
"kab": {
"Language": "Kabyle",
"Date": "2020-12-11",
"Size": "16 GB",
"Version": "kab_622h_2020-12-11",
"Validated_Hr_Total": 525,
"Overall_Hr_Total": 622,
"Number_Of_Voice": 1309,
},
"ky": {
"Language": "Kyrgyz",
"Date": "2020-12-11",
"Size": "553 MB",
"Version": "ky_22h_2020-12-11",
"Validated_Hr_Total": 11,
"Overall_Hr_Total": 22,
"Number_Of_Voice": 134,
},
"lg": {
"Language": "Luganda",
"Date": "2020-12-11",
"Size": "199 MB",
"Version": "lg_8h_2020-12-11",
"Validated_Hr_Total": 3,
"Overall_Hr_Total": 8,
"Number_Of_Voice": 76,
},
"lt": {
"Language": "Lithuanian",
"Date": "2020-12-11",
"Size": "129 MB",
"Version": "lt_4h_2020-12-11",
"Validated_Hr_Total": 2,
"Overall_Hr_Total": 4,
"Number_Of_Voice": 30,
},
"lv": {
"Language": "Latvian",
"Date": "2020-12-11",
"Size": "199 MB",
"Version": "lv_7h_2020-12-11",
"Validated_Hr_Total": 6,
"Overall_Hr_Total": 7,
"Number_Of_Voice": 99,
},
"mn": {
"Language": "Mongolian",
"Date": "2020-12-11",
"Size": "464 MB",
"Version": "mn_17h_2020-12-11",
"Validated_Hr_Total": 11,
"Overall_Hr_Total": 17,
"Number_Of_Voice": 376,
},
"mt": {
"Language": "Maltese",
"Date": "2020-12-11",
"Size": "405 MB",
"Version": "mt_15h_2020-12-11",
"Validated_Hr_Total": 7,
"Overall_Hr_Total": 15,
"Number_Of_Voice": 171,
},
"nl": {
"Language": "Dutch",
"Date": "2020-12-11",
"Size": "2 GB",
"Version": "nl_63h_2020-12-11",
"Validated_Hr_Total": 59,
"Overall_Hr_Total": 63,
"Number_Of_Voice": 1012,
},
"or": {
"Language": "Odia",
"Date": "2020-12-11",
"Size": "190 MB",
"Version": "or_7h_2020-12-11",
"Validated_Hr_Total": 0.87,
"Overall_Hr_Total": 7,
"Number_Of_Voice": 34,
},
"pa-IN": {
"Language": "Punjabi",
"Date": "2020-12-11",
"Size": "67 MB",
"Version": "pa-IN_2h_2020-12-11",
"Validated_Hr_Total": 0.5,
"Overall_Hr_Total": 2,
"Number_Of_Voice": 26,
},
"pl": {
"Language": "Polish",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "pl_129h_2020-12-11",
"Validated_Hr_Total": 108,
"Overall_Hr_Total": 129,
"Number_Of_Voice": 2647,
},
"pt": {
"Language": "Portuguese",
"Date": "2020-12-11",
"Size": "2 GB",
"Version": "pt_63h_2020-12-11",
"Validated_Hr_Total": 50,
"Overall_Hr_Total": 63,
"Number_Of_Voice": 1120,
},
"rm-sursilv": {
"Language": "Romansh Sursilvan",
"Date": "2020-12-11",
"Size": "263 MB",
"Version": "rm-sursilv_9h_2020-12-11",
"Validated_Hr_Total": 5,
"Overall_Hr_Total": 9,
"Number_Of_Voice": 78,
},
"rm-vallader": {
"Language": "Romansh Vallader",
"Date": "2020-12-11",
"Size": "103 MB",
"Version": "rm-vallader_3h_2020-12-11",
"Validated_Hr_Total": 2,
"Overall_Hr_Total": 3,
"Number_Of_Voice": 39,
},
"ro": {
"Language": "Romanian",
"Date": "2020-12-11",
"Size": "250 MB",
"Version": "ro_9h_2020-12-11",
"Validated_Hr_Total": 6,
"Overall_Hr_Total": 9,
"Number_Of_Voice": 130,
},
"ru": {
"Language": "Russian",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "ru_130h_2020-12-11",
"Validated_Hr_Total": 111,
"Overall_Hr_Total": 130,
"Number_Of_Voice": 1412,
},
"rw": {
"Language": "Kinyarwanda",
"Date": "2020-12-11",
"Size": "40 GB",
"Version": "rw_1510h_2020-12-11",
"Validated_Hr_Total": 1183,
"Overall_Hr_Total": 1510,
"Number_Of_Voice": 410,
},
"sah": {
"Language": "Sakha",
"Date": "2020-12-11",
"Size": "173 MB",
"Version": "sah_6h_2020-12-11",
"Validated_Hr_Total": 4,
"Overall_Hr_Total": 6,
"Number_Of_Voice": 42,
},
"sl": {
"Language": "Slovenian",
"Date": "2020-12-11",
"Size": "212 MB",
"Version": "sl_7h_2020-12-11",
"Validated_Hr_Total": 5,
"Overall_Hr_Total": 7,
"Number_Of_Voice": 82,
},
"sv-SE": {
"Language": "Swedish",
"Date": "2020-12-11",
"Size": "402 MB",
"Version": "sv-SE_15h_2020-12-11",
"Validated_Hr_Total": 12,
"Overall_Hr_Total": 15,
"Number_Of_Voice": 222,
},
"ta": {
"Language": "Tamil",
"Date": "2020-12-11",
"Size": "648 MB",
"Version": "ta_24h_2020-12-11",
"Validated_Hr_Total": 14,
"Overall_Hr_Total": 24,
"Number_Of_Voice": 266,
},
"th": {
"Language": "Thai",
"Date": "2020-12-11",
"Size": "325 MB",
"Version": "th_12h_2020-12-11",
"Validated_Hr_Total": 8,
"Overall_Hr_Total": 12,
"Number_Of_Voice": 182,
},
"tr": {
"Language": "Turkish",
"Date": "2020-12-11",
"Size": "592 MB",
"Version": "tr_22h_2020-12-11",
"Validated_Hr_Total": 20,
"Overall_Hr_Total": 22,
"Number_Of_Voice": 678,
},
"tt": {
"Language": "Tatar",
"Date": "2020-12-11",
"Size": "741 MB",
"Version": "tt_28h_2020-12-11",
"Validated_Hr_Total": 26,
"Overall_Hr_Total": 28,
"Number_Of_Voice": 185,
},
"uk": {
"Language": "Ukrainian",
"Date": "2020-12-11",
"Size": "1 GB",
"Version": "uk_43h_2020-12-11",
"Validated_Hr_Total": 30,
"Overall_Hr_Total": 43,
"Number_Of_Voice": 459,
},
"vi": {
"Language": "Vietnamese",
"Date": "2020-12-11",
"Size": "50 MB",
"Version": "vi_1h_2020-12-11",
"Validated_Hr_Total": 0.74,
"Overall_Hr_Total": 1,
"Number_Of_Voice": 62,
},
"vot": {
"Language": "Votic",
"Date": "2020-12-11",
"Size": "7 MB",
"Version": "vot_0.28h_2020-12-11",
"Validated_Hr_Total": 0,
"Overall_Hr_Total": 0.28,
"Number_Of_Voice": 3,
},
"zh-CN": {
"Language": "Chinese (China)",
"Date": "2020-12-11",
"Size": "2 GB",
"Version": "zh-CN_78h_2020-12-11",
"Validated_Hr_Total": 56,
"Overall_Hr_Total": 78,
"Number_Of_Voice": 3501,
},
"zh-HK": {
"Language": "Chinese (Hong Kong)",
"Date": "2020-12-11",
"Size": "3 GB",
"Version": "zh-HK_100h_2020-12-11",
"Validated_Hr_Total": 50,
"Overall_Hr_Total": 100,
"Number_Of_Voice": 2536,
},
"zh-TW": {
"Language": "Chinese (Taiwan)",
"Date": "2020-12-11",
"Size": "2 GB",
"Version": "zh-TW_78h_2020-12-11",
"Validated_Hr_Total": 55,
"Overall_Hr_Total": 78,
"Number_Of_Voice": 1444,
},
}
class CommonVoiceConfig(datasets.BuilderConfig):
"""BuilderConfig for CommonVoice."""
def __init__(self, name, sub_version, **kwargs):
"""
Args:
data_dir: `string`, the path to the folder containing the files in the
downloaded .tar
citation: `string`, citation for the data set
url: `string`, url for information about the data set
**kwargs: keyword arguments forwarded to super.
"""
self.sub_version = sub_version
self.language = kwargs.pop("language", None)
self.date_of_snapshot = kwargs.pop("date", None)
self.size = kwargs.pop("size", None)
self.validated_hr_total = kwargs.pop("val_hrs", None)
self.total_hr_total = kwargs.pop("total_hrs", None)
self.num_of_voice = kwargs.pop("num_of_voice", None)
description = f"Common Voice speech to text dataset in {self.language} version {self.sub_version} of {self.date_of_snapshot}. The dataset comprises {self.validated_hr_total} of validated transcribed speech data from {self.num_of_voice} speakers. The dataset has a size of {self.size}"
super(CommonVoiceConfig, self).__init__(
name=name, version=datasets.Version("6.1.0", ""), description=description, **kwargs
)
class CommonVoice(datasets.GeneratorBasedBuilder):
DEFAULT_WRITER_BATCH_SIZE = 1000
BUILDER_CONFIGS = [
CommonVoiceConfig(
name=lang_id,
language=_LANGUAGES[lang_id]["Language"],
sub_version=_LANGUAGES[lang_id]["Version"],
date=_LANGUAGES[lang_id]["Date"],
size=_LANGUAGES[lang_id]["Size"],
val_hrs=_LANGUAGES[lang_id]["Validated_Hr_Total"],
total_hrs=_LANGUAGES[lang_id]["Overall_Hr_Total"],
num_of_voice=_LANGUAGES[lang_id]["Number_Of_Voice"],
)
for lang_id in _LANGUAGES.keys()
]
def _info(self):
warnings.warn(
"""
This version of the Common Voice dataset is deprecated.
You can download the latest one with
>>> load_dataset(\"mozilla-foundation/common_voice_11_0\", \"en\")
""",
FutureWarning,
)
features = datasets.Features(
{
"client_id": datasets.Value("string"),
"path": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=48_000),
"sentence": datasets.Value("string"),
"up_votes": datasets.Value("int64"),
"down_votes": datasets.Value("int64"),
"age": datasets.Value("string"),
"gender": datasets.Value("string"),
"accent": datasets.Value("string"),
"locale": datasets.Value("string"),
"segment": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="sentence")],
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
# Download the TAR archive that contains the audio files:
archive_path = dl_manager.download(_DATA_URL.format(self.config.name))
# First we locate the data using the path within the archive:
path_to_data = "/".join(["cv-corpus-6.1-2020-12-11", self.config.name])
path_to_clips = "/".join([path_to_data, "clips"])
metadata_filepaths = {
split: "/".join([path_to_data, f"{split}.tsv"])
for split in ["train", "test", "dev", "other", "validated", "invalidated"]
}
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
# To access the audio data from the TAR archives using the download manager,
# we have to use the dl_manager.iter_archive method.
#
# This is because dl_manager.download_and_extract
# doesn't work to stream TAR archives in streaming mode.
# (we have to stream the files of a TAR archive one by one)
#
# The iter_archive method returns an iterable of (path_within_archive, file_obj) for every
# file in the TAR archive.
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["train"],
"path_to_clips": path_to_clips,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["test"],
"path_to_clips": path_to_clips,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["dev"],
"path_to_clips": path_to_clips,
},
),
datasets.SplitGenerator(
name="other",
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["other"],
"path_to_clips": path_to_clips,
},
),
datasets.SplitGenerator(
name="validated",
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["validated"],
"path_to_clips": path_to_clips,
},
),
datasets.SplitGenerator(
name="invalidated",
gen_kwargs={
"local_extracted_archive": local_extracted_archive,
"archive_iterator": dl_manager.iter_archive(
archive_path
), # use iter_archive here to access the files in the TAR archives
"metadata_filepath": metadata_filepaths["invalidated"],
"path_to_clips": path_to_clips,
},
),
]
def _generate_examples(self, local_extracted_archive, archive_iterator, metadata_filepath, path_to_clips):
"""Yields examples."""
data_fields = list(self._info().features.keys())
# audio is not a header of the csv files
data_fields.remove("audio")
path_idx = data_fields.index("path")
all_field_values = {}
metadata_found = False
# Here we iterate over all the files within the TAR archive:
for path, f in archive_iterator:
# Parse the metadata CSV file
if path == metadata_filepath:
metadata_found = True
lines = f.readlines()
headline = lines[0].decode("utf-8")
column_names = headline.strip().split("\t")
assert (
column_names == data_fields
), f"The file should have {data_fields} as column names, but has {column_names}"
for line in lines[1:]:
field_values = line.decode("utf-8").strip().split("\t")
# set full path for mp3 audio file
audio_path = "/".join([path_to_clips, field_values[path_idx]])
all_field_values[audio_path] = field_values
# Else, read the audio file and yield an example
elif path.startswith(path_to_clips):
assert metadata_found, "Found audio clips before the metadata TSV file."
if not all_field_values:
break
if path in all_field_values:
# retrieve the metadata corresponding to this audio file
field_values = all_field_values[path]
# if data is incomplete, fill with empty values
if len(field_values) < len(data_fields):
field_values += (len(data_fields) - len(field_values)) * ["''"]
result = {key: value for key, value in zip(data_fields, field_values)}
# set audio feature
path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
result["audio"] = {"path": path, "bytes": f.read()}
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
result["path"] = path if local_extracted_archive else None
yield path, result
|