diff --git a/assemblyai/__version__.py b/assemblyai/__version__.py index f49459c..51bbb3f 100644 --- a/assemblyai/__version__.py +++ b/assemblyai/__version__.py @@ -1 +1 @@ -__version__ = "1.6.1" +__version__ = "1.6.2" diff --git a/assemblyai/types.py b/assemblyai/types.py index 92377f6..49ce7d9 100644 --- a/assemblyai/types.py +++ b/assemblyai/types.py @@ -2908,6 +2908,13 @@ class SyncTranscriptResponse(BaseModel): session_id: str "Server-generated UUID for this request. Record it to correlate with support." + language_code: Optional[str] = None + """ISO 639-1 language code the model used for this transcript (e.g. ``"en"`` + for English, ``"es"`` for Spanish). Populated when the server detects or is + told the language; ``None`` for responses from servers that predate the field. + Useful when ``language_codes`` was not set and you need to know which language + the model chose.""" + request_time_ms: Optional[float] = None """End-to-end server-side request time in milliseconds: queue wait, auth, multipart parse, decode, inference, and serialization. ``None`` when the diff --git a/tests/unit/test_sync.py b/tests/unit/test_sync.py index 054101c..00d3db4 100644 --- a/tests/unit/test_sync.py +++ b/tests/unit/test_sync.py @@ -71,6 +71,40 @@ def test_transcribe_parses_response_without_request_time(httpx_mock: HTTPXMock): assert result.request_time_ms is None +def test_transcribe_parses_language_code(httpx_mock: HTTPXMock): + # Given a server response that includes the language_code field + response = {**_OK_RESPONSE, "language_code": "es"} + httpx_mock.add_response( + url=TRANSCRIBE_URL, + method="POST", + status_code=httpx.codes.OK, + json=response, + ) + + # When transcribing + result = aai.SyncTranscriber().transcribe(b"RIFFfake-wav-bytes") + + # Then language_code is surfaced on the response + assert result.language_code == "es" + + +def test_transcribe_parses_response_without_language_code(httpx_mock: HTTPXMock): + # Given a server response that predates the language_code field + response = {k: v for k, v in _OK_RESPONSE.items() if k != "language_code"} + httpx_mock.add_response( + url=TRANSCRIBE_URL, + method="POST", + status_code=httpx.codes.OK, + json=response, + ) + + # When transcribing + result = aai.SyncTranscriber().transcribe(b"RIFFfake-wav-bytes") + + # Then language_code is None instead of a parse failure + assert result.language_code is None + + def test_transcribe_sends_model_header_and_wav_part(httpx_mock: HTTPXMock): # Given a mocked sync endpoint _mock_ok(httpx_mock)