-
Notifications
You must be signed in to change notification settings - Fork 9
Pr/configurable turn options #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3ce065b
Merge branch 'main' of github.com:ServiceNow/eva into develop/0.1.2
raghavm243512 cf2e86d
WIP
raghavm243512 d3bb301
read from metric summary
raghavm243512 0ffeb26
revert reading location
raghavm243512 86e2fa8
merge and fix s2s
raghavm243512 de67ed2
cleanup defaults
raghavm243512 4b3d6ee
Merge branch 'main' into pr/configurable_turn_options
raghavm243512 4dda9f0
Apply pre-commit
raghavm243512 818973f
add tests
raghavm243512 60f5be5
merge main
raghavm243512 80debfc
Apply pre-commit
raghavm243512 348697e
Merge branch 'main' of github.com:ServiceNow/eva into pr/configurable…
raghavm243512 062733a
comments
raghavm243512 2c06f12
Apply pre-commit
raghavm243512 01c0d5e
none option
raghavm243512 9ed1df1
typo
raghavm243512 ec0e30c
useless test
raghavm243512 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
fanny-riols marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """Factory functions for creating turn strategies and VAD analyzers from configuration. | ||
|
|
||
| This module provides functions to instantiate Pipecat turn strategies and VAD analyzers | ||
| based on configuration settings from environment variables or config files. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pipecat.audio.turn.smart_turn.base_smart_turn import SmartTurnParams | ||
| from pipecat.audio.turn.smart_turn.local_smart_turn_v3 import LocalSmartTurnAnalyzerV3 | ||
| from pipecat.audio.vad.silero import SileroVADAnalyzer | ||
| from pipecat.audio.vad.vad_analyzer import VADAnalyzer, VADParams | ||
| from pipecat.turns.user_start import ( | ||
| BaseUserTurnStartStrategy, | ||
| ExternalUserTurnStartStrategy, | ||
| TranscriptionUserTurnStartStrategy, | ||
| VADUserTurnStartStrategy, | ||
| ) | ||
| from pipecat.turns.user_stop import ( | ||
| BaseUserTurnStopStrategy, | ||
| ExternalUserTurnStopStrategy, | ||
| SpeechTimeoutUserTurnStopStrategy, | ||
| TurnAnalyzerUserTurnStopStrategy, | ||
| ) | ||
|
|
||
| from eva.utils.logging import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def create_vad_analyzer(vad_type: str | None, vad_params: dict[str, Any]) -> VADAnalyzer | None: | ||
| """Create a VAD analyzer from configuration. | ||
|
|
||
| Args: | ||
| vad_type: VAD analyzer type ('silero' or None for default) | ||
| vad_params: VAD parameters (confidence, start_secs, stop_secs, min_volume) | ||
|
|
||
| Returns: | ||
| VAD analyzer instance, or None if vad_type is None | ||
|
|
||
| Raises: | ||
| ValueError: If vad_type is not supported | ||
| """ | ||
| if vad_type is None: | ||
| return None | ||
|
|
||
| vad_type_lower = vad_type.lower() | ||
|
|
||
| if vad_type_lower == "silero": | ||
| # Create VADParams, respecting existing defaults if no params specified | ||
| params = VADParams(**vad_params) if vad_params else None | ||
| return SileroVADAnalyzer(params=params) | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported VAD type: {vad_type}. Supported types: 'silero'" | ||
| ) | ||
|
|
||
|
|
||
| def create_turn_start_strategy( | ||
| strategy_type: str | None, | ||
| strategy_params: dict[str, Any], | ||
| ) -> BaseUserTurnStartStrategy | None: | ||
| """Create a user turn start strategy from configuration. | ||
|
|
||
| Args: | ||
| strategy_type: Strategy type ('vad', 'transcription', 'external', or None for default) | ||
| strategy_params: Strategy-specific parameters | ||
|
|
||
| Returns: | ||
| Turn start strategy instance, or None if strategy_type is None | ||
|
|
||
| Raises: | ||
| ValueError: If strategy_type is not supported | ||
| """ | ||
| if strategy_type is None: | ||
| return None | ||
|
|
||
| strategy_type_lower = strategy_type.lower() | ||
|
|
||
| if strategy_type_lower == "vad": | ||
| # VADUserTurnStartStrategy has no required parameters | ||
| return VADUserTurnStartStrategy(**strategy_params) | ||
| elif strategy_type_lower == "transcription": | ||
| # TranscriptionUserTurnStartStrategy has no required parameters | ||
| return TranscriptionUserTurnStartStrategy(**strategy_params) | ||
| elif strategy_type_lower == "external": | ||
| # ExternalUserTurnStartStrategy has no required parameters | ||
| return ExternalUserTurnStartStrategy(**strategy_params) | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported turn start strategy: {strategy_type}. " | ||
| f"Supported types: 'vad', 'transcription', 'external'" | ||
| ) | ||
|
|
||
|
|
||
| def create_turn_stop_strategy( | ||
| strategy_type: str | None, | ||
| strategy_params: dict[str, Any], | ||
| smart_turn_stop_secs: float | None = None, | ||
| ) -> BaseUserTurnStopStrategy | None: | ||
| """Create a user turn stop strategy from configuration. | ||
|
|
||
| Args: | ||
| strategy_type: Strategy type ('speech_timeout', 'turn_analyzer', 'external', or None for default) | ||
| strategy_params: Strategy-specific parameters | ||
| smart_turn_stop_secs: stop_secs for SmartTurnParams (used with turn_analyzer strategy) | ||
|
|
||
| Returns: | ||
| Turn stop strategy instance, or None if strategy_type is None | ||
|
|
||
| Raises: | ||
| ValueError: If strategy_type is not supported | ||
| """ | ||
| if strategy_type is None: | ||
| return None | ||
|
|
||
| strategy_type_lower = strategy_type.lower() | ||
|
|
||
| if strategy_type_lower == "speech_timeout": | ||
| # SpeechTimeoutUserTurnStopStrategy accepts user_speech_timeout parameter | ||
| return SpeechTimeoutUserTurnStopStrategy(**strategy_params) | ||
| elif strategy_type_lower == "turn_analyzer": | ||
| # TurnAnalyzerUserTurnStopStrategy requires a turn_analyzer instance | ||
| # If smart_turn_stop_secs is provided, use it; otherwise let SmartTurnParams use its default | ||
| smart_params = SmartTurnParams(stop_secs=smart_turn_stop_secs) if smart_turn_stop_secs is not None else None | ||
| turn_analyzer = LocalSmartTurnAnalyzerV3(params=smart_params) | ||
| return TurnAnalyzerUserTurnStopStrategy(turn_analyzer=turn_analyzer, **strategy_params) | ||
| elif strategy_type_lower == "external": | ||
| # ExternalUserTurnStopStrategy has no required parameters | ||
| return ExternalUserTurnStopStrategy(**strategy_params) | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported turn stop strategy: {strategy_type}. " | ||
| f"Supported types: 'speech_timeout', 'turn_analyzer', 'external'" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.