Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions sdk/batch/speechmatics/batch/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ class TranscriptionConfig:
defaults to None.
audio_filtering_config: Configuration for limiting the transcription of quiet audio.
Defaults to None.
language_hints: List of languages that are most likely to appear in your audio,
This improves accuracy by biasing recognition toward the specified languages.
Use ``language_hints_strict`` to control whether other languages can also be detected.
Applicable only for the next-gen models. Support for next-gen models is coming soon.
language_hints_strict: Controls how strictly language hints are applied.
When ``True``, the transcript will only contain languages specified in ``language_hints``.
When ``False``, recognition is biased toward the specified languages while still allowing other
languages to be detected if present.
Applicable only for the next-gen models. Support for the next-gen models is coming soon.
language_hints: List of languages that are most likely to appear in your audio.
Recognition is restricted to these languages, which improves accuracy on multilingual
audio. Typically used with ``language="multi"``. Hints take precedence over ``language``,
so the transcript may not contain the language named there.
Applicable only for the next-gen models (e.g. melia-1, oak-1).
language_hints_strict: Controls how strictly ``language_hints`` is applied, and is only valid
alongside it.
Only ``True`` is currently supported: the transcript will contain only the languages
specified in ``language_hints``. This is also what happens when it is left unset.
``False`` is reserved for biasing recognition toward the hinted languages while still
allowing other languages to be detected, which the models do not implement yet.
"""

language: str = "en"
Expand Down
15 changes: 15 additions & 0 deletions sdk/rt/speechmatics/rt/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@ class TranscriptionConfig:
Defaults to None.
operating_point: (Deprecated) Legacy argument for specifying the operating point. Use `model` instead going forward
Defaults to None.
language_hints: (Optional) List of languages that are most likely to appear in your audio.
Recognition is restricted to these languages, which improves accuracy on multilingual
audio. Typically used with ``language="multi"``. Hints take precedence over ``language``,
so the transcript may not contain the language named there.
Applicable only for the next-gen models (e.g. melia-1).
Comment thread
rakeshv247 marked this conversation as resolved.
Defaults to None.
language_hints_strict: (Optional) Controls how strictly ``language_hints`` is applied, and is
only valid alongside it.
Only ``True`` is currently supported: the transcript will contain only the languages
specified in ``language_hints``. This is also what happens when it is left unset.
``False`` is reserved for biasing recognition toward the hinted languages while still
allowing other languages to be detected, which the models do not implement yet.
Defaults to None.

Examples:
Basic English transcription:
Expand Down Expand Up @@ -438,6 +451,8 @@ class TranscriptionConfig:
ctrl: Optional[dict] = None
channel_diarization_labels: Optional[list[str]] = None
operating_point: Optional[OperatingPoint] = None
language_hints: Optional[list[str]] = None
language_hints_strict: Optional[bool] = None

def __post_init__(self) -> None:
if self.model is not _UNSET and self.operating_point is not None:
Expand Down
28 changes: 28 additions & 0 deletions tests/rt/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from speechmatics.rt._models import TranscriptionConfig


class TestLanguageHintsToDict:
def test_language_hints_serializes_correctly(self):
config = TranscriptionConfig(language_hints=["en", "fr"])
result = config.to_dict()
assert result["language_hints"] == ["en", "fr"]
assert "language_hints_strict" not in result

def test_language_hints_strict_true_serializes_correctly(self):
config = TranscriptionConfig(language_hints=["en"], language_hints_strict=True)
result = config.to_dict()
assert result["language_hints"] == ["en"]
assert result["language_hints_strict"] is True

def test_language_hints_strict_false_serializes_correctly(self):
config = TranscriptionConfig(language_hints=["en"], language_hints_strict=False)
result = config.to_dict()
assert result["language_hints"] == ["en"]
assert "language_hints_strict" in result
assert result["language_hints_strict"] is False

def test_language_hints_absent_when_none(self):
config = TranscriptionConfig()
result = config.to_dict()
assert "language_hints" not in result
assert "language_hints_strict" not in result
Loading