Spaces:
Sleeping
Sleeping
File size: 38,022 Bytes
2267fac 8f39105 2267fac c9ba89c ac87612 2267fac d03c698 2267fac 8f39105 2267fac 168b5c0 03aae6c 2267fac 03aae6c f392af0 c9ba89c d03c698 59cce29 03aae6c 59cce29 03aae6c 0cd926b 59cce29 03aae6c 59cce29 03aae6c 0cd926b 59cce29 7903607 03aae6c 7903607 03aae6c f392af0 c9ba89c 3e3be60 4a879cc 3e3be60 3eaca0e 4a879cc 10a4560 4a879cc 10a4560 4a879cc 3eaca0e 86a716b fc81d59 86a716b 59cce29 8692b5e 4a879cc 8692b5e e924ab6 4a879cc e924ab6 4a879cc e924ab6 59cce29 03aae6c 59cce29 03aae6c 0cd926b 59cce29 e924ab6 4a879cc e924ab6 302c392 e924ab6 5b60539 8274008 302c392 8274008 302c392 5b60539 e43afda 302c392 e43afda 302c392 e43afda 302c392 e43afda 302c392 e43afda 797e507 0cd926b 797e507 302c392 797e507 302c392 797e507 302c392 797e507 03c0c2e 302c392 03c0c2e 302c392 03c0c2e 302c392 03c0c2e 961a8f0 302c392 961a8f0 59cce29 961a8f0 4a879cc 961a8f0 d03c698 03aae6c d03c698 03aae6c 0cd926b 59cce29 961a8f0 302c392 961a8f0 302c392 961a8f0 59cce29 4a879cc 59cce29 03aae6c 59cce29 03aae6c 4a879cc 302c392 0cd926b 302c392 0cd926b d49cecc 302c392 4a879cc 302c392 4a879cc 59cce29 4a879cc 302c392 4a879cc 2267fac c9ba89c 2267fac c9ba89c 2267fac c9ba89c 8f39105 c9ba89c 2267fac c9ba89c 8f39105 c9ba89c 8f39105 c9ba89c 8f39105 c9ba89c 8f39105 e924ab6 2267fac 8dc832e 4281a4a 2267fac 3194abe 2267fac f392af0 2267fac f392af0 2267fac 8f39105 d8e6dc5 8f39105 2267fac 26dfa9a 2267fac 302c392 4a879cc d03c698 4a879cc 3e3be60 4a879cc 8692b5e 32e5ca1 4a879cc 961a8f0 4a879cc 18f3a11 c9ba89c 3194abe 168b5c0 0a78294 2267fac 8f39105 2267fac ac87612 c9ba89c 2267fac c9ba89c 98bbe7c c9ba89c 98bbe7c c9ba89c 98bbe7c c9ba89c 98bbe7c c9ba89c e924ab6 c9ba89c ac87612 d03c698 168b5c0 c9ba89c 168b5c0 302c392 4a879cc d03c698 c9ba89c d03c698 4a879cc 74df484 4a879cc 32e5ca1 4a879cc b6416e6 4a879cc 961a8f0 168b5c0 d03c698 168b5c0 2267fac 18f3a11 0a78294 f9690b9 0a78294 f9690b9 0a78294 2267fac |
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 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from enum import Enum
from functools import lru_cache
import logging
import os
import platform
from pathlib import Path
import huggingface_hub
import sherpa
import sherpa_onnx
main_logger = logging.getLogger("main")
class EnumDecodingMethod(Enum):
greedy_search = "greedy_search"
modified_beam_search = "modified_beam_search"
model_map = {
"Chinese": [
{
"repo_id": "csukuangfj/wenet-chinese-model",
"nn_model_file": "final.zip",
"nn_model_file_sub_folder": ".",
"tokens_file": "units.txt",
"tokens_file_sub_folder": ".",
"normalize_samples": False,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "csukuangfj/sherpa-onnx-paraformer-zh-2024-03-09",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "csukuangfj/sherpa-onnx-paraformer-zh-small-2024-03-09",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "luomingshuang/icefall_asr_wenetspeech_pruned_transducer_stateless2",
"nn_model_file": "cpu_jit_epoch_10_avg_2_torch_1.7.1.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "zrjin/sherpa-onnx-zipformer-multi-zh-hans-2023-9-2",
"encoder_model_file": "encoder-epoch-20-avg-1.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "decoder-epoch-20-avg-1.onnx",
"decoder_model_file_sub_folder": ".",
"joiner_model_file": "joiner-epoch-20-avg-1.onnx",
"joiner_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "zrjin/icefall-asr-aishell-zipformer-large-2023-10-24",
"encoder_model_file": "encoder-epoch-56-avg-23.onnx",
"encoder_model_file_sub_folder": "exp",
"decoder_model_file": "decoder-epoch-56-avg-23.onnx",
"decoder_model_file_sub_folder": "exp",
"joiner_model_file": "joiner-epoch-56-avg-23.onnx",
"joiner_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "zrjin/icefall-asr-aishell-zipformer-small-2023-10-24",
"encoder_model_file": "encoder-epoch-55-avg-21.onnx",
"encoder_model_file_sub_folder": "exp",
"decoder_model_file": "decoder-epoch-55-avg-21.onnx",
"decoder_model_file_sub_folder": "exp",
"joiner_model_file": "joiner-epoch-55-avg-21.onnx",
"joiner_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "zrjin/icefall-asr-aishell-zipformer-2023-10-24",
"encoder_model_file": "encoder-epoch-55-avg-17.onnx",
"encoder_model_file_sub_folder": "exp",
"decoder_model_file": "decoder-epoch-55-avg-17.onnx",
"decoder_model_file_sub_folder": "exp",
"joiner_model_file": "joiner-epoch-55-avg-17.onnx",
"joiner_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "desh2608/icefall-asr-alimeeting-pruned-transducer-stateless7",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "yuekai/icefall-asr-aishell2-pruned-transducer-stateless5-A-2022-07-12",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "yuekai/icefall-asr-aishell2-pruned-transducer-stateless5-B-2022-07-12",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "luomingshuang/icefall_asr_aidatatang-200zh_pruned_transducer_stateless2",
"nn_model_file": "cpu_jit_torch.1.7.1.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "luomingshuang/icefall_asr_alimeeting_pruned_transducer_stateless2",
"nn_model_file": "cpu_jit_torch_1.7.1.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
],
"English": [
{
"repo_id": "csukuangfj/sherpa-onnx-whisper-tiny.en",
"encoder_model_file": "tiny.en-encoder.int8.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "tiny.en-decoder.int8.onnx",
"decoder_model_file_sub_folder": ".",
"tokens_file": "tiny.en-tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_whisper",
},
{
"repo_id": "csukuangfj/sherpa-onnx-whisper-base.en",
"encoder_model_file": "base.en-encoder.int8.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "base.en-decoder.int8.onnx",
"decoder_model_file_sub_folder": ".",
"tokens_file": "base.en-tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_whisper",
},
{
"repo_id": "csukuangfj/sherpa-onnx-whisper-small.en",
"encoder_model_file": "small.en-encoder.int8.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "small.en-decoder.int8.onnx",
"decoder_model_file_sub_folder": ".",
"tokens_file": "small.en-tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_whisper",
},
{
"repo_id": "csukuangfj/sherpa-onnx-paraformer-en-2024-03-09",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "yfyeung/icefall-asr-gigaspeech-zipformer-2023-10-17",
"encoder_model_file": "encoder-epoch-30-avg-9.onnx",
"encoder_model_file_sub_folder": "exp",
"decoder_model_file": "decoder-epoch-30-avg-9.onnx",
"decoder_model_file_sub_folder": "exp",
"joiner_model_file": "joiner-epoch-30-avg-9.onnx",
"joiner_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "wgb14/icefall-asr-gigaspeech-pruned-transducer-stateless2",
"nn_model_file": "cpu_jit-iter-3488000-avg-20.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "./giga-tokens.txt",
"tokens_file_sub_folder": ".",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "yfyeung/icefall-asr-multidataset-pruned_transducer_stateless7-2023-05-04",
"nn_model_file": "cpu_jit-epoch-30-avg-4.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "yfyeung/icefall-asr-finetune-mux-pruned_transducer_stateless7-2023-05-19",
"nn_model_file": "cpu_jit-epoch-20-avg-5.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "WeijiZhuang/icefall-asr-librispeech-pruned-transducer-stateless8-2022-12-02",
"nn_model_file": "cpu_jit-torch-1.10.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "csukuangfj/icefall-asr-librispeech-pruned-transducer-stateless8-2022-11-14",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "csukuangfj/icefall-asr-librispeech-pruned-transducer-stateless7-2022-11-11",
"nn_model_file": "cpu_jit-torch-1.10.0.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "csukuangfj/icefall-asr-librispeech-pruned-transducer-stateless3-2022-05-13",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "yujinqiu/sherpa-onnx-paraformer-en-2023-10-24",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "new_tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "Zengwei/icefall-asr-librispeech-zipformer-large-2023-05-16",
"nn_model_file": "jit_script.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "Zengwei/icefall-asr-librispeech-zipformer-2023-05-15",
"nn_model_file": "jit_script.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "Zengwei/icefall-asr-librispeech-zipformer-small-2023-05-16",
"nn_model_file": "jit_script.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "videodanchik/icefall-asr-tedlium3-conformer-ctc2",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "pkufool/icefall_asr_librispeech_conformer_ctc",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "WayneWiser/icefall-asr-librispeech-conformer-ctc2-jit-bpe-500-2022-07-21",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "csukuangfj/wenet-english-model",
"nn_model_file": "final.zip",
"nn_model_file_sub_folder": ".",
"tokens_file": "units.txt",
"tokens_file_sub_folder": ".",
"normalize_samples": False,
"loader": "load_sherpa_offline_recognizer",
},
],
"Chinese+English": [
{
"repo_id": "csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20",
"encoder_model_file": "encoder-epoch-99-avg-1.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "decoder-epoch-99-avg-1.onnx",
"decoder_model_file_sub_folder": ".",
"joiner_model_file": "joiner-epoch-99-avg-1.onnx",
"joiner_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_online_recognizer_from_transducer",
},
{
"repo_id": "csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "ptrnull/icefall-asr-conv-emformer-transducer-stateless2-zh",
"nn_model_file": "cpu_jit-epoch-11-avg-1.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char_bpe",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "luomingshuang/icefall_asr_tal-csasr_pruned_transducer_stateless5",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
],
"Chinese+English+Cantonese": [
{
"repo_id": "csukuangfj/sherpa-onnx-paraformer-trilingual-zh-cantonese-en",
"nn_model_file": "model.int8.onnx",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_offline_recognizer_from_paraformer",
},
{
"repo_id": "csukuangfj/sherpa-onnx-streaming-paraformer-trilingual-zh-cantonese-en",
"encoder_model_file": "encoder.int8.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "decoder.int8.onnx",
"decoder_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_online_recognizer_from_paraformer",
},
],
"Cantonese": [
{
"repo_id": "zrjin/icefall-asr-mdcc-zipformer-2024-03-11",
"encoder_model_file": "encoder-epoch-45-avg-35.int8.onnx",
"encoder_model_file_sub_folder": "exp",
"decoder_model_file": "decoder-epoch-45-avg-35.onnx",
"decoder_model_file_sub_folder": "exp",
"joiner_model_file": "joiner-epoch-45-avg-35.int8.onnx",
"joiner_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_char",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
],
# "Japanese": [
# {
# "repo_id": "TeoWenShen/icefall-asr-csj-pruned-transducer-stateless7-streaming-230208-fluent",
# "encoder_model_file": "encoder_jit_trace.pt",
# "encoder_model_file_sub_folder": "exp_fluent",
# "decoder_model_file": "decoder_jit_trace.pt",
# "decoder_model_file_sub_folder": "exp_fluent",
# "joiner_model_file": "joiner_jit_trace.pt",
# "joiner_model_file_sub_folder": "exp_fluent",
# "tokens_file": "tokens.txt",
# "tokens_file_sub_folder": "data/lang_char",
# "normalize_samples": True,
# "loader": "load_sherpa_online_recognizer",
# },
# {
# "repo_id": "TeoWenShen/icefall-asr-csj-pruned-transducer-stateless7-streaming-230208-disfluent",
# "encoder_model_file": "encoder_jit_trace.pt",
# "encoder_model_file_sub_folder": "exp_disfluent",
# "decoder_model_file": "decoder_jit_trace.pt",
# "decoder_model_file_sub_folder": "exp_disfluent",
# "joiner_model_file": "joiner_jit_trace.pt",
# "joiner_model_file_sub_folder": "exp_disfluent",
# "tokens_file": "tokens.txt",
# "tokens_file_sub_folder": "data/lang_char",
# "normalize_samples": True,
# "loader": "load_sherpa_online_recognizer",
# },
# ],
"German": [
{
"repo_id": "csukuangfj/wav2vec2.0-torchaudio",
"nn_model_file": "voxpopuli_asr_base_10k_de.pt",
"nn_model_file_sub_folder": ".",
"tokens_file": "tokens-de.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_offline_recognizer_without_feat_config",
},
],
"French": [
{
"repo_id": "shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14",
"encoder_model_file": "encoder-epoch-29-avg-9-with-averaged-model.onnx",
"encoder_model_file_sub_folder": ".",
"decoder_model_file": "decoder-epoch-29-avg-9-with-averaged-model.onnx",
"decoder_model_file_sub_folder": ".",
"joiner_model_file": "joiner-epoch-29-avg-9-with-averaged-model.onnx",
"joiner_model_file_sub_folder": ".",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": ".",
"loader": "load_sherpa_onnx_online_recognizer_from_transducer",
},
],
"Russian": [
{
"repo_id": "alphacep/vosk-model-ru",
"encoder_model_file": "encoder.onnx",
"encoder_model_file_sub_folder": "am-onnx",
"decoder_model_file": "decoder.onnx",
"decoder_model_file_sub_folder": "am-onnx",
"joiner_model_file": "joiner.onnx",
"joiner_model_file_sub_folder": "am-onnx",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "lang",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
{
"repo_id": "alphacep/vosk-model-small-ru",
"encoder_model_file": "encoder.onnx",
"encoder_model_file_sub_folder": "am",
"decoder_model_file": "decoder.onnx",
"decoder_model_file_sub_folder": "am",
"joiner_model_file": "joiner.onnx",
"joiner_model_file_sub_folder": "am",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "lang",
"loader": "load_sherpa_onnx_offline_recognizer_from_transducer",
},
],
"Arabic": [
{
"repo_id": "AmirHussein/icefall-asr-mgb2-conformer_ctc-2022-27-06",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_5000",
"loader": "load_sherpa_offline_recognizer_without_feat_config",
},
],
"Tibetan": [
{
"repo_id": "syzym/icefall-asr-xbmu-amdo31-pruned-transducer-stateless7-2022-12-02",
"nn_model_file": "cpu_jit.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
{
"repo_id": "syzym/icefall-asr-xbmu-amdo31-pruned-transducer-stateless5-2022-11-29",
"nn_model_file": "cpu_jit-epoch-28-avg-23-torch-1.10.0.pt",
"nn_model_file_sub_folder": "exp",
"tokens_file": "tokens.txt",
"tokens_file_sub_folder": "data/lang_bpe_500",
"normalize_samples": True,
"loader": "load_sherpa_offline_recognizer",
},
],
}
def download_model(local_model_dir: str,
**kwargs,
):
repo_id = kwargs["repo_id"]
if "nn_model_file" in kwargs.keys():
main_logger.info("download nn_model_file. filename: {}, subfolder: {}".format(kwargs["nn_model_file"], kwargs["nn_model_file_sub_folder"]))
_ = huggingface_hub.hf_hub_download(
repo_id=repo_id,
filename=kwargs["nn_model_file"],
subfolder=kwargs["nn_model_file_sub_folder"],
local_dir=local_model_dir,
)
if "encoder_model_file" in kwargs.keys():
main_logger.info("download encoder_model_file. filename: {}, subfolder: {}".format(kwargs["encoder_model_file"], kwargs["encoder_model_file_sub_folder"]))
_ = huggingface_hub.hf_hub_download(
repo_id=repo_id,
filename=kwargs["encoder_model_file"],
subfolder=kwargs["encoder_model_file_sub_folder"],
local_dir=local_model_dir,
)
if "decoder_model_file" in kwargs.keys():
main_logger.info("download decoder_model_file. filename: {}, subfolder: {}".format(kwargs["decoder_model_file"], kwargs["decoder_model_file_sub_folder"]))
_ = huggingface_hub.hf_hub_download(
repo_id=repo_id,
filename=kwargs["decoder_model_file"],
subfolder=kwargs["decoder_model_file_sub_folder"],
local_dir=local_model_dir,
)
if "joiner_model_file" in kwargs.keys():
main_logger.info("download joiner_model_file. filename: {}, subfolder: {}".format(kwargs["joiner_model_file"], kwargs["joiner_model_file_sub_folder"]))
_ = huggingface_hub.hf_hub_download(
repo_id=repo_id,
filename=kwargs["joiner_model_file"],
subfolder=kwargs["joiner_model_file_sub_folder"],
local_dir=local_model_dir,
)
if "tokens_file" in kwargs.keys():
main_logger.info("download tokens_file. filename: {}, subfolder: {}".format(kwargs["tokens_file"], kwargs["tokens_file_sub_folder"]))
tokens_file = kwargs["tokens_file"]
if not tokens_file.startswith("./"):
_ = huggingface_hub.hf_hub_download(
repo_id=repo_id,
filename=kwargs["tokens_file"],
subfolder=kwargs["tokens_file_sub_folder"],
local_dir=local_model_dir,
)
def load_sherpa_offline_recognizer(nn_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
num_active_paths: int = 2,
decoding_method: str = "greedy_search",
num_mel_bins: int = 80,
frame_dither: int = 0,
normalize_samples: bool = False,
):
feat_config = sherpa.FeatureConfig(normalize_samples=normalize_samples)
feat_config.fbank_opts.frame_opts.samp_freq = sample_rate
feat_config.fbank_opts.mel_opts.num_bins = num_mel_bins
feat_config.fbank_opts.frame_opts.dither = frame_dither
if not os.path.exists(nn_model_file):
raise AssertionError("nn_model_file not found. nn_model_file: {}".format(nn_model_file))
config = sherpa.OfflineRecognizerConfig(
nn_model=nn_model_file,
tokens=tokens_file,
use_gpu=False,
feat_config=feat_config,
decoding_method=decoding_method,
num_active_paths=num_active_paths,
)
recognizer = sherpa.OfflineRecognizer(config)
return recognizer
def load_sherpa_offline_recognizer_without_feat_config(nn_model_file: str,
tokens_file: str,
num_active_paths: int = 2,
decoding_method: str = "greedy_search",
):
config = sherpa.OfflineRecognizerConfig(
nn_model=nn_model_file,
tokens=tokens_file,
use_gpu=False,
decoding_method=decoding_method,
num_active_paths=num_active_paths,
)
recognizer = sherpa.OfflineRecognizer(config)
return recognizer
def load_sherpa_onnx_offline_recognizer_from_paraformer(nn_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
decoding_method: str = "greedy_search",
feature_dim: int = 80,
num_threads: int = 2,
):
recognizer = sherpa_onnx.OfflineRecognizer.from_paraformer(
paraformer=nn_model_file,
tokens=tokens_file,
num_threads=num_threads,
sample_rate=sample_rate,
feature_dim=feature_dim,
decoding_method=decoding_method,
debug=False,
)
return recognizer
def load_sherpa_onnx_offline_recognizer_from_transducer(encoder_model_file: str,
decoder_model_file: str,
joiner_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
decoding_method: str = "greedy_search",
feature_dim: int = 80,
num_threads: int = 2,
num_active_paths: int = 2,
):
recognizer = sherpa_onnx.OfflineRecognizer.from_transducer(
encoder=encoder_model_file,
decoder=decoder_model_file,
joiner=joiner_model_file,
tokens=tokens_file,
num_threads=num_threads,
sample_rate=sample_rate,
feature_dim=feature_dim,
decoding_method=decoding_method,
max_active_paths=num_active_paths,
)
return recognizer
def load_sherpa_onnx_offline_recognizer_from_whisper(encoder_model_file: str,
decoder_model_file: str,
tokens_file: str,
num_threads: int = 2,
):
recognizer = sherpa_onnx.OfflineRecognizer.from_whisper(
encoder=encoder_model_file,
decoder=decoder_model_file,
tokens=tokens_file,
num_threads=num_threads,
)
return recognizer
def load_sherpa_online_recognizer(nn_model_file: str,
encoder_model_file: str,
decoder_model_file: str,
joiner_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
num_active_paths: int = 2,
decoding_method: str = "greedy_search",
num_mel_bins: int = 80,
frame_dither: int = 0,
normalize_samples: bool = False,
):
feat_config = sherpa.FeatureConfig(normalize_samples=normalize_samples)
feat_config.fbank_opts.frame_opts.samp_freq = sample_rate
feat_config.fbank_opts.mel_opts.num_bins = num_mel_bins
feat_config.fbank_opts.frame_opts.dither = frame_dither
if not os.path.exists(nn_model_file):
raise AssertionError("nn_model_file not found. nn_model_file: {}".format(nn_model_file))
config = sherpa.OfflineRecognizerConfig(
nn_model=nn_model_file,
encoder_model=encoder_model_file,
decoder_model=decoder_model_file,
joiner_model=joiner_model_file,
tokens=tokens_file,
use_gpu=False,
feat_config=feat_config,
decoding_method=decoding_method,
num_active_paths=num_active_paths,
chunk_size=32,
)
recognizer = sherpa.OnlineRecognizer(config)
return recognizer
def load_sherpa_onnx_online_recognizer_from_transducer(encoder_model_file: str,
decoder_model_file: str,
joiner_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
decoding_method: str = "greedy_search",
feature_dim: int = 80,
num_threads: int = 2,
num_active_paths: int = 2,
):
recognizer = sherpa_onnx.OnlineRecognizer.from_transducer(
encoder=encoder_model_file,
decoder=decoder_model_file,
joiner=joiner_model_file,
tokens=tokens_file,
num_threads=num_threads,
sample_rate=sample_rate,
feature_dim=feature_dim,
decoding_method=decoding_method,
max_active_paths=num_active_paths,
)
return recognizer
def load_sherpa_onnx_online_recognizer_from_paraformer(encoder_model_file: str,
decoder_model_file: str,
tokens_file: str,
sample_rate: int = 16000,
decoding_method: str = "greedy_search",
feature_dim: int = 80,
num_threads: int = 2,
):
recognizer = sherpa_onnx.OnlineRecognizer.from_paraformer(
encoder=encoder_model_file,
decoder=decoder_model_file,
tokens=tokens_file,
num_threads=num_threads,
sample_rate=sample_rate,
feature_dim=feature_dim,
decoding_method=decoding_method,
)
return recognizer
@lru_cache(maxsize=15)
def load_recognizer(local_model_dir: Path,
decoding_method: str = "greedy_search",
num_active_paths: int = 4,
**kwargs,
):
if not local_model_dir.exists():
download_model(
local_model_dir=local_model_dir.as_posix(),
**kwargs,
)
loader = kwargs["loader"]
kwargs_ = dict()
if "nn_model_file" in kwargs.keys():
nn_model_file = (local_model_dir / kwargs["nn_model_file_sub_folder"] / kwargs["nn_model_file"]).as_posix()
kwargs_["nn_model_file"] = nn_model_file
if "encoder_model_file" in kwargs.keys():
encoder_model_file = (local_model_dir / kwargs["encoder_model_file_sub_folder"] / kwargs["encoder_model_file"]).as_posix()
kwargs_["encoder_model_file"] = encoder_model_file
if "decoder_model_file" in kwargs.keys():
decoder_model_file = (local_model_dir / kwargs["decoder_model_file_sub_folder"] / kwargs["decoder_model_file"]).as_posix()
kwargs_["decoder_model_file"] = decoder_model_file
if "joiner_model_file" in kwargs.keys():
joiner_model_file = (local_model_dir / kwargs["joiner_model_file_sub_folder"] / kwargs["joiner_model_file"]).as_posix()
kwargs_["joiner_model_file"] = joiner_model_file
if "tokens_file" in kwargs.keys():
tokens_file: str = kwargs["tokens_file"]
if not tokens_file.startswith("./"):
tokens_file = (local_model_dir / kwargs["tokens_file_sub_folder"] / kwargs["tokens_file"]).as_posix()
kwargs_["tokens_file"] = tokens_file
if "normalize_samples" in kwargs.keys():
kwargs_["normalize_samples"] = kwargs["normalize_samples"]
if loader == "load_sherpa_offline_recognizer":
recognizer = load_sherpa_offline_recognizer(
decoding_method=decoding_method,
num_active_paths=num_active_paths,
**kwargs_
)
elif loader == "load_sherpa_offline_recognizer_without_feat_config":
recognizer = load_sherpa_offline_recognizer_without_feat_config(
decoding_method=decoding_method,
**kwargs_
)
elif loader == "load_sherpa_onnx_offline_recognizer_from_paraformer":
recognizer = load_sherpa_onnx_offline_recognizer_from_paraformer(
decoding_method=decoding_method,
**kwargs_
)
elif loader == "load_sherpa_onnx_offline_recognizer_from_transducer":
recognizer = load_sherpa_onnx_offline_recognizer_from_transducer(
decoding_method=decoding_method,
**kwargs_
)
elif loader == "load_sherpa_onnx_offline_recognizer_from_whisper":
recognizer = load_sherpa_onnx_offline_recognizer_from_whisper(
**kwargs_
)
elif loader == "load_sherpa_online_recognizer":
recognizer = load_sherpa_online_recognizer(
decoding_method=decoding_method,
num_active_paths=num_active_paths,
**kwargs_
)
elif loader == "load_sherpa_onnx_online_recognizer_from_transducer":
recognizer = load_sherpa_onnx_online_recognizer_from_transducer(
**kwargs_
)
elif loader == "load_sherpa_onnx_online_recognizer_from_paraformer":
recognizer = load_sherpa_onnx_online_recognizer_from_paraformer(
**kwargs_
)
else:
raise NotImplementedError("loader not support: {}".format(loader))
return recognizer
@lru_cache(maxsize=15)
def load_punctuation_model(local_model_dir: Path,
repo_id: str,
nn_model_file: str,
nn_model_file_sub_folder: str,
):
if not local_model_dir.exists():
download_model(
local_model_dir=local_model_dir.as_posix(),
repo_id=repo_id,
nn_model_file=nn_model_file,
nn_model_file_sub_folder=nn_model_file_sub_folder,
)
nn_model_file = (local_model_dir / nn_model_file_sub_folder / nn_model_file).as_posix()
config = sherpa_onnx.OfflinePunctuationConfig(
model=sherpa_onnx.OfflinePunctuationModelConfig(
ct_transformer=nn_model_file
),
)
punctuation_model = sherpa_onnx.OfflinePunctuation(config)
return punctuation_model
if __name__ == "__main__":
pass
|