add resample module in preprocessing package, refactor demucs_wrapper.py

This commit is contained in:
Joel Mathew Thomas
2024-12-26 19:47:24 +05:30
parent 96b4468138
commit cfd30185bd
2 changed files with 30 additions and 43 deletions
+18
View File
@@ -0,0 +1,18 @@
import librosa
def resample(waveform, org_samplerate, new_samplerate):
"""
Reads a waveform and returns a waveform resampled to samplerate.
Args:
waveform: waveform of the target audio.
org_samplerate : original samplerate of the audio.
new_samplerate : samplerate to which the audio is to be resampled.
"""
try:
waveform = librosa.resample(waveform, orig_sr=org_samplerate, target_sr=new_samplerate)
return waveform, new_samplerate
except Exception as e:
raise RuntimeError(f"Error reasmpling the audio file: {e}")