From 444d6b8611097c726c4e42d59ffc61a14e70378c Mon Sep 17 00:00:00 2001 From: genisplaja Date: Sat, 4 Nov 2023 15:17:47 +0100 Subject: [PATCH] drop pytsmod --- .gitignore | 5 +- compiam/utils/augment/__init__.py | 46 +++++++------- compiam/utils/augment/augment_data_ps.py | 62 ------------------- .../0_Tabla_Stroke_Classification.ipynb | 5 +- requirements.txt | 2 +- 5 files changed, 31 insertions(+), 89 deletions(-) delete mode 100644 compiam/utils/augment/augment_data_ps.py diff --git a/.gitignore b/.gitignore index 54820487..494c5e91 100644 --- a/.gitignore +++ b/.gitignore @@ -76,4 +76,7 @@ tests/resources/mir_datasets/* # For next release compiam/models/rhythm/4wayTabla/ tests/rhythm/test_4way_tabla.py -compiam/rhythm/transcription/tabla_transcription/ \ No newline at end of file +compiam/rhythm/transcription/tabla_transcription/ + +# To avoid dependency clashes +compiam/utils/augment/augment_data_ps.py \ No newline at end of file diff --git a/compiam/utils/augment/__init__.py b/compiam/utils/augment/__init__.py index dcaa64fc..009d076a 100644 --- a/compiam/utils/augment/__init__.py +++ b/compiam/utils/augment/__init__.py @@ -3,7 +3,7 @@ from compiam.utils import create_if_not_exists from compiam.utils.augment.augment_data_ar import augment_data_attack_remix -from compiam.utils.augment.augment_data_ps import augment_data_pitch_shift +#from compiam.utils.augment.augment_data_ps import augment_data_pitch_shift from compiam.utils.augment.augment_data_sf import augment_data_spectral_shape from compiam.utils.augment.augment_data_sr import augment_data_stroke_remix from compiam.utils.augment.augment_data_ts import augment_data_time_scale @@ -11,28 +11,28 @@ file_dir = os.path.dirname(__file__) -def pitch_shift(in_path, out_dir, shifts=-1.0, sr=16000, n_jobs=4): - """Pitch shift audio at , by shifts in . Output to - - :param in_path: Path to input audio - :type in_path: str - :param out_dir: Directory to output pitch shifted audios - :type out_dir: str - :param shifts: Pitch shifts value in semitones (or list of values for multiple outputs) - :type shifts: float or list - :param sr: Sampling rate of input audio - :type sr: float - :param n_jobs: n jobs for parrelelization - :type n_jobs: int - """ - create_if_not_exists(out_dir) - - if not isinstance(shifts, list): - shifts = [shifts] - - _ = Parallel(n_jobs=n_jobs)( - delayed(augment_data_pitch_shift)(in_path, out_dir, sr, ps) for ps in shifts - ) +#def pitch_shift(in_path, out_dir, shifts=-1.0, sr=16000, n_jobs=4): +# """Pitch shift audio at , by shifts in . Output to +# +# :param in_path: Path to input audio +# :type in_path: str +# :param out_dir: Directory to output pitch shifted audios +# :type out_dir: str +# :param shifts: Pitch shifts value in semitones (or list of values for multiple outputs) +# :type shifts: float or list +# :param sr: Sampling rate of input audio +# :type sr: float +# :param n_jobs: n jobs for parrelelization +# :type n_jobs: int +# """ +# create_if_not_exists(out_dir) +# +# if not isinstance(shifts, list): +# shifts = [shifts] +# +# _ = Parallel(n_jobs=n_jobs)( +# delayed(augment_data_pitch_shift)(in_path, out_dir, sr, ps) for ps in shifts +# ) def spectral_shape( diff --git a/compiam/utils/augment/augment_data_ps.py b/compiam/utils/augment/augment_data_ps.py deleted file mode 100644 index 155ac572..00000000 --- a/compiam/utils/augment/augment_data_ps.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -import numpy as np -import librosa -import soundfile as sf -from joblib import Parallel, delayed -import pytsmod as tsm -import argparse -from pathlib import PurePath - - -def augment_data_pitch_shift(audio_path, out_dir, fs, pitch_shift_factor): - x, fs = librosa.load(audio_path, sr=fs) - x /= np.max(np.abs(x)) - - pitch_shift_factor_hz = 2 ** (pitch_shift_factor / 12) - - y = tsm.hptsm(x, pitch_shift_factor_hz) - y = librosa.resample(y, fs, fs / pitch_shift_factor_hz) - - sf.write( - os.path.join( - out_dir, - PurePath(audio_path).name.replace( - ".wav", "_ps_%2.2f.wav" % pitch_shift_factor - ), - ), - y, - fs, - ) - return - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="pitch-shift") - parser.add_argument("--input", type=str, default="", help="path to input audio") - parser.add_argument( - "--output", - type=str, - default="./outputs/", - help="folder to save modified audios", - ) - parser.add_argument("--fs", type=int, default=16000, help="sampling rate") - parser.add_argument( - "--params", - nargs="+", - type=float, - default=[-1.0, -0.5, 0.5, 1.0], - help="list of pitch shift values in semitones", - ) - parser.add_argument( - "--n_jobs", type=int, default=4, help="number of cores to run program on" - ) - - args, _ = parser.parse_known_args() - - if not os.path.exists(args.output): - os.makedirs(args.output) - - _ = Parallel(n_jobs=args.n_jobs)( - delayed(augment_data_pitch_shift)(args.input, args.output, args.fs, ps) - for ps in args.shifts - ) diff --git a/notebooks/rhythm/0_Tabla_Stroke_Classification.ipynb b/notebooks/rhythm/0_Tabla_Stroke_Classification.ipynb index 3695c3e4..4f3c38c0 100644 --- a/notebooks/rhythm/0_Tabla_Stroke_Classification.ipynb +++ b/notebooks/rhythm/0_Tabla_Stroke_Classification.ipynb @@ -28,9 +28,10 @@ "outputs": [], "source": [ "# Data augment\n", - "from compiam.utils.augment import pitch_shift, spectral_shape, stroke_remix, time_scale, attack_remix\n", + "#from compiam.utils.augment import pitch_shift dropping for now\n", + "from compiam.utils.augment import spectral_shape, stroke_remix, time_scale, attack_remix\n", "\n", - "pitch_shift(in_path, out_dir, fs, ps, shifts, n_jobs=n_jobs)\n", + "#pitch_shift(in_path, out_dir, fs, ps, shifts, n_jobs=n_jobs)\n", "spectral_shape(in_path, out_dir, fs, gain_set, winDur, hopDur, params, n_jobs=n_jobs)\n", "stroke_remix(in_path, out_dir, fs, gain_set, templates, winDur, hopDur, params, n_jobs=n_jobs)\n", "time_scale(in_path, out_dir, fs, ts, params, n_jobs=n_jobs)\n", diff --git a/requirements.txt b/requirements.txt index f0367f2b..2907b7f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ matplotlib>=3.0.0 numpy>=1.20.3 joblib>=1.2.0 pathlib~=1.0.1 -pytsmod~=0.3.7 +#pytsmod~=0.3.7 Needs update tqdm>=4.66.1 IPython>=7.34.0 ipywidgets>=7.0.0,<8