Skip to content

Commit d7893e2

Browse files
he-jamesarawka-aai
andauthored
chore: sync sdk code with DeepLearning repo (#149)
Co-authored-by: AssemblyAI <[email protected]> and Abhi Rawka <[email protected]>
1 parent eda1a7c commit d7893e2

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

assemblyai/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.46.0"
1+
__version__ = "0.48.0"

assemblyai/types.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ class LanguageDetectionOptions(BaseModel):
507507
None,
508508
description="The confidence threshold for code switching detection. Valid values are in the range [0,1] inclusive.",
509509
)
510+
on_low_language_confidence: Optional[str] = Field(
511+
None,
512+
description='Controls behavior when language confidence is below threshold. Either "error" (default) or "fallback".',
513+
)
510514

511515

512516
class CodeSwitchingLanguage(BaseModel):
@@ -681,6 +685,10 @@ class SpeakerOptions(BaseModel):
681685
max_speakers_expected: Optional[int] = Field(
682686
None, ge=1, description="Maximum number of speakers expected in the audio"
683687
)
688+
use_two_stage_clustering: Optional[bool] = Field(
689+
None,
690+
description="Enable or disable two-stage clustering for speaker diarization",
691+
)
684692

685693
if pydantic_v2:
686694

@@ -1702,6 +1710,7 @@ def set_language_detection(
17021710
confidence_threshold: Optional[float] = None,
17031711
expected_languages: Optional[List[str]] = None,
17041712
fallback_language: Optional[str] = None,
1713+
on_low_language_confidence: Optional[str] = None,
17051714
) -> Self:
17061715
"""
17071716
Enable Automatic Language Detection with optional configuration.
@@ -1711,6 +1720,7 @@ def set_language_detection(
17111720
confidence_threshold: The confidence threshold that must be reached.
17121721
expected_languages: A list of languages that the audio could be expected to be.
17131722
fallback_language: The language to fallback to if detection fails.
1723+
on_low_language_confidence: Controls behavior when language confidence is below threshold. Either "error" (default) or "fallback".
17141724
"""
17151725

17161726
if not enable:
@@ -1724,11 +1734,12 @@ def set_language_detection(
17241734
confidence_threshold
17251735
)
17261736

1727-
if expected_languages or fallback_language:
1737+
if expected_languages or fallback_language or on_low_language_confidence:
17281738
self._raw_transcription_config.language_detection_options = (
17291739
LanguageDetectionOptions(
17301740
expected_languages=expected_languages,
17311741
fallback_language=fallback_language,
1742+
on_low_language_confidence=on_low_language_confidence,
17321743
)
17331744
)
17341745

tests/unit/test_language_detection_options.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,68 @@ def test_set_language_detection_disable():
127127
assert config.language_detection is None
128128
assert config.language_confidence_threshold is None
129129
assert config.language_detection_options is None
130+
131+
132+
def test_language_detection_options_with_on_low_language_confidence():
133+
"""Test that LanguageDetectionOptions accepts on_low_language_confidence parameter."""
134+
options = aai.LanguageDetectionOptions(
135+
expected_languages=["en", "es"],
136+
fallback_language="en",
137+
on_low_language_confidence="fallback",
138+
)
139+
assert options.expected_languages == ["en", "es"]
140+
assert options.fallback_language == "en"
141+
assert options.on_low_language_confidence == "fallback"
142+
143+
144+
def test_language_detection_options_on_low_confidence_only():
145+
"""Test that LanguageDetectionOptions can be created with only on_low_language_confidence."""
146+
options = aai.LanguageDetectionOptions(on_low_language_confidence="error")
147+
assert options.expected_languages is None
148+
assert options.fallback_language is None
149+
assert options.on_low_language_confidence == "error"
150+
151+
152+
def test_set_language_detection_with_on_low_confidence():
153+
"""Test the set_language_detection method with on_low_language_confidence."""
154+
config = aai.TranscriptionConfig().set_language_detection(
155+
confidence_threshold=0.8,
156+
expected_languages=["en", "fr"],
157+
fallback_language="en",
158+
on_low_language_confidence="fallback",
159+
)
160+
161+
assert config.language_detection is True
162+
assert config.language_confidence_threshold == 0.8
163+
assert config.language_detection_options.expected_languages == ["en", "fr"]
164+
assert config.language_detection_options.fallback_language == "en"
165+
assert config.language_detection_options.on_low_language_confidence == "fallback"
166+
167+
168+
def test_set_language_detection_on_low_confidence_only():
169+
"""Test set_language_detection with only on_low_language_confidence parameter."""
170+
config = aai.TranscriptionConfig().set_language_detection(
171+
on_low_language_confidence="error"
172+
)
173+
174+
assert config.language_detection is True
175+
assert config.language_detection_options is not None
176+
assert config.language_detection_options.on_low_language_confidence == "error"
177+
178+
179+
def test_transcription_config_with_on_low_confidence_in_options():
180+
"""Test that TranscriptionConfig properly handles on_low_language_confidence in options."""
181+
options = aai.LanguageDetectionOptions(
182+
fallback_language="en", on_low_language_confidence="fallback"
183+
)
184+
185+
config = aai.TranscriptionConfig(
186+
language_detection=True,
187+
language_confidence_threshold=0.9,
188+
language_detection_options=options,
189+
)
190+
191+
assert config.language_detection is True
192+
assert config.language_confidence_threshold == 0.9
193+
assert config.language_detection_options.fallback_language == "en"
194+
assert config.language_detection_options.on_low_language_confidence == "fallback"

tests/unit/test_speaker_options.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,36 @@ def test_speaker_options_in_raw_config():
9494
config = aai.TranscriptionConfig(speaker_options=speaker_options)
9595

9696
assert config.raw.speaker_options == speaker_options
97+
98+
99+
def test_speaker_options_with_two_stage_clustering():
100+
"""Test that SpeakerOptions can be created with use_two_stage_clustering parameter."""
101+
speaker_options = aai.SpeakerOptions(
102+
min_speakers_expected=2,
103+
max_speakers_expected=5,
104+
use_two_stage_clustering=False,
105+
)
106+
assert speaker_options.min_speakers_expected == 2
107+
assert speaker_options.max_speakers_expected == 5
108+
assert speaker_options.use_two_stage_clustering is False
109+
110+
111+
def test_speaker_options_two_stage_clustering_true():
112+
"""Test that use_two_stage_clustering can be set to True."""
113+
speaker_options = aai.SpeakerOptions(use_two_stage_clustering=True)
114+
assert speaker_options.use_two_stage_clustering is True
115+
116+
117+
def test_transcription_config_with_two_stage_clustering():
118+
"""Test that TranscriptionConfig accepts speaker_options with use_two_stage_clustering."""
119+
speaker_options = aai.SpeakerOptions(
120+
min_speakers_expected=2, max_speakers_expected=4, use_two_stage_clustering=False
121+
)
122+
123+
config = aai.TranscriptionConfig(
124+
speaker_labels=True, speaker_options=speaker_options
125+
)
126+
127+
assert config.speaker_labels is True
128+
assert config.speaker_options == speaker_options
129+
assert config.speaker_options.use_two_stage_clustering is False

0 commit comments

Comments
 (0)