import os
def retrieve_local_wav_files_from_folder(folder_path, result_dir, missing_files_tsv="missing_files.tsv"): """ Retrieve local WAV files from a specified folder and save them in a result directory. It also stores the missing files in a TSV file with associated error.
Args:
folder_path: str, path to the folder where WAV files are located.
result_dir: str, result directory where retrieved WAV files will be saved.
missing_files_tsv: str, path of the TSV which will contain the filenames that couldn't be found.
Returns:
missing_files: pandas DataFrame, files not found with associated error.
"""
warnings.filterwarnings("ignore")
create_folder(result_dir)
files_error = []
for filename in tqdm(filenames):
file_path = os.path.join(folder_path, filename)
if os.path.exists(file_path):
shutil.copy(file_path, os.path.join(result_dir, filename))
else:
files_error.append({"filename": filename, "error": "File not found"})
# Store files which couldn't be found
missing_files = pd.DataFrame(files_error).dropna()
if not missing_files.empty:
# Save missing_files to be able to identify them
missing_files.to_csv(missing_files_tsv, index=False, sep="\t")
warnings.warn(f"Some files were not found and are listed in {missing_files_tsv}", DesedWarning)
warnings.resetwarnings()
return missing_files