Last active
March 4, 2022 12:18
-
-
Save pranav6670/3e96d58b3ee55f5f4e8f53ed1ce27487 to your computer and use it in GitHub Desktop.
A envelope detection to downsample and clean audio data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def envelope(y, rate, threshold): | |
mask = [] | |
y = pd.Series(y).apply(np.abs) | |
y_mean = y.rolling(window=int(rate/10), min_periods=1, center=True).mean() | |
for mean in y_mean: | |
if mean > threshold: | |
mask.append(True) | |
else: | |
mask.append(False) | |
return mask | |
if len(os.listdir('clean')) == 0: | |
for f in tqdm(df.fname): | |
signal, rate = librosa.load('wavfiles/'+f, sr=16000) | |
mask = envelope(signal, rate, 0.0005) | |
wavfile.write(filename='clean/'+f, rate=rate, data=signal[mask]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment