azure-ai-transcription 1.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azure/ai/transcription/__init__.py +32 -0
- azure/ai/transcription/_client.py +103 -0
- azure/ai/transcription/_configuration.py +73 -0
- azure/ai/transcription/_operations/__init__.py +23 -0
- azure/ai/transcription/_operations/_operations.py +151 -0
- azure/ai/transcription/_operations/_patch.py +118 -0
- azure/ai/transcription/_patch.py +21 -0
- azure/ai/transcription/_utils/__init__.py +6 -0
- azure/ai/transcription/_utils/model_base.py +1237 -0
- azure/ai/transcription/_utils/serialization.py +2030 -0
- azure/ai/transcription/_utils/utils.py +67 -0
- azure/ai/transcription/_version.py +9 -0
- azure/ai/transcription/aio/__init__.py +29 -0
- azure/ai/transcription/aio/_client.py +107 -0
- azure/ai/transcription/aio/_configuration.py +75 -0
- azure/ai/transcription/aio/_operations/__init__.py +23 -0
- azure/ai/transcription/aio/_operations/_operations.py +131 -0
- azure/ai/transcription/aio/_operations/_patch.py +116 -0
- azure/ai/transcription/aio/_patch.py +21 -0
- azure/ai/transcription/models/__init__.py +48 -0
- azure/ai/transcription/models/_enums.py +23 -0
- azure/ai/transcription/models/_models.py +450 -0
- azure/ai/transcription/models/_patch.py +21 -0
- azure/ai/transcription/py.typed +1 -0
- azure_ai_transcription-1.0.0b1.dist-info/METADATA +471 -0
- azure_ai_transcription-1.0.0b1.dist-info/RECORD +29 -0
- azure_ai_transcription-1.0.0b1.dist-info/WHEEL +5 -0
- azure_ai_transcription-1.0.0b1.dist-info/licenses/LICENSE +21 -0
- azure_ai_transcription-1.0.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=wrong-import-position
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ._patch import * # pylint: disable=unused-wildcard-import
|
|
14
|
+
|
|
15
|
+
from ._client import TranscriptionClient # type: ignore
|
|
16
|
+
from ._version import VERSION
|
|
17
|
+
|
|
18
|
+
__version__ = VERSION
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from ._patch import __all__ as _patch_all
|
|
22
|
+
from ._patch import *
|
|
23
|
+
except ImportError:
|
|
24
|
+
_patch_all = []
|
|
25
|
+
from ._patch import patch_sdk as _patch_sdk
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"TranscriptionClient",
|
|
29
|
+
]
|
|
30
|
+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
|
|
31
|
+
|
|
32
|
+
_patch_sdk()
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
from copy import deepcopy
|
|
10
|
+
from typing import Any, TYPE_CHECKING, Union
|
|
11
|
+
from typing_extensions import Self
|
|
12
|
+
|
|
13
|
+
from azure.core import PipelineClient
|
|
14
|
+
from azure.core.credentials import AzureKeyCredential
|
|
15
|
+
from azure.core.pipeline import policies
|
|
16
|
+
from azure.core.rest import HttpRequest, HttpResponse
|
|
17
|
+
|
|
18
|
+
from ._configuration import TranscriptionClientConfiguration
|
|
19
|
+
from ._operations import _TranscriptionClientOperationsMixin
|
|
20
|
+
from ._utils.serialization import Deserializer, Serializer
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from azure.core.credentials import TokenCredential
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TranscriptionClient(_TranscriptionClientOperationsMixin):
|
|
27
|
+
"""TranscriptionClient.
|
|
28
|
+
|
|
29
|
+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
|
|
30
|
+
`https://westus.api.cognitive.microsoft.com <https://westus.api.cognitive.microsoft.com>`_.
|
|
31
|
+
Required.
|
|
32
|
+
:type endpoint: str
|
|
33
|
+
:param credential: Credential used to authenticate requests to the service. Is either a key
|
|
34
|
+
credential type or a token credential type. Required.
|
|
35
|
+
:type credential: ~azure.core.credentials.AzureKeyCredential or
|
|
36
|
+
~azure.core.credentials.TokenCredential
|
|
37
|
+
:keyword api_version: The API version to use for this operation. Default value is "2025-10-15".
|
|
38
|
+
Note that overriding this default value may result in unsupported behavior.
|
|
39
|
+
:paramtype api_version: str
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
|
|
43
|
+
_endpoint = "{endpoint}/speechtotext"
|
|
44
|
+
self._config = TranscriptionClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
|
|
45
|
+
|
|
46
|
+
_policies = kwargs.pop("policies", None)
|
|
47
|
+
if _policies is None:
|
|
48
|
+
_policies = [
|
|
49
|
+
policies.RequestIdPolicy(**kwargs),
|
|
50
|
+
self._config.headers_policy,
|
|
51
|
+
self._config.user_agent_policy,
|
|
52
|
+
self._config.proxy_policy,
|
|
53
|
+
policies.ContentDecodePolicy(**kwargs),
|
|
54
|
+
self._config.redirect_policy,
|
|
55
|
+
self._config.retry_policy,
|
|
56
|
+
self._config.authentication_policy,
|
|
57
|
+
self._config.custom_hook_policy,
|
|
58
|
+
self._config.logging_policy,
|
|
59
|
+
policies.DistributedTracingPolicy(**kwargs),
|
|
60
|
+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
|
|
61
|
+
self._config.http_logging_policy,
|
|
62
|
+
]
|
|
63
|
+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
|
|
64
|
+
|
|
65
|
+
self._serialize = Serializer()
|
|
66
|
+
self._deserialize = Deserializer()
|
|
67
|
+
self._serialize.client_side_validation = False
|
|
68
|
+
|
|
69
|
+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
|
|
70
|
+
"""Runs the network request through the client's chained policies.
|
|
71
|
+
|
|
72
|
+
>>> from azure.core.rest import HttpRequest
|
|
73
|
+
>>> request = HttpRequest("GET", "https://www.example.org/")
|
|
74
|
+
<HttpRequest [GET], url: 'https://www.example.org/'>
|
|
75
|
+
>>> response = client.send_request(request)
|
|
76
|
+
<HttpResponse: 200 OK>
|
|
77
|
+
|
|
78
|
+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
|
|
79
|
+
|
|
80
|
+
:param request: The network request you want to make. Required.
|
|
81
|
+
:type request: ~azure.core.rest.HttpRequest
|
|
82
|
+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
|
|
83
|
+
:return: The response of your network call. Does not do error handling on your response.
|
|
84
|
+
:rtype: ~azure.core.rest.HttpResponse
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
request_copy = deepcopy(request)
|
|
88
|
+
path_format_arguments = {
|
|
89
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
|
|
93
|
+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
|
|
94
|
+
|
|
95
|
+
def close(self) -> None:
|
|
96
|
+
self._client.close()
|
|
97
|
+
|
|
98
|
+
def __enter__(self) -> Self:
|
|
99
|
+
self._client.__enter__()
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
def __exit__(self, *exc_details: Any) -> None:
|
|
103
|
+
self._client.__exit__(*exc_details)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
from typing import Any, TYPE_CHECKING, Union
|
|
10
|
+
|
|
11
|
+
from azure.core.credentials import AzureKeyCredential
|
|
12
|
+
from azure.core.pipeline import policies
|
|
13
|
+
|
|
14
|
+
from ._version import VERSION
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from azure.core.credentials import TokenCredential
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TranscriptionClientConfiguration: # pylint: disable=too-many-instance-attributes
|
|
21
|
+
"""Configuration for TranscriptionClient.
|
|
22
|
+
|
|
23
|
+
Note that all parameters used to create this instance are saved as instance
|
|
24
|
+
attributes.
|
|
25
|
+
|
|
26
|
+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
|
|
27
|
+
`https://westus.api.cognitive.microsoft.com <https://westus.api.cognitive.microsoft.com>`_.
|
|
28
|
+
Required.
|
|
29
|
+
:type endpoint: str
|
|
30
|
+
:param credential: Credential used to authenticate requests to the service. Is either a key
|
|
31
|
+
credential type or a token credential type. Required.
|
|
32
|
+
:type credential: ~azure.core.credentials.AzureKeyCredential or
|
|
33
|
+
~azure.core.credentials.TokenCredential
|
|
34
|
+
:keyword api_version: The API version to use for this operation. Default value is "2025-10-15".
|
|
35
|
+
Note that overriding this default value may result in unsupported behavior.
|
|
36
|
+
:paramtype api_version: str
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
|
|
40
|
+
api_version: str = kwargs.pop("api_version", "2025-10-15")
|
|
41
|
+
|
|
42
|
+
if endpoint is None:
|
|
43
|
+
raise ValueError("Parameter 'endpoint' must not be None.")
|
|
44
|
+
if credential is None:
|
|
45
|
+
raise ValueError("Parameter 'credential' must not be None.")
|
|
46
|
+
|
|
47
|
+
self.endpoint = endpoint
|
|
48
|
+
self.credential = credential
|
|
49
|
+
self.api_version = api_version
|
|
50
|
+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
|
|
51
|
+
kwargs.setdefault("sdk_moniker", "ai-transcription/{}".format(VERSION))
|
|
52
|
+
self.polling_interval = kwargs.get("polling_interval", 30)
|
|
53
|
+
self._configure(**kwargs)
|
|
54
|
+
|
|
55
|
+
def _infer_policy(self, **kwargs):
|
|
56
|
+
if isinstance(self.credential, AzureKeyCredential):
|
|
57
|
+
return policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
|
|
58
|
+
if hasattr(self.credential, "get_token"):
|
|
59
|
+
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
|
|
60
|
+
raise TypeError(f"Unsupported credential: {self.credential}")
|
|
61
|
+
|
|
62
|
+
def _configure(self, **kwargs: Any) -> None:
|
|
63
|
+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
|
|
64
|
+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
|
|
65
|
+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
|
|
66
|
+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
|
|
67
|
+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
|
|
68
|
+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
|
|
69
|
+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
|
|
70
|
+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
|
|
71
|
+
self.authentication_policy = kwargs.get("authentication_policy")
|
|
72
|
+
if self.credential and not self.authentication_policy:
|
|
73
|
+
self.authentication_policy = self._infer_policy(**kwargs)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=wrong-import-position
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ._patch import * # pylint: disable=unused-wildcard-import
|
|
14
|
+
|
|
15
|
+
from ._operations import _TranscriptionClientOperationsMixin # type: ignore # pylint: disable=unused-import
|
|
16
|
+
|
|
17
|
+
from ._patch import __all__ as _patch_all
|
|
18
|
+
from ._patch import *
|
|
19
|
+
from ._patch import patch_sdk as _patch_sdk
|
|
20
|
+
|
|
21
|
+
__all__ = []
|
|
22
|
+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
|
|
23
|
+
_patch_sdk()
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
from collections.abc import MutableMapping
|
|
9
|
+
from typing import Any, Callable, Optional, TypeVar, Union, overload
|
|
10
|
+
|
|
11
|
+
from azure.core import PipelineClient
|
|
12
|
+
from azure.core.exceptions import (
|
|
13
|
+
ClientAuthenticationError,
|
|
14
|
+
HttpResponseError,
|
|
15
|
+
ResourceExistsError,
|
|
16
|
+
ResourceNotFoundError,
|
|
17
|
+
ResourceNotModifiedError,
|
|
18
|
+
StreamClosedError,
|
|
19
|
+
StreamConsumedError,
|
|
20
|
+
map_error,
|
|
21
|
+
)
|
|
22
|
+
from azure.core.pipeline import PipelineResponse
|
|
23
|
+
from azure.core.rest import HttpRequest, HttpResponse
|
|
24
|
+
from azure.core.tracing.decorator import distributed_trace
|
|
25
|
+
from azure.core.utils import case_insensitive_dict
|
|
26
|
+
|
|
27
|
+
from .. import models as _models
|
|
28
|
+
from .._configuration import TranscriptionClientConfiguration
|
|
29
|
+
from .._utils.model_base import Model as _Model, _deserialize
|
|
30
|
+
from .._utils.serialization import Serializer
|
|
31
|
+
from .._utils.utils import ClientMixinABC, prepare_multipart_form_data
|
|
32
|
+
|
|
33
|
+
JSON = MutableMapping[str, Any]
|
|
34
|
+
T = TypeVar("T")
|
|
35
|
+
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]]
|
|
36
|
+
|
|
37
|
+
_SERIALIZER = Serializer()
|
|
38
|
+
_SERIALIZER.client_side_validation = False
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_transcription_transcribe_request(**kwargs: Any) -> HttpRequest:
|
|
42
|
+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
|
|
43
|
+
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
|
|
44
|
+
|
|
45
|
+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-10-15"))
|
|
46
|
+
accept = _headers.pop("Accept", "application/json")
|
|
47
|
+
|
|
48
|
+
# Construct URL
|
|
49
|
+
_url = "/transcriptions:transcribe"
|
|
50
|
+
|
|
51
|
+
# Construct parameters
|
|
52
|
+
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
|
|
53
|
+
|
|
54
|
+
# Construct headers
|
|
55
|
+
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
|
|
56
|
+
|
|
57
|
+
return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class _TranscriptionClientOperationsMixin(
|
|
61
|
+
ClientMixinABC[PipelineClient[HttpRequest, HttpResponse], TranscriptionClientConfiguration]
|
|
62
|
+
):
|
|
63
|
+
|
|
64
|
+
@overload
|
|
65
|
+
def transcribe(self, body: _models.TranscriptionContent, **kwargs: Any) -> _models.TranscriptionResult:
|
|
66
|
+
"""Transcribes the provided audio stream.
|
|
67
|
+
|
|
68
|
+
:param body: The body of the multipart request. Required.
|
|
69
|
+
:type body: ~azure.ai.transcription.models.TranscriptionContent
|
|
70
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
71
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
72
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
@overload
|
|
76
|
+
def transcribe(self, body: JSON, **kwargs: Any) -> _models.TranscriptionResult:
|
|
77
|
+
"""Transcribes the provided audio stream.
|
|
78
|
+
|
|
79
|
+
:param body: The body of the multipart request. Required.
|
|
80
|
+
:type body: JSON
|
|
81
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
82
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
83
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
@distributed_trace
|
|
87
|
+
def transcribe(self, body: Union[_models.TranscriptionContent, JSON], **kwargs: Any) -> _models.TranscriptionResult:
|
|
88
|
+
"""Transcribes the provided audio stream.
|
|
89
|
+
|
|
90
|
+
:param body: The body of the multipart request. Is either a TranscriptionContent type or a JSON
|
|
91
|
+
type. Required.
|
|
92
|
+
:type body: ~azure.ai.transcription.models.TranscriptionContent or JSON
|
|
93
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
94
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
95
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
96
|
+
"""
|
|
97
|
+
error_map: MutableMapping = {
|
|
98
|
+
401: ClientAuthenticationError,
|
|
99
|
+
404: ResourceNotFoundError,
|
|
100
|
+
409: ResourceExistsError,
|
|
101
|
+
304: ResourceNotModifiedError,
|
|
102
|
+
}
|
|
103
|
+
error_map.update(kwargs.pop("error_map", {}) or {})
|
|
104
|
+
|
|
105
|
+
_headers = kwargs.pop("headers", {}) or {}
|
|
106
|
+
_params = kwargs.pop("params", {}) or {}
|
|
107
|
+
|
|
108
|
+
cls: ClsType[_models.TranscriptionResult] = kwargs.pop("cls", None)
|
|
109
|
+
|
|
110
|
+
_body = body.as_dict() if isinstance(body, _Model) else body
|
|
111
|
+
_file_fields: list[str] = ["audio"]
|
|
112
|
+
_data_fields: list[str] = ["definition"]
|
|
113
|
+
_files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields)
|
|
114
|
+
|
|
115
|
+
_request = build_transcription_transcribe_request(
|
|
116
|
+
api_version=self._config.api_version,
|
|
117
|
+
files=_files,
|
|
118
|
+
data=_data,
|
|
119
|
+
headers=_headers,
|
|
120
|
+
params=_params,
|
|
121
|
+
)
|
|
122
|
+
path_format_arguments = {
|
|
123
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
124
|
+
}
|
|
125
|
+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
|
|
126
|
+
|
|
127
|
+
_stream = kwargs.pop("stream", False)
|
|
128
|
+
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
|
|
129
|
+
_request, stream=_stream, **kwargs
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
response = pipeline_response.http_response
|
|
133
|
+
|
|
134
|
+
if response.status_code not in [200]:
|
|
135
|
+
if _stream:
|
|
136
|
+
try:
|
|
137
|
+
response.read() # Load the body in memory and close the socket
|
|
138
|
+
except (StreamConsumedError, StreamClosedError):
|
|
139
|
+
pass
|
|
140
|
+
map_error(status_code=response.status_code, response=response, error_map=error_map)
|
|
141
|
+
raise HttpResponseError(response=response)
|
|
142
|
+
|
|
143
|
+
if _stream:
|
|
144
|
+
deserialized = response.iter_bytes()
|
|
145
|
+
else:
|
|
146
|
+
deserialized = _deserialize(_models.TranscriptionResult, response.json())
|
|
147
|
+
|
|
148
|
+
if cls:
|
|
149
|
+
return cls(pipeline_response, deserialized, {}) # type: ignore
|
|
150
|
+
|
|
151
|
+
return deserialized # type: ignore
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# pylint: disable=line-too-long,useless-suppression
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
# --------------------------------------------------------------------------
|
|
7
|
+
"""Customize generated code here.
|
|
8
|
+
|
|
9
|
+
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
10
|
+
"""
|
|
11
|
+
from collections.abc import MutableMapping
|
|
12
|
+
from typing import Any, Optional
|
|
13
|
+
import json
|
|
14
|
+
from azure.core.tracing.decorator import distributed_trace
|
|
15
|
+
from azure.core.exceptions import map_error, HttpResponseError, ClientAuthenticationError, ResourceNotFoundError, ResourceExistsError, ResourceNotModifiedError
|
|
16
|
+
|
|
17
|
+
from .. import models as _models
|
|
18
|
+
from .._utils.model_base import _deserialize, SdkJSONEncoder
|
|
19
|
+
from ._operations import (
|
|
20
|
+
_TranscriptionClientOperationsMixin as _TranscriptionClientOperationsMixinGenerated,
|
|
21
|
+
build_transcription_transcribe_request,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
JSON = MutableMapping[str, Any]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _TranscriptionClientOperationsMixin(_TranscriptionClientOperationsMixinGenerated):
|
|
28
|
+
"""Custom operations mixin for TranscriptionClient."""
|
|
29
|
+
|
|
30
|
+
@distributed_trace
|
|
31
|
+
def transcribe_from_url(
|
|
32
|
+
self, audio_url: str, *, options: Optional[_models.TranscriptionOptions] = None, **kwargs: Any
|
|
33
|
+
) -> _models.TranscriptionResult:
|
|
34
|
+
"""Transcribes audio from a URL.
|
|
35
|
+
|
|
36
|
+
Use this method when the audio is hosted at a URL that the service can access.
|
|
37
|
+
For transcribing local audio files or byte streams, use :meth:`transcribe` instead.
|
|
38
|
+
|
|
39
|
+
:param audio_url: The URL of the audio file to transcribe. The audio must be shorter than 2
|
|
40
|
+
hours in duration and smaller than 250 MB in size. Required.
|
|
41
|
+
:type audio_url: str
|
|
42
|
+
:keyword options: Optional transcription configuration. If provided, the audio_url parameter
|
|
43
|
+
will override the audio_url field in the options object.
|
|
44
|
+
:paramtype options: ~azure.ai.transcription.models.TranscriptionOptions
|
|
45
|
+
:return: TranscriptionResult with the transcription text and phrases.
|
|
46
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
47
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
48
|
+
|
|
49
|
+
.. admonition:: Example:
|
|
50
|
+
|
|
51
|
+
.. literalinclude:: ../samples/sample_transcribe_from_url.py
|
|
52
|
+
:start-after: [START transcribe_from_url]
|
|
53
|
+
:end-before: [END transcribe_from_url]
|
|
54
|
+
:language: python
|
|
55
|
+
:dedent: 4
|
|
56
|
+
:caption: Transcribe audio from a URL.
|
|
57
|
+
"""
|
|
58
|
+
# Create or update options with the audio URL
|
|
59
|
+
if options is None:
|
|
60
|
+
options = _models.TranscriptionOptions(audio_url=audio_url)
|
|
61
|
+
else:
|
|
62
|
+
options.audio_url = audio_url
|
|
63
|
+
|
|
64
|
+
# Send as multipart request with only definition (no audio file)
|
|
65
|
+
error_map: MutableMapping = {
|
|
66
|
+
401: ClientAuthenticationError,
|
|
67
|
+
404: ResourceNotFoundError,
|
|
68
|
+
409: ResourceExistsError,
|
|
69
|
+
304: ResourceNotModifiedError,
|
|
70
|
+
}
|
|
71
|
+
error_map.update(kwargs.pop("error_map", {}) or {})
|
|
72
|
+
|
|
73
|
+
_headers = kwargs.pop("headers", {}) or {}
|
|
74
|
+
_params = kwargs.pop("params", {}) or {}
|
|
75
|
+
|
|
76
|
+
_params["api-version"] = self._config.api_version
|
|
77
|
+
_headers["Accept"] = "application/json"
|
|
78
|
+
|
|
79
|
+
# Serialize definition as JSON string for multipart
|
|
80
|
+
definition_json = json.dumps(options.as_dict(), cls=SdkJSONEncoder, exclude_readonly=True)
|
|
81
|
+
|
|
82
|
+
# Build multipart request - pass definition through files to ensure multipart encoding
|
|
83
|
+
# The definition needs to be in files list with explicit content-type to trigger multipart/form-data
|
|
84
|
+
_request = build_transcription_transcribe_request(
|
|
85
|
+
api_version=self._config.api_version,
|
|
86
|
+
files=[("definition", (None, definition_json, "application/json"))],
|
|
87
|
+
headers=_headers,
|
|
88
|
+
params=_params,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
path_format_arguments = {
|
|
92
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
93
|
+
}
|
|
94
|
+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
|
|
95
|
+
|
|
96
|
+
pipeline_response = self._client._pipeline.run(_request, stream=False, **kwargs) # pylint: disable=protected-access
|
|
97
|
+
response = pipeline_response.http_response
|
|
98
|
+
|
|
99
|
+
if response.status_code not in [200]:
|
|
100
|
+
map_error(status_code=response.status_code, response=response, error_map=error_map)
|
|
101
|
+
raise HttpResponseError(response=response)
|
|
102
|
+
|
|
103
|
+
deserialized = _deserialize(_models.TranscriptionResult, response.json())
|
|
104
|
+
return deserialized
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
__all__: list[str] = [
|
|
108
|
+
"_TranscriptionClientOperationsMixin"
|
|
109
|
+
] # Add all objects you want publicly available to users at this package level
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def patch_sdk():
|
|
113
|
+
"""Do not remove from this file.
|
|
114
|
+
|
|
115
|
+
`patch_sdk` is a last resort escape hatch that allows you to do customizations
|
|
116
|
+
you can't accomplish using the techniques described in
|
|
117
|
+
https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
118
|
+
"""
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
"""Customize generated code here.
|
|
7
|
+
|
|
8
|
+
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__: list[str] = [] # Add all objects you want publicly available to users at this package level
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def patch_sdk():
|
|
16
|
+
"""Do not remove from this file.
|
|
17
|
+
|
|
18
|
+
`patch_sdk` is a last resort escape hatch that allows you to do customizations
|
|
19
|
+
you can't accomplish using the techniques described in
|
|
20
|
+
https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
21
|
+
"""
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
5
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
6
|
+
# --------------------------------------------------------------------------
|