Skip to content

Commit

Permalink
fix asr import
Browse files Browse the repository at this point in the history
  • Loading branch information
abdeladim-s committed Jun 2, 2023
1 parent 3006094 commit 4bb07cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions easymms/models/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
from pathlib import Path
from typing import List
import torch
# fix importing from fairseq.examples
# import site
# sys.path.append(str(Path(site.getsitepackages()[0]) / 'fairseq'))
# try:
# from fairseq.examples.mms.data_prep.align_and_segment import get_alignments
# from fairseq.examples.mms.data_prep.align_utils import get_uroman_tokens, get_spans
# from fairseq.examples.mms.data_prep.text_normalization import text_normalize
# except ImportError:
# from examples.mms.data_prep.align_and_segment import get_alignments
# from examples.mms.data_prep.align_utils import get_uroman_tokens, get_spans
# from examples.mms.data_prep.text_normalization import text_normalize

from easymms import utils
from easymms._logger import set_log_level
Expand Down
16 changes: 14 additions & 2 deletions easymms/models/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
from pydub import AudioSegment
from pydub.utils import mediainfo

# fix importing from fairseq.examples
# import site
# sys.path.append(str(Path(site.getsitepackages()[0]) / 'fairseq'))
# try:
# from fairseq.examples.speech_recognition.new.infer import hydra_main
# except ImportError:
# from examples.speech_recognition.new.infer import hydra_main


from easymms import utils as easymms_utils
from easymms._logger import set_log_level
Expand Down Expand Up @@ -142,12 +150,16 @@ def transcribe(self,
:return: List of transcription text in the same order as input files
"""
processed_files = self._prepare_media_files(media_files)
# import
cwd = os.getcwd()
os.chdir(constants.FAIRSEQ_DIR)
from examples.speech_recognition.new.infer import hydra_main
import site
fairseq_path = str((Path(site.getsitepackages()[0]) / 'fairseq').resolve())
sys.path.append(fairseq_path)
os.chdir(fairseq_path)

processed_files = self._prepare_media_files(media_files)
self._setup_tmp_dir(processed_files)
# edit cfg
if cfg is None:
Expand Down Expand Up @@ -186,8 +198,8 @@ def transcribe(self,
res.append(segments)
else:
res = transcripts

os.chdir(cwd)

return res

@staticmethod
Expand Down

0 comments on commit 4bb07cc

Please sign in to comment.