Commit 4d50138c authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

create preprocess function

parent 7944179a
......@@ -32,3 +32,17 @@ class _Keyword_Spotting_Service:
predicted_keyword = self._mappings[predicted_index]
return predicted_keyword
def preprocess(self, file_path, n_mfcc=13, n_fft=2048, hop_length=512):
# load audio file
signal, sr = librosa.load(file_path)
# ensure consistency in the audio file length
if len(signal) > NUM_SAMPLES_TO_CONSIDER:
signal = signal[:NUM_SAMPLES_TO_CONSIDER]
# extract MFCCs
MFCCs = librosa.feature.mfcc(signal, n_mfcc=n_mfcc, n_fft=n_fft, hop_length=hop_length)
return MFCCs.T
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment