|
7 | 7 |
|
8 | 8 |
|
9 | 9 | class ASR: |
10 | | - def __init__(self, model: str="airesearch/wav2vec2-large-xlsr-53-th", lm=False, device=None) -> None: |
| 10 | + def __init__(self, model: str="airesearch/wav2vec2-large-xlsr-53-th", lm: bool=False, device: str=None) -> None: |
11 | 11 | """ |
12 | 12 | :param str model: The ASR model name |
13 | 13 | :param bool lm: Use language model (default is False and except *airesearch/wav2vec2-large-xlsr-53-th* model) |
@@ -74,21 +74,23 @@ def __call__(self, file: str) -> str: |
74 | 74 | _model = None |
75 | 75 |
|
76 | 76 |
|
77 | | -def asr(file: str, model: str = _model_name) -> str: |
| 77 | +def asr(file: str, model: str = _model_name, lm: bool=False, device: str=None) -> str: |
78 | 78 | """ |
79 | 79 | :param str file: path of sound file |
80 | | - :param str model: The ASR model |
| 80 | + :param str model: The ASR model name |
| 81 | + :param bool lm: Use language model (except *airesearch/wav2vec2-large-xlsr-53-th* model) |
| 82 | + :param str device: device |
81 | 83 | :return: thai text from ASR |
82 | 84 | :rtype: str |
83 | 85 |
|
84 | 86 | **Options for model** |
85 | 87 | * *airesearch/wav2vec2-large-xlsr-53-th* (default) - AI RESEARCH - PyThaiNLP model |
86 | | - * *wannaphong/wav2vec2-large-xlsr-53-th-cv8-newmm* - Thai Wav2Vec2 with CommonVoice V8 (newmm tokenizer) + language model |
87 | | - * *wannaphong/wav2vec2-large-xlsr-53-th-cv8-deepcut* - Thai Wav2Vec2 with CommonVoice V8 (deepcut tokenizer) + language model |
| 88 | + * *wannaphong/wav2vec2-large-xlsr-53-th-cv8-newmm* - Thai Wav2Vec2 with CommonVoice V8 (newmm tokenizer) (+ language model) |
| 89 | + * *wannaphong/wav2vec2-large-xlsr-53-th-cv8-deepcut* - Thai Wav2Vec2 with CommonVoice V8 (deepcut tokenizer) (+ language model) |
88 | 90 | """ |
89 | 91 | global _model, _model_name |
90 | 92 | if model!=_model or _model == None: |
91 | | - _model = ASR(model) |
| 93 | + _model = ASR(model, lm=lm, device=device) |
92 | 94 | _model_name = model |
93 | 95 |
|
94 | 96 | return _model(file=file) |
0 commit comments