Commit 20b54af2 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

Merge branch 'it18218640' into 'master'

create preprocess function

See merge request !43
parents 248b404e 4d50138c
...@@ -31,4 +31,18 @@ class _Keyword_Spotting_Service: ...@@ -31,4 +31,18 @@ class _Keyword_Spotting_Service:
predicted_index = np.argmax(predictions) predicted_index = np.argmax(predictions)
predicted_keyword = self._mappings[predicted_index] predicted_keyword = self._mappings[predicted_index]
return predicted_keyword return predicted_keyword
\ No newline at end of file
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