Skip to content

Commit

Permalink
[Fix] Relative Audio Paths (NVIDIA#4470)
Browse files Browse the repository at this point in the history
* update

Signed-off-by: stevehuang52 <[email protected]>

* update

Signed-off-by: stevehuang52 <[email protected]>

* fix typo

Signed-off-by: stevehuang52 <[email protected]>
Signed-off-by: Hainan Xu <[email protected]>
  • Loading branch information
stevehuang52 authored and Hainan Xu committed Nov 29, 2022
1 parent 04776e4 commit 5da9ad7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions nemo/collections/common/parts/preprocessing/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ def __parse_item(line: str, manifest_file: str) -> Dict[str, Any]:
f"Manifest file {manifest_file} has invalid json line structure: {line} without proper audio file key."
)

# If the audio path is relative, and not using tarred dataset,
# attach the parent directory of manifest to the audio path.
# Assume "audio_file" starts with a dir, such as "wavs/xxxxx.wav".
# If using a tarred dataset, the "audio_path" is like "_home_data_tarred_wavs_xxxx.wav",
# so we will just ignore it.
# If the audio path is a relative path and does not exist,
# try to attach the parent directory of manifest to the audio path.
# Revert to the original path if the new path still doesn't exist.
# Assume that the audio path is like "wavs/xxxxxx.wav".
manifest_dir = Path(manifest_file).parent
audio_file = Path(item['audio_file'])
if not audio_file.is_file() and not audio_file.is_absolute() and audio_file.parent != Path("."):
# assume the wavs/ dir and manifest are under the same parent dir
if not audio_file.is_file() and not audio_file.is_absolute():
# assume the "wavs/" dir and manifest are under the same parent dir
audio_file = manifest_dir / audio_file
item['audio_file'] = str(audio_file.absolute())
if audio_file.is_file():
item['audio_file'] = str(audio_file.absolute())
else:
item['audio_file'] = expanduser(item['audio_file'])
else:
item['audio_file'] = expanduser(item['audio_file'])

Expand Down

0 comments on commit 5da9ad7

Please sign in to comment.