File size: 2,420 Bytes
6b31279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09d9587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright      2022  Xiaomi Corp.        (authors: Fangjun Kuang)
#
# See LICENSE for clarification regarding multiple authors
#
# 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.

from huggingface_hub import hf_hub_download
from functools import lru_cache


from offline_asr import OfflineAsr

sample_rate = 16000


@lru_cache(maxsize=1)
def get_gigaspeech_pre_trained_model():
    nn_model_filename = hf_hub_download(
        # It is converted from https://huggingface.co/wgb14/icefall-asr-gigaspeech-pruned-transducer-stateless2
        repo_id="csukuangfj/icefall-asr-gigaspeech-pruned-transducer-stateless2",
        filename="cpu_jit-epoch-29-avg-11-torch-1.10.0.pt",
        subfolder="exp",
    )

    bpe_model_filename = hf_hub_download(
        repo_id="wgb14/icefall-asr-gigaspeech-pruned-transducer-stateless2",
        filename="bpe.model",
        subfolder="data/lang_bpe_500",
    )

    return OfflineAsr(
        nn_model_filename=nn_model_filename,
        bpe_model_filename=bpe_model_filename,
        token_filename=None,
        decoding_method="greedy_search",
        num_active_paths=4,
        sample_rate=sample_rate,
        device="cpu",
    )


@lru_cache(maxsize=1)
def get_wenetspeech_pre_trained_model():
    nn_model_filename = hf_hub_download(
        repo_id="luomingshuang/icefall_asr_wenetspeech_pruned_transducer_stateless2",
        filename="cpu_jit_epoch_10_avg_2_torch_1.7.1.pt",
        subfolder="exp",
    )

    token_filename = hf_hub_download(
        repo_id="luomingshuang/icefall_asr_wenetspeech_pruned_transducer_stateless2",
        filename="tokens.txt",
        subfolder="data/lang_char",
    )

    return OfflineAsr(
        nn_model_filename=nn_model_filename,
        bpe_model_filename=None,
        token_filename=token_filename,
        decoding_method="greedy_search",
        num_active_paths=4,
        sample_rate=sample_rate,
        device="cpu",
    )