Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mgb2.py #725

Merged
merged 5 commits into from
Jun 4, 2022
Merged

Update mgb2.py #725

merged 5 commits into from
Jun 4, 2022

Conversation

AmirHussein96
Copy link
Contributor

extra new line causes error with load_kaldi_data_dir()

extra new line causes error with load_kaldi_data_dir()
@csukuangfj
Copy link
Contributor

Should load_kaldi_data_dir() skip empty lines?

@AmirHussein96
Copy link
Contributor Author

Should load_kaldi_data_dir() skip empty lines?

Yes, I think so. The way it works now is that It assumes that each line in the wav will be split into list of two items [id, text]. The additional empty line adds third item and causes an error. One can also fix this issue from the load_kaldi_data_dir() by skipping/removing the empty lines.

Fixing unicode string
Copy link
Collaborator

@pzelasko pzelasko left a comment

Choose a reason for hiding this comment

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

Why don’t we fix Kaldi utilities to skip empty lines instead?

@@ -130,7 +130,7 @@ def prepare_mgb2(
) as f_out:
for line in f_in:
f_out.write(line.replace("wav/", f"{corpus_dir}/{part}/wav/"))
f_out.write("\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn’t the script write everything to a single line after this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lines read from the wav.scp file already contain a new line, so the additional "\n" adds empty line. However I agree that it will be cleaner to just filter out the empty lines from any files that is being read from kaldi folder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As Dan pointed out, Kaldi doesn’t allow empty lines, so let’s strive to produce correct outputs. Please fix style issues and LGTM.

Copy link
Contributor Author

@AmirHussein96 AmirHussein96 May 29, 2022

Choose a reason for hiding this comment

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

The empty line was coming from the line f_out.write("\n") which I removed now. I tested it and now it works perfectly with load_kaldi_data_dir().

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool. Please fix black issues and LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@danpovey
Copy link
Collaborator

Should load_kaldi_data_dir() skip empty lines?

Kaldi data dirs have a well defined format that does not allow empty lines.

@pzelasko pzelasko merged commit 4198446 into lhotse-speech:master Jun 4, 2022
@pzelasko
Copy link
Collaborator

pzelasko commented Jun 4, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants