Skip to content
Closed
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
3 changes: 3 additions & 0 deletions gateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class GatewayConfig:

# Delivery settings
always_log_local: bool = True # Always save cron outputs to local files
stt_enabled: bool = True # Whether to auto-transcribe voice messages

def get_connected_platforms(self) -> List[Platform]:
"""Return list of platforms that are enabled and configured."""
Expand Down Expand Up @@ -215,6 +216,7 @@ def to_dict(self) -> Dict[str, Any]:
"reset_triggers": self.reset_triggers,
"sessions_dir": str(self.sessions_dir),
"always_log_local": self.always_log_local,
"stt_enabled": self.stt_enabled,
}

@classmethod
Expand Down Expand Up @@ -255,6 +257,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "GatewayConfig":
reset_triggers=data.get("reset_triggers", ["/new", "/reset"]),
sessions_dir=sessions_dir,
always_log_local=data.get("always_log_local", True),
stt_enabled=data.get("stt", {}).get("enabled", True),
)


Expand Down
2 changes: 1 addition & 1 deletion gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ async def _handle_message(self, event: MessageEvent) -> Optional[str]:
)
if is_audio:
audio_paths.append(path)
if audio_paths:
if audio_paths and self.config.stt_enabled:
message_text = await self._enrich_message_with_transcription(
message_text, audio_paths
)
Expand Down
53 changes: 53 additions & 0 deletions tests/gateway/test_stt_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Tests for STT config — gateway should honor stt.enabled: false (#1100)."""
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from gateway.config import GatewayConfig
from gateway.platforms.base import MessageEvent, MessageType


def _make_runner(stt_enabled=True):
from gateway.run import GatewayRunner
config = GatewayConfig(stt_enabled=stt_enabled)
runner = GatewayRunner.__new__(GatewayRunner)
runner.config = config
return runner


@pytest.mark.asyncio
async def test_stt_disabled_skips_transcription():
runner = _make_runner(stt_enabled=False)
runner._enrich_message_with_transcription = AsyncMock(return_value="should not be called")
audio_paths = ["/tmp/voice.ogg"]
if audio_paths and runner.config.stt_enabled:
await runner._enrich_message_with_transcription("", audio_paths)
runner._enrich_message_with_transcription.assert_not_called()


@pytest.mark.asyncio
async def test_stt_enabled_calls_transcription():
runner = _make_runner(stt_enabled=True)
runner._enrich_message_with_transcription = AsyncMock(return_value="[transcript]")
audio_paths = ["/tmp/voice.ogg"]
if audio_paths and runner.config.stt_enabled:
await runner._enrich_message_with_transcription("", audio_paths)
runner._enrich_message_with_transcription.assert_called_once()


def test_gateway_config_stt_enabled_default():
config = GatewayConfig()
assert config.stt_enabled is True


def test_gateway_config_stt_disabled_from_dict():
config = GatewayConfig.from_dict({"stt": {"enabled": False}})
assert config.stt_enabled is False


def test_gateway_config_stt_enabled_from_dict():
config = GatewayConfig.from_dict({"stt": {"enabled": True}})
assert config.stt_enabled is True


def test_gateway_config_stt_missing_defaults_true():
config = GatewayConfig.from_dict({})
assert config.stt_enabled is True
Loading