Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rai_s2s/rai_s2s/asr/models/open_wake_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ def __init__(self, wake_word_model_path: str, threshold: float = 0.1):
"""
super(OpenWakeWord, self).__init__()
self.model_name = "open_wake_word"
if not isinstance(threshold, (int, float)) or isinstance(threshold, bool):
raise ValueError("threshold must be a number in (0, 1]")
if not (0.0 < float(threshold) <= 1.0) or threshold != threshold:
raise ValueError("threshold must be in (0, 1]")
self.threshold = float(threshold)
download_models()
self.model = OWWModel(
wakeword_models=[
wake_word_model_path,
],
inference_framework="onnx",
)
self.threshold = threshold

def detect(
self, audio_data: NDArray, input_parameters: dict[str, Any]
Expand Down
34 changes: 34 additions & 0 deletions tests/test_open_wake_word_threshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2026 Robotec.AI
import pytest

from rai_s2s.asr.models.open_wake_word import OpenWakeWord


def test_open_wake_word_rejects_invalid_threshold(monkeypatch):
monkeypatch.setattr(
"rai_s2s.asr.models.open_wake_word.download_models", lambda: None
)

class _Boom:
def __init__(self, *a, **k):
raise AssertionError("OWWModel should not load on bad threshold")

monkeypatch.setattr("rai_s2s.asr.models.open_wake_word.OWWModel", _Boom)

for bad in (0, -0.1, 1.1, float("nan"), True):
with pytest.raises(ValueError, match="threshold"):
OpenWakeWord(wake_word_model_path="unused.onnx", threshold=bad)


def test_open_wake_word_accepts_valid_threshold(monkeypatch):
monkeypatch.setattr(
"rai_s2s.asr.models.open_wake_word.download_models", lambda: None
)

class _Ok:
def __init__(self, *a, **k):
pass

monkeypatch.setattr("rai_s2s.asr.models.open_wake_word.OWWModel", _Ok)
m = OpenWakeWord(wake_word_model_path="unused.onnx", threshold=0.5)
assert m.threshold == 0.5
Loading