Files
livekit-agents/python/tests/test_plugin_gradium_stt.py
T

67 lines
2.0 KiB
Python

"""Tests for Gradium STT plugin configuration and behavior."""
from __future__ import annotations
import json
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
pytestmark = pytest.mark.plugin("gradium")
async def test_stream_language_overrides_stream_options():
"""stream language overrides the copied stream config."""
from livekit.plugins.gradium import STT
stt = STT(api_key="test-key", language="fr", http_session=MagicMock())
from livekit.plugins.gradium.stt import SpeechStream
with patch.object(SpeechStream, "_run", new_callable=AsyncMock):
stream = stt.stream(language="de")
assert stream._opts.language == "de"
assert stt._opts.language == "fr"
await stream.aclose()
@pytest.mark.asyncio
async def test_speech_stream_sends_language_in_json_config():
"""SpeechStream sends language in setup json_config."""
from livekit.agents import DEFAULT_API_CONNECT_OPTIONS, LanguageCode
from livekit.plugins.gradium import STT
from livekit.plugins.gradium.stt import SpeechStream, STTOptions
sent_messages: list[str] = []
class FakeWebSocket:
async def send_str(self, message: str) -> None:
sent_messages.append(message)
class FakeSession:
trace_configs: list[object] = []
async def ws_connect(self, url, headers, **kwargs):
return FakeWebSocket()
stt = STT(api_key="test-key")
opts = STTOptions(language=LanguageCode("pt"), temperature=0.3)
with patch.object(SpeechStream, "_run", new_callable=AsyncMock):
stream = SpeechStream(
stt=stt,
opts=opts,
conn_options=DEFAULT_API_CONNECT_OPTIONS,
api_key="test-key",
model_endpoint="wss://api.gradium.ai/api/speech/asr",
model_name="default",
http_session=FakeSession(),
)
await stream._connect_ws()
await stream.aclose()
setup_msg = json.loads(sent_messages[0])
assert setup_msg["json_config"] == {"language": "pt", "temp": 0.3}