Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUN pip install --no-cache-dir \
espnet_tts_frontend \
graphviz \
kaldi-decoder \
kaldi_native_fbank \
kaldi_native_io \
kaldialign \
kaldifst \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
cd ../transducer_lstm
pytest -v -s

pip install kaldi_native_fbank
cd ../zipformer
pytest -v -s

Expand Down
2 changes: 1 addition & 1 deletion egs/iwslt22_ta/ASR/local/prepare_transcripts.py
132 changes: 66 additions & 66 deletions egs/iwslt22_ta/ST/local/prepare_transcripts.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
# Copyright 2023 Johns Hopkins University (Amir Hussein)
#!/usr/bin/python
"""
This script prepares transcript_words.txt from cutset
"""
from lhotse import CutSet
import argparse
import logging
import pdb
from pathlib import Path
import os
def get_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--cut",
type=str,
default="",
help="Cutset file",
)
parser.add_argument(
"--src-langdir",
type=str,
default="",
help="name of the source lang-dir",
)
parser.add_argument(
"--tgt-langdir",
type=str,
default=None,
help="name of the target lang-dir",
)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
logging.info("Reading the cuts")
cuts = CutSet.from_file(args.cut)
if args.tgt_langdir != None:
logging.info("Target dir is not None")
langdirs = [Path(args.src_langdir), Path(args.tgt_langdir)]
else:
langdirs = [Path(args.src_langdir)]
for langdir in langdirs:
if not os.path.exists(langdir):
os.makedirs(langdir)
with open(langdirs[0] / "transcript_words.txt", 'w') as src, open(langdirs[1] / "transcript_words.txt", 'w') as tgt:
for c in cuts:
src_txt = c.supervisions[0].text
tgt_txt = c.supervisions[0].custom['translated_text']['eng']
src.write(src_txt + '\n')
tgt.write(tgt_txt + '\n')
if __name__ == "__main__":
main()
# Copyright 2023 Johns Hopkins University (Amir Hussein)

#!/usr/bin/python
Comment on lines +1 to +3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Shebang should be at the beginning of the file.

The shebang (#!/usr/bin/python) on line 3 should come before the copyright comment on line 1 to be recognized by the shell.

Proposed fix
+#!/usr/bin/python
 # Copyright 2023 Johns Hopkins University  (Amir Hussein)
-
-#!/usr/bin/python
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Copyright 2023 Johns Hopkins University (Amir Hussein)
#!/usr/bin/python
#!/usr/bin/python
# Copyright 2023 Johns Hopkins University (Amir Hussein)
🧰 Tools
🪛 Ruff (0.14.13)

3-3: Shebang should be at the beginning of the file

(EXE005)

🤖 Prompt for AI Agents
In `@egs/iwslt22_ta/ST/local/prepare_transcripts.py` around lines 1 - 3, Move the
shebang line (#!/usr/bin/python) to the very top of the file with no preceding
bytes or comments so the shell can recognize it; place the copyright/comment
lines (e.g., "Copyright 2023 Johns Hopkins University  (Amir Hussein)")
immediately after the shebang and ensure there are no blank lines or other
characters before the shebang.

"""
This script prepares transcript_words.txt from cutset
"""

from lhotse import CutSet
import argparse
import logging
import pdb
from pathlib import Path
import os


def get_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--cut",
type=str,
default="",
help="Cutset file",
)
parser.add_argument(
"--src-langdir",
type=str,
default="",
help="name of the source lang-dir",
)
parser.add_argument(
"--tgt-langdir",
type=str,
default=None,
help="name of the target lang-dir",
)
return parser


def main():

parser = get_parser()
args = parser.parse_args()

logging.info("Reading the cuts")
cuts = CutSet.from_file(args.cut)
if args.tgt_langdir != None:
logging.info("Target dir is not None")
langdirs = [Path(args.src_langdir), Path(args.tgt_langdir)]
else:
langdirs = [Path(args.src_langdir)]

for langdir in langdirs:
if not os.path.exists(langdir):
os.makedirs(langdir)

with open(langdirs[0] / "transcript_words.txt", 'w') as src, open(langdirs[1] / "transcript_words.txt", 'w') as tgt:
for c in cuts:
src_txt = c.supervisions[0].text
tgt_txt = c.supervisions[0].custom['translated_text']['eng']
src.write(src_txt + '\n')
tgt.write(tgt_txt + '\n')
Comment on lines +51 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

IndexError when tgt_langdir is None.

When args.tgt_langdir is None, langdirs contains only one element (line 52), but line 58 unconditionally accesses langdirs[1], causing an IndexError.

Proposed fix: handle single langdir case
-    with open(langdirs[0] / "transcript_words.txt", 'w') as src, open(langdirs[1] / "transcript_words.txt", 'w') as tgt:
-        for c in cuts:
-            src_txt = c.supervisions[0].text
-            tgt_txt = c.supervisions[0].custom['translated_text']['eng']
-            src.write(src_txt + '\n')
-            tgt.write(tgt_txt + '\n')
+    if args.tgt_langdir is not None:
+        with open(langdirs[0] / "transcript_words.txt", 'w') as src, \
+             open(langdirs[1] / "transcript_words.txt", 'w') as tgt:
+            for c in cuts:
+                src_txt = c.supervisions[0].text
+                tgt_txt = c.supervisions[0].custom['translated_text']['eng']
+                src.write(src_txt + '\n')
+                tgt.write(tgt_txt + '\n')
+    else:
+        with open(langdirs[0] / "transcript_words.txt", 'w') as src:
+            for c in cuts:
+                src_txt = c.supervisions[0].text
+                src.write(src_txt + '\n')
🤖 Prompt for AI Agents
In `@egs/iwslt22_ta/ST/local/prepare_transcripts.py` around lines 51 - 63, The
code builds langdirs from args.src_langdir and optionally args.tgt_langdir but
then always accesses langdirs[1], causing an IndexError when args.tgt_langdir is
None; update the block that opens transcript files to handle the single-langdir
case: if len(langdirs) == 1, open only langdirs[0] / "transcript_words.txt" and
write only src_txt for each cut (using c.supervisions[0].text), otherwise open
both langdirs[0] and langdirs[1] and write src_txt and tgt_txt
(c.supervisions[0].custom['translated_text']['eng']) respectively. Ensure you
reference the same variables (langdirs, cuts, src_txt, tgt_txt,
args.tgt_langdir) so the change integrates cleanly.


if __name__ == "__main__":
main()
Loading