diff --git a/sdk/batch/speechmatics/batch/__init__.py b/sdk/batch/speechmatics/batch/__init__.py index fd9b698..54aeb48 100644 --- a/sdk/batch/speechmatics/batch/__init__.py +++ b/sdk/batch/speechmatics/batch/__init__.py @@ -35,11 +35,13 @@ from ._models import TranscriptFilteringConfig from ._models import TranscriptionConfig from ._models import TranslationConfig +from ._transport import EAR_TAG_HEADER from ._transport import PROCESSING_DATA_HEADER __all__ = [ "AudioFilteringConfig", "AsyncClient", + "EAR_TAG_HEADER", "PROCESSING_DATA_HEADER", "AuthBase", "AuthenticationError", diff --git a/sdk/batch/speechmatics/batch/_async_client.py b/sdk/batch/speechmatics/batch/_async_client.py index 873218b..a409001 100644 --- a/sdk/batch/speechmatics/batch/_async_client.py +++ b/sdk/batch/speechmatics/batch/_async_client.py @@ -31,6 +31,7 @@ from ._models import JobType from ._models import Transcript from ._models import TranscriptionConfig +from ._transport import EAR_TAG_HEADER from ._transport import PROCESSING_DATA_HEADER from ._transport import Transport @@ -142,6 +143,7 @@ async def submit_job( transcription_config: Optional[TranscriptionConfig] = None, parallel_engines: Optional[int] = None, user_id: Optional[str] = None, + ear_tag: Optional[str] = None, ) -> JobDetails: """ Submit a new transcription job. @@ -163,6 +165,7 @@ async def submit_job( user_id: Optional user identifier to associate with this job. Sent as ``{"user_id": "..."}`` in the ``X-SM-Processing-Data`` header. This only applies when using the container onPrem on http batch mode. + ear_tag: Optional Early Access Release tag sent as ``X-SM-EAR-Tag`` header. Returns: JobDetails object containing the job ID and initial status. @@ -210,7 +213,7 @@ async def submit_job( multipart_data, filename = await self._prepare_file_submission(audio_file, config_dict) return await self._submit_and_create_job_details( - multipart_data, filename, config, parallel_engines, user_id + multipart_data, filename, config, parallel_engines, user_id, ear_tag ) except Exception as e: if isinstance(e, (AuthenticationError, BatchError)): @@ -448,6 +451,7 @@ async def transcribe( timeout: Optional[float] = None, parallel_engines: Optional[int] = None, user_id: Optional[str] = None, + ear_tag: Optional[str] = None, ) -> Union[Transcript, str]: """ Complete transcription workflow: submit job and wait for completion. @@ -467,6 +471,7 @@ async def transcribe( user_id: Optional user identifier to associate with this job. Sent as ``{"user_id": "..."}`` in the ``X-SM-Processing-Data`` header. This only applies when using the container onPrem on http batch mode. + ear_tag: Optional Early Access Release tag sent as ``X-SM-EAR-Tag`` header. Returns: Transcript object containing the transcript and metadata. @@ -496,6 +501,7 @@ async def transcribe( transcription_config=transcription_config, parallel_engines=parallel_engines, user_id=user_id, + ear_tag=ear_tag, ) # Wait for completion and return result @@ -555,16 +561,19 @@ async def _submit_and_create_job_details( config: JobConfig, parallel_engines: Optional[int] = None, user_id: Optional[str] = None, + ear_tag: Optional[str] = None, ) -> JobDetails: """Submit job and create JobDetails response.""" - extra_headers: Optional[dict[str, Any]] = None + extra_headers: dict[str, Any] = {} processing_data: dict[str, Any] = {} if parallel_engines is not None: processing_data["parallel_engines"] = parallel_engines if user_id is not None: processing_data["user_id"] = user_id if processing_data: - extra_headers = {PROCESSING_DATA_HEADER: processing_data} + extra_headers[PROCESSING_DATA_HEADER] = processing_data + if ear_tag is not None: + extra_headers[EAR_TAG_HEADER] = ear_tag response = await self._transport.post("/jobs", multipart_data=multipart_data, extra_headers=extra_headers) job_id = response.get("id") if not job_id: diff --git a/sdk/batch/speechmatics/batch/_transport.py b/sdk/batch/speechmatics/batch/_transport.py index 4beb3d6..1d2e667 100644 --- a/sdk/batch/speechmatics/batch/_transport.py +++ b/sdk/batch/speechmatics/batch/_transport.py @@ -27,6 +27,7 @@ from ._models import ConnectionConfig PROCESSING_DATA_HEADER = "X-SM-Processing-Data" +EAR_TAG_HEADER = "X-SM-EAR-Tag" class Transport: @@ -313,9 +314,9 @@ async def _prepare_headers(self) -> dict[str, str]: Headers dictionary with authentication and tracking info """ auth_headers = await self._auth.get_auth_headers() - auth_headers["User-Agent"] = ( - f"speechmatics-batch-v{get_version()} python/{sys.version_info.major}.{sys.version_info.minor}" - ) + auth_headers[ + "User-Agent" + ] = f"speechmatics-batch-v{get_version()} python/{sys.version_info.major}.{sys.version_info.minor}" if self._request_id: auth_headers["X-Request-Id"] = self._request_id