|
2 | 2 |
|
3 | 3 | import itertools as it
|
4 | 4 |
|
5 |
| -import warnings |
6 | 5 | from abc import abstractmethod
|
7 | 6 | from collections import namedtuple
|
8 | 7 | from typing import Dict, List, NamedTuple, Optional, Tuple, Union
|
9 | 8 |
|
10 | 9 | import torch
|
11 |
| -import torchaudio |
12 |
| -from torchaudio.utils import download_asset |
13 |
| - |
14 | 10 |
|
15 |
| -# We prioritize the version from upstream flashlight here. |
16 |
| -# This will allow applications that use the upstream flashlight |
17 |
| -# alongside torchaudio. |
18 |
| -if torchaudio._internal.module_utils.is_module_available("flashlight"): |
19 |
| - from flashlight.lib.text.decoder import ( |
20 |
| - CriterionType as _CriterionType, |
21 |
| - LexiconDecoder as _LexiconDecoder, |
22 |
| - LexiconDecoderOptions as _LexiconDecoderOptions, |
23 |
| - LexiconFreeDecoder as _LexiconFreeDecoder, |
24 |
| - LexiconFreeDecoderOptions as _LexiconFreeDecoderOptions, |
25 |
| - LM as _LM, |
26 |
| - LMState as _LMState, |
27 |
| - SmearingMode as _SmearingMode, |
28 |
| - Trie as _Trie, |
29 |
| - ZeroLM as _ZeroLM, |
30 |
| - ) |
31 |
| - from flashlight.lib.text.dictionary import ( |
32 |
| - create_word_dict as _create_word_dict, |
33 |
| - Dictionary as _Dictionary, |
34 |
| - load_words as _load_words, |
35 |
| - ) |
| 11 | +from flashlight.lib.text.decoder import ( |
| 12 | + CriterionType as _CriterionType, |
| 13 | + LexiconDecoder as _LexiconDecoder, |
| 14 | + LexiconDecoderOptions as _LexiconDecoderOptions, |
| 15 | + LexiconFreeDecoder as _LexiconFreeDecoder, |
| 16 | + LexiconFreeDecoderOptions as _LexiconFreeDecoderOptions, |
| 17 | + LM as _LM, |
| 18 | + LMState as _LMState, |
| 19 | + SmearingMode as _SmearingMode, |
| 20 | + Trie as _Trie, |
| 21 | + ZeroLM as _ZeroLM, |
| 22 | +) |
| 23 | +from flashlight.lib.text.dictionary import ( |
| 24 | + create_word_dict as _create_word_dict, |
| 25 | + Dictionary as _Dictionary, |
| 26 | + load_words as _load_words, |
| 27 | +) |
| 28 | +from torchaudio.utils import download_asset |
36 | 29 |
|
| 30 | +try: |
| 31 | + from flashlight.lib.text.decoder.kenlm import KenLM as _KenLM |
| 32 | +except Exception: |
37 | 33 | try:
|
38 | 34 | from flashlight.lib.text.decoder import KenLM as _KenLM
|
39 | 35 | except Exception:
|
40 | 36 | _KenLM = None
|
41 |
| -else: |
42 |
| - torchaudio._extension._load_lib("libflashlight-text") |
43 |
| - from torchaudio.lib.flashlight_lib_text_decoder import ( |
44 |
| - CriterionType as _CriterionType, |
45 |
| - KenLM as _KenLM, |
46 |
| - LexiconDecoder as _LexiconDecoder, |
47 |
| - LexiconDecoderOptions as _LexiconDecoderOptions, |
48 |
| - LexiconFreeDecoder as _LexiconFreeDecoder, |
49 |
| - LexiconFreeDecoderOptions as _LexiconFreeDecoderOptions, |
50 |
| - LM as _LM, |
51 |
| - LMState as _LMState, |
52 |
| - SmearingMode as _SmearingMode, |
53 |
| - Trie as _Trie, |
54 |
| - ZeroLM as _ZeroLM, |
55 |
| - ) |
56 |
| - from torchaudio.lib.flashlight_lib_text_dictionary import ( |
57 |
| - create_word_dict as _create_word_dict, |
58 |
| - Dictionary as _Dictionary, |
59 |
| - load_words as _load_words, |
60 |
| - ) |
61 |
| - |
62 |
| - warnings.warn( |
63 |
| - "The built-in flashlight integration is deprecated, and will be removed in future release. " |
64 |
| - "Please install flashlight-text. https://pypi.org/project/flashlight-text/ " |
65 |
| - "For the detail of CTC decoder migration, please see https://github.com/pytorch/audio/issues/3088." |
66 |
| - ) |
67 |
| - |
68 | 37 |
|
69 | 38 | __all__ = [
|
70 | 39 | "CTCHypothesis",
|
@@ -450,7 +419,10 @@ def ctc_decoder(
|
450 | 419 |
|
451 | 420 | if type(lm) == str:
|
452 | 421 | if _KenLM is None:
|
453 |
| - raise RuntimeError("flashlight is installed, but KenLM is not installed. Please install KenLM.") |
| 422 | + raise RuntimeError( |
| 423 | + "flashlight-text is installed, but KenLM is not installed. " |
| 424 | + "Please refer to https://github.com/kpu/kenlm#python-module for how to install it." |
| 425 | + ) |
454 | 426 | lm = _KenLM(lm, word_dict)
|
455 | 427 | elif lm is None:
|
456 | 428 | lm = _ZeroLM()
|
|
0 commit comments