Overview
ServiceSwitcher
is a specialized parallel pipeline that enables dynamic switching between multiple service instances at runtime. This is useful when you need to change between different STT providers, TTS providers, or other frame processors based on user preferences, costs, performance requirements, or other runtime conditions.
The switcher uses a strategy pattern to determine which service is active. Currently, a manual switching strategy is provided, allowing explicit control over which service handles frames at any given time.
How It Works
ServiceSwitcher
wraps multiple services in a parallel pipeline where only the active service processes frames. Each service is “sandwiched” between two filters that check if it’s the currently active service before allowing frames to pass through. When you switch services, the filters update to redirect frame flow to the newly active service.
Constructor
List of service instances to switch between. Can be any frame processors (STT,
TTS, or custom processors).
The strategy class to use for switching logic. Pass the class itself, not an
instance.
Switching Strategies
ServiceSwitcherStrategyManual
The manual strategy allows explicit control over which service is active by pushingManuallySwitchServiceFrame
frames into the pipeline.
Initial State: The first service in the list is active by default.
Switching: Push a ManuallySwitchServiceFrame
with the desired service instance.