Skip to content

Commit 45d8483

Browse files
dmccrystals0h3yl
authored andcommitted
feat: add speech_threshold
GitOrigin-RevId: e4fdb960f375bd01c3d79f3bc85bc346fcaf9368
1 parent 3098a70 commit 45d8483

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

assemblyai/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ class RawTranscriptionConfig(BaseModel):
413413
- Dutch
414414
"""
415415

416+
speech_threshold: Optional[float]
417+
"Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive"
418+
416419
class Config:
417420
extra = Extra.allow
418421

@@ -451,6 +454,7 @@ def __init__(
451454
summary_type: Optional[SummarizationType] = None,
452455
auto_highlights: Optional[bool] = None,
453456
language_detection: Optional[bool] = None,
457+
speech_threshold: Optional[float] = None,
454458
raw_transcription_config: Optional[RawTranscriptionConfig] = None,
455459
) -> None:
456460
"""
@@ -485,6 +489,7 @@ def __init__(
485489
summary_type: The summarization type to use in case `summarization` is enabled
486490
auto_highlights: Detect important phrases and words in your transcription text.
487491
language_detection: Identify the dominant language that’s spoken in an audio file, and route the file to the appropriate model for the detected language.
492+
speech_threshold: Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive
488493
raw_transcription_config: Create the config from a `RawTranscriptionConfig`
489494
"""
490495
self._raw_transcription_config = raw_transcription_config
@@ -529,6 +534,7 @@ def __init__(
529534
)
530535
self.auto_highlights = auto_highlights
531536
self.language_detection = language_detection
537+
self.speech_threshold = speech_threshold
532538

533539
@property
534540
def raw(self) -> RawTranscriptionConfig:
@@ -854,6 +860,21 @@ def language_detection(self, enable: Optional[bool]) -> None:
854860

855861
self._raw_transcription_config.language_detection = enable
856862

863+
@property
864+
def speech_threshold(self) -> Optional[float]:
865+
"Returns the current speech threshold."
866+
867+
return self._raw_transcription_config.speech_threshold
868+
869+
@speech_threshold.setter
870+
def speech_threshold(self, threshold: Optional[float]) -> None:
871+
"Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive"
872+
873+
if threshold is not None and (threshold < 0 or threshold > 1):
874+
raise ValueError("speech_threshold must be between 0 and 1 (inclusive).")
875+
876+
self._raw_transcription_config.speech_threshold = threshold
877+
857878
# endregion
858879

859880
# region: Convenience (helper) methods
@@ -1434,6 +1455,9 @@ class BaseTranscript(BaseModel):
14341455
- Dutch
14351456
"""
14361457

1458+
speech_threshold: Optional[float]
1459+
"Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive"
1460+
14371461

14381462
class TranscriptRequest(BaseTranscript):
14391463
"""

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
setup(
99
name="assemblyai",
10-
version="0.11.0",
10+
version="0.7.1",
1111
description="AssemblyAI Python SDK",
1212
author="AssemblyAI",
1313
author_email="engineering.sdk@assemblyai.com",
1414
packages=find_packages(),
1515
install_requires=[
1616
"httpx>=0.19.0",
1717
"pydantic>=1.7.0",
18-
"typing-extensions>=3.7,<4.6",
19-
"websockets>=11.0",
18+
"typing-extensions",
19+
"websockets>=10.0",
2020
],
2121
extras_require={
22-
"extras": ["pyaudio>=0.2.13"],
22+
"extras": ["pyaudio"],
2323
},
2424
classifiers=[
2525
"Development Status :: 3 - Alpha",

tests/unit/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Meta:
9090
summary_type = None
9191
auto_highlights = False
9292
language_detection = False
93+
speech_threshold = None
9394

9495

9596
class TranscriptCompletedResponseFactory(BaseTranscriptFactory):

tests/unit/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ def test_configuration_are_none_by_default():
1818
pytest.fail(
1919
f"Configuration field {name} is {value} and not None by default."
2020
)
21+
22+
23+
def test_speech_threshold_fails_if_outside_range():
24+
"""
25+
Tests that an exception is raised if the value for speech_threshold is outside the range of [0, 1].
26+
"""
27+
28+
with pytest.raises(ValueError, match="speech_threshold"):
29+
aai.TranscriptionConfig(speech_threshold=1.5)
30+
with pytest.raises(ValueError, match="speech_threshold"):
31+
aai.TranscriptionConfig(speech_threshold=-0.5)

tests/unit/test_transcript_group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import uuid
22

3+
import assemblyai as aai
34
import assemblyai as aai
45
from tests.unit import factories
56

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ deps =
1616
pydantic1.9: pydantic>=1.9.0,<1.10.0
1717
pydantic1.8: pydantic>=1.8.0,<1.9.0
1818
pydantic1.7: pydantic>=1.7.0,<1.8.0
19-
typing-extensions: typing-extensions>=3.7,<4.6
19+
typing-extensions: typing-extensions>=3.7
2020
# extra dependencies
21-
pyaudiolatest: pyaudio
21+
pyaudio: pyaudio
2222
pyaudio0.2: pyaudio>=0.2.13,<0.3.0
2323
# test dependencies
2424
pytest
2525
pytest-httpx
2626
pytest-xdist
27-
pytest-mock
2827
pytest-cov
2928
factory-boy
3029
allowlist_externals = pytest

0 commit comments

Comments
 (0)