mirror of
https://github.com/dscripka/openWakeWord.git
synced 2026-08-27 18:17:20 -04:00
Added/fixed reset methods
This commit is contained in:
parent
c63384489e
commit
68e88c1350
2 changed files with 12 additions and 2 deletions
|
|
@ -224,8 +224,10 @@ class Model():
|
|||
return parent_model
|
||||
|
||||
def reset(self):
|
||||
"""Reset the prediction buffer"""
|
||||
"""Reset the prediction and audio feature buffers. Useful for re-initializing the model, though may not be efficient
|
||||
when called too frequently."""
|
||||
self.prediction_buffer = defaultdict(partial(deque, maxlen=30))
|
||||
self.preprocessor.reset()
|
||||
|
||||
def predict(self, x: np.ndarray, patience: dict = {},
|
||||
threshold: dict = {}, debounce_time: float = 0.0, timing: bool = False):
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class AudioFeatures():
|
|||
|
||||
self.embedding_model_predict = tflite_embedding_predict
|
||||
|
||||
# Create databuffers
|
||||
# Create databuffers with empty/random data
|
||||
self.raw_data_buffer: Deque = deque(maxlen=sr*10)
|
||||
self.melspectrogram_buffer = np.ones((76, 32)) # n_frames x num_features
|
||||
self.melspectrogram_max_len = 10*97 # 97 is the number of frames in 1 second of 16hz audio
|
||||
|
|
@ -169,6 +169,14 @@ class AudioFeatures():
|
|||
self.feature_buffer = self._get_embeddings(np.random.randint(-1000, 1000, 16000*4).astype(np.int16))
|
||||
self.feature_buffer_max_len = 120 # ~10 seconds of feature buffer history
|
||||
|
||||
def reset(self):
|
||||
"""Reset the internal buffers"""
|
||||
self.raw_data_buffer.clear()
|
||||
self.melspectrogram_buffer = np.ones((76, 32))
|
||||
self.accumulated_samples = 0
|
||||
self.raw_data_remainder = np.empty(0)
|
||||
self.feature_buffer = self._get_embeddings(np.random.randint(-1000, 1000, 16000*4).astype(np.int16))
|
||||
|
||||
def _get_melspectrogram(self, x: Union[np.ndarray, List], melspec_transform: Callable = lambda x: x/10 + 2):
|
||||
"""
|
||||
Function to compute the mel-spectrogram of the provided audio samples.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue