Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/rai_s2s/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "rai_s2s"
version = "1.0.1"
version = "1.0.2"
description = "Speech-to-Speech module for RAI framework"
readme = "README.md"
requires-python = ">=3.10,<3.13"
Expand Down
17 changes: 12 additions & 5 deletions src/rai_s2s/rai_s2s/asr/agents/asr_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from typing_extensions import Self

from rai_s2s.asr.agents.initialization import load_config
from rai_s2s.asr.agents.initialization import TRANSCRIBE_MODELS, load_config
from rai_s2s.asr.models import BaseTranscriptionModel, BaseVoiceDetectionModel
from rai_s2s.sound_device import (
SoundDeviceConfig,
Expand Down Expand Up @@ -121,32 +121,39 @@ def from_config(cls, cfg_path: Optional[str] = None) -> Self:
is_output=False,
)
match cfg.transcribe.model_type:
case "LocalWhisper (Free)":
case "LocalWhisper":
from rai_s2s.asr.models import LocalWhisper

model = LocalWhisper(
cfg.transcribe.model_name, 16000, language=cfg.transcribe.language
)
case "FasterWhisper (Free)":
case "FasterWhisper":
from rai_s2s.asr.models import FasterWhisper

model = FasterWhisper(
cfg.transcribe.model_name, 16000, language=cfg.transcribe.language
)
case "OpenAI (Cloud)":
case "OpenAI":
from rai_s2s.asr.models import OpenAIWhisper

model = OpenAIWhisper(
cfg.transcribe.model_name, 16000, language=cfg.transcribe.language
)
case _:
raise ValueError(f"Unknown model name f{cfg.transcribe.model_name}")
raise ValueError(
f"Unknown transcription model: {cfg.transcribe.model_type}. "
f"Must be one of {TRANSCRIBE_MODELS}"
)

match cfg.voice_activity_detection.model_name:
case "SileroVAD":
from rai_s2s.asr.models import SileroVAD

vad = SileroVAD(16000, cfg.voice_activity_detection.threshold)
case _:
raise ValueError(
f"Unknown VAD model: {cfg.voice_activity_detection.model_name}"
)

agent = cls(microphone_configuration, "rai_auto_asr_agent", model, vad)
if cfg.wakeword.is_used:
Expand Down
83 changes: 83 additions & 0 deletions tests/s2s/test_asr_agent_from_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (C) 2026 Robotec.AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""from_config dispatches on config strings, so the values TRANSCRIBE_MODELS
advertises and the configurator writes have to be the ones it matches on."""

from pathlib import Path

import pytest

from rai_s2s.asr import models
from rai_s2s.asr.agents.asr_agent import SpeechRecognitionAgent
from rai_s2s.asr.agents.initialization import TRANSCRIBE_MODELS

CONFIG = """
[asr]
recording_device_name = "default"
transcription_model = "{transcription_model}"
transcription_model_name = "tiny"
language = "en"
vad_model = "{vad_model}"
vad_threshold = 0.3
silence_grace_period = 0.3
use_wake_word = false
wake_word_model = ""
wake_word_model_name = ""
wake_word_threshold = 0.5
"""


@pytest.fixture
def config(tmp_path: Path):
def write(transcription_model: str, vad_model: str = "SileroVAD") -> str:
path = tmp_path / "config.toml"
path.write_text(
CONFIG.format(transcription_model=transcription_model, vad_model=vad_model)
)
return str(path)

return write


@pytest.fixture(autouse=True)
def stub_models(monkeypatch):
"""The dispatch is under test, not the models it reaches for."""
for name in ("LocalWhisper", "FasterWhisper", "OpenAIWhisper", "SileroVAD"):
monkeypatch.setattr(models, name, lambda *args, **kwargs: object())
monkeypatch.setattr(
SpeechRecognitionAgent, "__init__", lambda self, *args, **kwargs: None
)


@pytest.mark.parametrize("transcription_model", TRANSCRIBE_MODELS)
def test_every_advertised_model_is_dispatchable(config, transcription_model):
assert isinstance(
SpeechRecognitionAgent.from_config(config(transcription_model)),
SpeechRecognitionAgent,
)


def test_unknown_transcription_model_lists_the_valid_ones(config):
# the old suffixed spelling is now rejected at config load, not silently
# accepted and then dropped by the dispatch below
with pytest.raises(ValueError, match="unknown model_type"):
SpeechRecognitionAgent.from_config(config("LocalWhisper (Free)"))


def test_unknown_vad_model_is_reported(config):
with pytest.raises(ValueError, match="Unknown VAD model"):
SpeechRecognitionAgent.from_config(
config(TRANSCRIBE_MODELS[0], vad_model="NotAVAD")
)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading