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

[audio_zen, recipes] keep directory structure #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions audio_zen/inferencer/base_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __call__(self):

inference_args = self.inference_config["args"]

for noisy, name in tqdm(self.dataloader, desc="Inference"):
for noisy, name, noisy_file_path, dataset_dir in tqdm(self.dataloader, desc="Inference"):
assert len(name) == 1, "The batch size of inference stage must 1."
name = name[0]

Expand All @@ -140,4 +140,11 @@ def __call__(self):

# clnsp102_traffic_248091_3_snr0_tl-21_fileid_268 => clean_fileid_0
# name = "clean_" + "_".join(name.split("_")[-2:])
sf.write(self.enhanced_dir / f"{name}.wav", enhanced, samplerate=self.acoustic_config["sr"])
if dataset_dir is not None:
noisy_file_path = noisy_file_path[0]
dataset_dir = dataset_dir[0]
out_path = Path(str(noisy_file_path).replace(str(dataset_dir), str(self.enhanced_dir)))
prepare_empty_dir([out_path.parents[0]])
sf.write(out_path, enhanced, samplerate=self.acoustic_config["sr"])
else:
sf.write(self.enhanced_dir / f"{name}.wav", enhanced, samplerate=self.acoustic_config["sr"])
5 changes: 4 additions & 1 deletion recipes/dns_interspeech_2020/dataset_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self,
dataset_dir = Path(dataset_dir).expanduser().absolute()
noisy_file_path_list += librosa.util.find_files(dataset_dir.as_posix()) # Sorted

self.dataset_dir = None
if len(dataset_dir_list) == 1:
self.dataset_dir = dataset_dir_list[0]
self.noisy_file_path_list = noisy_file_path_list
self.length = len(self.noisy_file_path_list)

Expand All @@ -36,4 +39,4 @@ def __getitem__(self, item):
noisy_y = librosa.load(noisy_file_path, sr=self.sr)[0]
noisy_y = noisy_y.astype(np.float32)

return noisy_y, basename(noisy_file_path)[0]
return noisy_y, basename(noisy_file_path)[0], noisy_file_path, self.dataset_dir