moodsync / preprocessing.py
PsalmsJava's picture
Create preprocessing.py
0d5c993 verified
raw
history blame contribute delete
511 Bytes
import librosa
import numpy as np
TARGET_SR = 16000
def load_audio(file_path):
audio, sr = librosa.load(file_path, sr=TARGET_SR)
return audio
def normalize_audio(audio):
audio = audio / np.max(np.abs(audio))
return audio
def remove_silence(audio):
intervals = librosa.effects.split(audio, top_db=30)
segments = []
for start, end in intervals:
segments.append(audio[start:end])
if len(segments) == 0:
return audio
return np.concatenate(segments)