Commit 7944179a authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

create predict function

parent 19e43f67
...@@ -17,3 +17,18 @@ class _Keyword_Spotting_Service: ...@@ -17,3 +17,18 @@ class _Keyword_Spotting_Service:
"yellow" "yellow"
] ]
_instance = None _instance = None
def predict(self, file_path):
# extract MFCCs
MFCCs = self.preprocess(file_path) # (# segment, # coefficients)
# convert 2d MFCCs array into 4d array -> (# samples, # segment, # coefficients, # channels)
MFCCs = MFCCs[np.newaxis, ..., np.newaxis]
# make prediction
predictions = self.model.predict(MFCCs)
predicted_index = np.argmax(predictions)
predicted_keyword = self._mappings[predicted_index]
return predicted_keyword
\ 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