Commit 13f8183c authored by Michaël Lauer's avatar Michaël Lauer
Browse files

add automatic download of IRCAM database

changed split of filename in order to work on windows and unix file systems
parent a48560d1
import numpy as np
import tensorflow as tf
def load_ircam_hrirs_data(filepath='.//databases//ircam_hrirs_512samples.p'):
import pickle
with open(filepath, mode='rb') as f:
......@@ -184,6 +185,7 @@ def split_long_wav(rootpath, max_parts=None):
print(f'selected {len(data_parts_loud_enough)}/{len(data_parts)}')
return data_parts_loud_enough
# from tensorflow GPU guide
def set_gpus():
gpus = tf.config.experimental.list_physical_devices('GPU')
......@@ -196,4 +198,6 @@ def set_gpus():
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
\ No newline at end of file
print(e)
......@@ -7,6 +7,37 @@ import pandas as pd
import scipy.io.wavfile
def download_ircam_database(path):
from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile
from bs4 import BeautifulSoup
print('downloading IRCAM database...')
# Set variable for page to be open and url to be concatenated
url = "http://recherche.ircam.fr"
page = urlopen(
'http://recherche.ircam.fr/equipes/salles/listen/download.html').read()
# File extension to be looked for.
extension = ".zip"
# Use BeautifulSoup to clean up the page
soup = BeautifulSoup(page, features='html.parser')
soup.prettify()
# Find all the links on the page that end in .zip
for anchor in soup.findAll('a', href=True):
links = anchor['href']
if links.endswith(extension):
print('downloading ' + links)
with urlopen(links) as zipresp:
with ZipFile(BytesIO(zipresp.read())) as zfile:
dir_name = os.path.join(path, links[-8:-4])
print(f'extracting to ', dir_name)
zfile.extractall(dir_name)
def load_ircam_database(path, hrir_length):
"""
......@@ -20,13 +51,26 @@ def load_ircam_database(path, hrir_length):
input_files = [file for file in glob.iglob(os.path.join(path, '**/*.wav'), recursive=True) if
('COMP' in file or 'RAW' in file)]
#if no input files, downoad database from IRCAM and retry input files
if not input_files:
download_ircam_database(path)
input_files = [file for file in glob.iglob(os.path.join(path, '**/*.wav'), recursive=True) if
('COMP' in file or 'RAW' in file)]
# window to be applied to each hrir before being truncated when hrir are longer then specified hrir_length
from scipy import signal
win = signal.windows.hann(M=2 * hrir_length, sym=True)[hrir_length:]
hrirs = []
for file in input_files:
_, subject_id, status, radius, azimuth, elevation = file[:-4].split('\\')[-1].split('_')
# _, subject_id, status, radius, azimuth, elevation = file[:-4].split('\\')[-1].split('_')
try:
_, filename = os.path.split(file)
_, subject_id, status, radius, azimuth, elevation = filename[:-4].split('_')
except ValueError:
print('Oops! wrong filename format:', filename)
break
assert radius[0] == 'R'
assert azimuth[0] == 'T'
assert elevation[0] == 'P'
......@@ -103,6 +147,7 @@ def custom_parse_args():
return args
if __name__ == '__main__':
# get args + sanity check
args = custom_parse_args()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment