Deprecate stt_service parameter in STTMuteFilter

This commit is contained in:
Mark Backman
2025-02-07 19:20:51 -05:00
parent 6855bc0ada
commit a1b58115ce
3 changed files with 17 additions and 5 deletions

View File

@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
- `STTMuteFilter` constructor's `stt_service` parameter is now deprecated and
will be removed in a future version. The filter now manages mute state
internally instead of querying the STT service.
- `RTVI.observer()` is now deprecated, instantiate an `RTVIObserver` directly
instead.

View File

@@ -61,7 +61,6 @@ async def main():
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
# Configure the mute processor with both strategies
stt_mute_processor = STTMuteFilter(
stt_service=stt,
config=STTMuteConfig(
strategies={STTMuteStrategy.FIRST_SPEECH, STTMuteStrategy.FUNCTION_CALL}
),

View File

@@ -11,6 +11,7 @@ such as during function calls, bot speech, or custom conditions. It helps manage
the STT service should be active or inactive during a conversation.
"""
import warnings
from dataclasses import dataclass
from enum import Enum
from typing import Awaitable, Callable, Optional
@@ -71,28 +72,36 @@ class STTMuteFilter(FrameProcessor):
feature. When STT is muted, interruptions are automatically disabled.
Args:
stt_service: Service handling speech-to-text functionality
config: Configuration specifying muting strategies
stt_service: STT service instance (deprecated, will be removed in future version)
**kwargs: Additional arguments passed to parent class
"""
def __init__(self, stt_service: STTService, config: STTMuteConfig, **kwargs):
def __init__(self, config: STTMuteConfig, stt_service: Optional[STTService] = None, **kwargs):
super().__init__(**kwargs)
self._stt_service = stt_service
self._config = config
if stt_service is not None:
warnings.warn(
"The stt_service parameter is deprecated and will be removed in a future version. "
"STTMuteFilter now manages mute state internally.",
DeprecationWarning,
stacklevel=2,
)
self._first_speech_handled = False
self._bot_is_speaking = False
self._function_call_in_progress = False
self._is_muted = False
@property
def is_muted(self) -> bool:
"""Returns whether STT is currently muted."""
return self._stt_service.is_muted
return self._is_muted
async def _handle_mute_state(self, should_mute: bool):
"""Handles both STT muting and interruption control."""
if should_mute != self.is_muted:
logger.debug(f"STT {'muting' if should_mute else 'unmuting'}")
self._is_muted = should_mute
await self.push_frame(STTMuteFrame(mute=should_mute))
async def _should_mute(self) -> bool: