TranscriptionClient Class
TranscriptionClient.
Constructor
TranscriptionClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)
Parameters
| Name | Description |
|---|---|
|
endpoint
Required
|
Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com). Required. |
|
credential
Required
|
Credential used to authenticate requests to the service. Is either a key credential type or a token credential type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
api_version
|
The API version to use for this operation. Default value is "2025-10-15". Note that overriding this default value may result in unsupported behavior. |
Methods
| close | |
| send_request |
Runs the network request through the client's chained policies.
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| transcribe |
Transcribes the provided audio stream. |
| transcribe_from_url |
Transcribes audio from a URL. Use this method when the audio is hosted at a URL that the service can access. For transcribing local audio files or byte streams, use transcribe instead. |
close
close() -> None
send_request
Runs the network request through the client's chained policies.
>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse
Parameters
| Name | Description |
|---|---|
|
request
Required
|
The network request you want to make. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
stream
|
Whether the response payload will be streamed. Defaults to False. Default value: False
|
Returns
| Type | Description |
|---|---|
|
The response of your network call. Does not do error handling on your response. |
transcribe
Transcribes the provided audio stream.
transcribe(body: TranscriptionContent | MutableMapping[str, Any], **kwargs: Any) -> TranscriptionResult
Parameters
| Name | Description |
|---|---|
|
body
Required
|
TranscriptionContent or
<xref:JSON>
The body of the multipart request. Is either a TranscriptionContent type or a JSON type. Required. |
Returns
| Type | Description |
|---|---|
|
TranscriptionResult. The TranscriptionResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
transcribe_from_url
Transcribes audio from a URL.
Use this method when the audio is hosted at a URL that the service can access. For transcribing local audio files or byte streams, use transcribe instead.
transcribe_from_url(audio_url: str, *, options: TranscriptionOptions | None = None, **kwargs: Any) -> TranscriptionResult
Parameters
| Name | Description |
|---|---|
|
audio_url
Required
|
The URL of the audio file to transcribe. The audio must be shorter than 2 hours in duration and smaller than 250 MB in size. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
options
|
Optional transcription configuration. If provided, the audio_url parameter will override the audio_url field in the options object. Default value: None
|
Returns
| Type | Description |
|---|---|
|
TranscriptionResult with the transcription text and phrases. |
Exceptions
| Type | Description |
|---|---|
Examples
Transcribe audio from a URL.
from azure.core.credentials import AzureKeyCredential
from azure.ai.transcription import TranscriptionClient
from azure.ai.transcription.models import TranscriptionOptions
# Get configuration from environment variables
endpoint = os.environ["AZURE_SPEECH_ENDPOINT"]
# We recommend using role-based access control (RBAC) for production scenarios
api_key = os.environ.get("AZURE_SPEECH_API_KEY")
if api_key:
credential = AzureKeyCredential(api_key)
else:
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
# Create the transcription client
client = TranscriptionClient(endpoint=endpoint, credential=credential)
# URL to your audio file (must be publicly accessible)
audio_url = "https://example.com/path/to/audio.wav"
# Configure transcription options
options = TranscriptionOptions(locales=["en-US"])
# Transcribe the audio from URL
# The service will access and transcribe the audio directly from the URL
result = client.transcribe_from_url(audio_url, options=options)
# Print the transcription result
print(f"Transcription: {result.combined_phrases[0].text}")
# Print duration information
if result.duration_milliseconds:
print(f"Audio duration: {result.duration_milliseconds / 1000:.2f} seconds")