-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(sarvam): align Bulbul validation with API constraints #6839
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
Open
mikemikimike
wants to merge
2
commits into
livekit:main
Choose a base branch
from
mikemikimike:fix/sarvam-bulbul-validation-6774
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−13
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
109 changes: 109 additions & 0 deletions
109
livekit-plugins/livekit-plugins-sarvam/tests/test_tts_validation.py
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,109 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.plugins.sarvam.tts import TTS, validate_model_speaker_compatibility | ||
|
|
||
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "speaker", | ||
| ["anand", "tarun", "sunny", "mani", "gokul", "vijay", "mohit", "rehan", "soham"], | ||
| ) | ||
| def test_bulbul_v3_accepts_documented_speakers(speaker: str) -> None: | ||
| assert validate_model_speaker_compatibility("bulbul:v3", speaker) | ||
|
|
||
|
|
||
| async def test_tts_initialization_accepts_a_documented_bulbul_v3_speaker() -> None: | ||
| tts = TTS(api_key="test-key", model="bulbul:v3", speaker="anand") | ||
| try: | ||
| assert tts._opts.speaker == "anand" | ||
| finally: | ||
| await tts.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("speaker", ["amelia", "sophia"]) | ||
| def test_bulbul_v3_rejects_speakers_not_supported_by_the_model(speaker: str) -> None: | ||
| assert not validate_model_speaker_compatibility("bulbul:v3", speaker) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("speaker", ["amelia", "sophia"]) | ||
| def test_tts_rejects_bulbul_v3_speakers_not_supported_by_the_model(speaker: str) -> None: | ||
| with pytest.raises(ValueError, match="not compatible with model 'bulbul:v3'"): | ||
| TTS(api_key="test-key", model="bulbul:v3", speaker=speaker) | ||
|
|
||
|
|
||
| def test_bulbul_v3_beta_keeps_international_speakers() -> None: | ||
| assert validate_model_speaker_compatibility("bulbul:v3-beta", "amelia") | ||
| assert validate_model_speaker_compatibility("bulbul:v3-beta", "sophia") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("model", "pace"), | ||
| [ | ||
| ("bulbul:v2", 0.3), | ||
| ("bulbul:v2", 3.0), | ||
| ("bulbul:v3-beta", 0.5), | ||
| ("bulbul:v3-beta", 2.0), | ||
| ("bulbul:v3", 0.5), | ||
| ("bulbul:v3", 2.0), | ||
| ], | ||
| ) | ||
| async def test_pace_accepts_the_bounds_for_each_model(model: str, pace: float) -> None: | ||
| tts = TTS(api_key="test-key", model=model, pace=pace) | ||
| try: | ||
| assert tts._opts.pace == pace | ||
| finally: | ||
| await tts.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("model", "pace"), | ||
| [ | ||
| ("bulbul:v3-beta", 0.49), | ||
| ("bulbul:v3-beta", 2.01), | ||
| ("bulbul:v3", 0.49), | ||
| ("bulbul:v3", 2.01), | ||
| ], | ||
| ) | ||
| def test_pace_rejects_values_outside_v3_model_range(model: str, pace: float) -> None: | ||
| with pytest.raises(ValueError, match=rf"Pace for {model} must be between 0.5 and 2.0"): | ||
| TTS(api_key="test-key", model=model, pace=pace) | ||
|
|
||
|
|
||
| async def test_update_options_uses_the_selected_model_pace_range() -> None: | ||
| tts = TTS(api_key="test-key", model="bulbul:v3", pace=1.0) | ||
| try: | ||
| with pytest.raises(ValueError, match="Pace for bulbul:v3 must be between 0.5 and 2.0"): | ||
| tts.update_options(pace=2.5) | ||
| finally: | ||
| await tts.aclose() | ||
|
|
||
|
|
||
| async def test_update_options_rejects_a_model_switch_with_an_invalid_existing_pace() -> None: | ||
| tts = TTS(api_key="test-key", model="bulbul:v2", pace=3.0) | ||
| try: | ||
| with pytest.raises(ValueError, match="Pace for bulbul:v3 must be between 0.5 and 2.0"): | ||
| tts.update_options(model="bulbul:v3") | ||
| finally: | ||
| await tts.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("sample_rate", [32000, 44100, 48000]) | ||
| async def test_rest_only_sample_rates_are_rejected_before_streaming(sample_rate: int) -> None: | ||
| tts = TTS(api_key="test-key", speech_sample_rate=sample_rate) | ||
| try: | ||
| with pytest.raises(ValueError, match="streaming TTS"): | ||
| tts.stream() | ||
| finally: | ||
| await tts.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("sample_rate", [32000, 44100, 48000]) | ||
| async def test_rest_only_sample_rates_remain_valid_for_synthesis(sample_rate: int) -> None: | ||
| tts = TTS(api_key="test-key", speech_sample_rate=sample_rate) | ||
| try: | ||
| assert tts.sample_rate == sample_rate | ||
| finally: | ||
| await tts.aclose() |
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.