Added tests for reset methods

This commit is contained in:
dscripka 2024-02-11 15:08:27 -05:00
parent 528f4bff2c
commit e9eade7aac

View file

@ -39,6 +39,7 @@ import platform
import pickle
import tempfile
import mock
import wave
# Download models needed for tests
openwakeword.utils.download_models()
@ -212,9 +213,6 @@ class TestModels:
# Load model with defaults
owwModel = openwakeword.Model()
# Get test clip
os.path.join("tests", "data", "alexa_test.wav")
# Predict with chunks of 1280 with and without debounce
predictions = owwModel.predict_clip(os.path.join("tests", "data", "alexa_test.wav"),
debounce_time=0, threshold={"alexa_v0.1": 0.5})
@ -227,6 +225,32 @@ class TestModels:
assert (scores >= 0.5).sum() > 1
assert (scores_with_debounce >= 0.5).sum() == 1
def test_model_reset(self):
# Load the model
owwModel = openwakeword.Model()
# Get test clip and load it
clip = os.path.join("tests", "data", "alexa_test.wav")
with wave.open(clip, mode='rb') as f:
data = np.frombuffer(f.readframes(f.getnframes()), dtype=np.int16)
# Predict frame by frame
for i in range(0, len(data), 1280):
prediction = owwModel.predict(data[i:i+1280])
if prediction['alexa'] > 0.5:
break
# Assert that next prediction is still > 0.5
prediction = owwModel.predict(data[i:i+1280])
assert prediction['alexa'] > 0.5
# Reset the model
owwModel.reset()
# Assert that next prediction is < 0.5
prediction = owwModel.predict(data[i:i+1280])
assert prediction['alexa'] < 0.5
def test_models_with_vad(self):
# Load model with defaults
owwModel = openwakeword.Model(vad_threshold=0.5)