def enhance_session(self, session_ids, audio_dir, dataset_slice=False, audio_dir_exist_ok=False): """ Args: session_ids: audio_dir: dataset_slice: audio_dir_exist_ok: When True: It is ok, when the audio dir exists and the files insinde may be overwritten. Returns: >>> enhancer = get_enhancer(wpe=False, bss_iterations=2) >>> for x_hat in enhancer.enhance_session('S02'): ... print(x_hat) """ ensure_single_thread_numeric() audio_dir = Path(audio_dir) it = self.get_iterator(session_ids) if dlp_mpi.IS_MASTER: audio_dir.mkdir(exist_ok=audio_dir_exist_ok) for dataset in set(mapping.session_to_dataset.values()): (audio_dir / dataset).mkdir(exist_ok=audio_dir_exist_ok) dlp_mpi.barrier() if dataset_slice is not False: if dataset_slice is True: it = it[:2] elif isinstance(dataset_slice, int): it = it[:dataset_slice] elif isinstance(dataset_slice, slice): it = it[dataset_slice] else: raise ValueError(dataset_slice) for ex in dlp_mpi.split_managed(it, allow_single_worker=True): x_hat = self.enhance_example(ex) example_id = ex["example_id"] session_id = ex["session_id"] dataset = mapping.session_to_dataset[session_id] if x_hat.ndim == 1: save_path = audio_dir / f'{dataset}' / f'{example_id}.wav' dump_audio( x_hat, save_path, ) else: raise NotImplementedError(x_hat.shape)
def enhance_session( self, session_ids, audio_dir, test_run=False, ): """ >>> enhancer = get_enhancer(wpe=False, bss_iterations=2) >>> for x_hat in enhancer.enhance_session('S02'): ... print(x_hat) """ audio_dir = Path(audio_dir) it = self.get_iterator(session_ids) if mpi.IS_MASTER: audio_dir.mkdir() for dataset in set(mapping.session_to_dataset.values()): (audio_dir / dataset).mkdir() mpi.barrier() if test_run is not False: if test_run is True: it = it[:2] elif isinstance(test_run, int): it = it[:test_run] else: raise ValueError(test_run) for ex in mpi.share_master(it, allow_single_worker=True): x_hat = self.enhance_example(ex) example_id = ex["example_id"] session_id = ex["session_id"] dataset = mapping.session_to_dataset[session_id] if x_hat.ndim == 1: save_path = audio_dir / f'{dataset}' / f'{example_id}.wav' dump_audio( x_hat, save_path, ) else: raise NotImplementedError(x_hat.shape)
def enhance_session( self, session_ids, audio_dir, dataset_slice=False, audio_dir_exist_ok=False, is_chime=True, ): """ Args: session_ids: audio_dir: dataset_slice: audio_dir_exist_ok: When True: It is ok, when the audio dir exists and the files insinde may be overwritten. is_chime: If true, map the session_id to the dataset name for the folder naming. Otherwise keep the session_id for the folder name. Returns: >>> enhancer = get_enhancer(wpe=False, bss_iterations=2) >>> for x_hat in enhancer.enhance_session('S02'): ... print(x_hat) """ ensure_single_thread_numeric() audio_dir = Path(audio_dir) it = self.get_dataset(session_ids) if dlp_mpi.IS_MASTER: audio_dir.mkdir(exist_ok=audio_dir_exist_ok) # for dataset in self.db.data['alias']: # (audio_dir / dataset).mkdir(exist_ok=audio_dir_exist_ok) dlp_mpi.barrier() if dataset_slice is not False: if dataset_slice is True: it = it[:2] elif isinstance(dataset_slice, int): it = it[:dataset_slice] elif isinstance(dataset_slice, slice): it = it[dataset_slice] else: raise ValueError(dataset_slice) for ex in dlp_mpi.split_managed(it, allow_single_worker=True): try: x_hat = self.enhance_example(ex) example_id = ex["example_id"] session_id = ex["session_id"] if is_chime: dataset = mapping.session_to_dataset[session_id] else: dataset = session_id if x_hat.ndim == 1: save_path = audio_dir / f'{dataset}' / f'{example_id}.wav' dump_audio(x_hat, save_path, mkdir=True) else: raise NotImplementedError(x_hat.shape) except Exception: print('ERROR: Failed example:', ex['example_id']) raise