"""MIT Impulse Response Survey=================================This is a dataset of environmental impulse responses from various real-world locations,collected in the `MIT IR Survey <https://mcdermottlab.mit.edu/Reverb/IR_Survey.html>`_ by Traer and McDermott.Each audio file is a waveform which contains the impulse response of a location.That is to say, how an instantaneous pressure at $t = 0$ is reflected, damped and scattered in the environment.By convolving the dataset impulse responses with an audio clip,we can simulate how that audio clip would sound if emitted and recorded in the environmentwhere the impulse response was recorded. This is a technique commonly used for data augmentation inaudio processing problems, commonly referred to asmulti-style training (see `Deep Spoken Keyword Spotting: An Overview <https://arxiv.org/pdf/2111.10592.pdf>`_), simulated reverberation(see e.g. `End-to-End Streaming Keyword Spotting <https://arxiv.org/pdf/1812.02802.pdf>`_) or acoustic simulation.License---------CC-BY 4.0 (see `MIT Creative Commons License <https://creativecommons.org/licenses/by/4.0>`_ for details).Credits--------------Traer and McDermott 2016 paper `Statistics of natural reverberation enable perceptual separation of sound and space <https://www.pnas.org/doi/full/10.1073/pnas.1612524113>`_"""fromtypingimportListimportosimportloggingimportnumpyasnpfrommltk.core.preprocess.utilsimportaudioasaudio_utilsfrommltk.utils.pythonimportappend_exception_msgfrommltk.utils.archive_downloaderimportdownload_verify_extractDOWNLOAD_URL='https://mcdermottlab.mit.edu/Reverb/IRMAudio/Audio.zip'"""Public download URL"""VERIFY_SHA1='de04f5be419c12f4f847f65d7ef8e2356b73aa38'"""SHA1 hash of the downloaded archive file"""
[docs]defdownload(dest_dir:str=None,dest_subdir='datasets/mit_ir_survey',logger:logging.Logger=None,clean_dest_dir=False,sample_rate_hz=16000,)->str:"""Download and extract the dataset Returns: The directory path to the extracted dataset """try:importsoundfileexceptModuleNotFoundErrorase:append_exception_msg(e,'Try running the command: pip install soundfile')raiseeifdest_dir:dest_subdir=Nonesample_dir=download_verify_extract(url=DOWNLOAD_URL,archive_fname='mit_ir_survey.zip',dest_dir=dest_dir,dest_subdir=dest_subdir,file_hash=VERIFY_SHA1,show_progress=False,remove_root_dir=False,clean_dest_dir=clean_dest_dir,logger=logger)src_dir=f'{sample_dir}/Audio'forfninos.listdir(src_dir):ifnotfn.endswith('.wav'):continuedst_path=f'{sample_dir}/{fn}'ifnotos.path.exists(dst_path):data,sr=soundfile.read(f'{src_dir}/{fn}')data=data.astype(np.float32)ifsr!=sample_rate_hz:data=audio_utils.resample(data,orig_sr=sr,target_sr=sample_rate_hz)audio_utils.write_audio_file(dst_path,data,sample_rate=sample_rate_hz)returnsample_dir
[docs]defapply_ir(audio:np.ndarray,ir:np.ndarray)->np.ndarray:"""Apply an impulse response to the given audio sample"""try:fromscipyimportsignalexceptModuleNotFoundErrorase:append_exception_msg(e,'Try running the command: pip install scipy')raisereturnsignal.fftconvolve(audio,ir)
[docs]defload_dataset(dataset_dir:str)->List[np.ndarray]:"""Load the impulse response dataset directory into RAM"""try:importsoundfileexceptModuleNotFoundErrorase:append_exception_msg(e,'Try running the command: pip install soundfile')raiseeretval=[]forfninos.listdir(dataset_dir):ifnotfn.endswith('.wav'):continuedata,_=soundfile.read(f'{dataset_dir}/{fn}')data=data.astype(np.float32)retval.append(data)returnretval
[docs]defapply_random_ir(audio:np.ndarray,ir_samples:List[np.ndarray],seed:int=42)->np.ndarray:"""Appyly a random impulse response to the given audio sample"""rgen=np.random.RandomState(seed=seed)index=rgen.choice(len(ir_samples))ir=ir_samples[index]returnapply_ir(audio,ir)
Important: We use cookies only for functional and traffic analytics.
We DO NOT use cookies for any marketing purposes. By using our site you acknowledge you have read and understood our Cookie Policy.