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,67 @@
|
|
|
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
|
+
# --------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
from abc import ABC
|
|
9
|
+
import json
|
|
10
|
+
from typing import Any, Generic, IO, Mapping, Optional, TYPE_CHECKING, TypeVar, Union
|
|
11
|
+
|
|
12
|
+
from .._utils.model_base import Model, SdkJSONEncoder
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from .serialization import Deserializer, Serializer
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
TClient = TypeVar("TClient")
|
|
19
|
+
TConfig = TypeVar("TConfig")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ClientMixinABC(ABC, Generic[TClient, TConfig]):
|
|
23
|
+
"""DO NOT use this class. It is for internal typing use only."""
|
|
24
|
+
|
|
25
|
+
_client: TClient
|
|
26
|
+
_config: TConfig
|
|
27
|
+
_serialize: "Serializer"
|
|
28
|
+
_deserialize: "Deserializer"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)`
|
|
32
|
+
FileContent = Union[str, bytes, IO[str], IO[bytes]]
|
|
33
|
+
|
|
34
|
+
FileType = Union[
|
|
35
|
+
# file (or bytes)
|
|
36
|
+
FileContent,
|
|
37
|
+
# (filename, file (or bytes))
|
|
38
|
+
tuple[Optional[str], FileContent],
|
|
39
|
+
# (filename, file (or bytes), content_type)
|
|
40
|
+
tuple[Optional[str], FileContent, Optional[str]],
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def serialize_multipart_data_entry(data_entry: Any) -> Any:
|
|
45
|
+
if isinstance(data_entry, (list, tuple, dict, Model)):
|
|
46
|
+
return json.dumps(data_entry, cls=SdkJSONEncoder, exclude_readonly=True)
|
|
47
|
+
return data_entry
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def prepare_multipart_form_data(
|
|
51
|
+
body: Mapping[str, Any], multipart_fields: list[str], data_fields: list[str]
|
|
52
|
+
) -> tuple[list[FileType], dict[str, Any]]:
|
|
53
|
+
files: list[FileType] = []
|
|
54
|
+
data: dict[str, Any] = {}
|
|
55
|
+
for multipart_field in multipart_fields:
|
|
56
|
+
multipart_entry = body.get(multipart_field)
|
|
57
|
+
if isinstance(multipart_entry, list):
|
|
58
|
+
files.extend([(multipart_field, e) for e in multipart_entry])
|
|
59
|
+
elif multipart_entry:
|
|
60
|
+
files.append((multipart_field, multipart_entry))
|
|
61
|
+
|
|
62
|
+
for data_field in data_fields:
|
|
63
|
+
data_entry = body.get(data_field)
|
|
64
|
+
if data_entry:
|
|
65
|
+
data[data_field] = serialize_multipart_data_entry(data_entry)
|
|
66
|
+
|
|
67
|
+
return files, data
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
VERSION = "1.0.0b1"
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
|
|
17
|
+
try:
|
|
18
|
+
from ._patch import __all__ as _patch_all
|
|
19
|
+
from ._patch import *
|
|
20
|
+
except ImportError:
|
|
21
|
+
_patch_all = []
|
|
22
|
+
from ._patch import patch_sdk as _patch_sdk
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"TranscriptionClient",
|
|
26
|
+
]
|
|
27
|
+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
|
|
28
|
+
|
|
29
|
+
_patch_sdk()
|
|
@@ -0,0 +1,107 @@
|
|
|
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, Awaitable, TYPE_CHECKING, Union
|
|
11
|
+
from typing_extensions import Self
|
|
12
|
+
|
|
13
|
+
from azure.core import AsyncPipelineClient
|
|
14
|
+
from azure.core.credentials import AzureKeyCredential
|
|
15
|
+
from azure.core.pipeline import policies
|
|
16
|
+
from azure.core.rest import AsyncHttpResponse, HttpRequest
|
|
17
|
+
|
|
18
|
+
from .._utils.serialization import Deserializer, Serializer
|
|
19
|
+
from ._configuration import TranscriptionClientConfiguration
|
|
20
|
+
from ._operations import _TranscriptionClientOperationsMixin
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from azure.core.credentials_async import AsyncTokenCredential
|
|
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_async.AsyncTokenCredential
|
|
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__(
|
|
43
|
+
self, endpoint: str, credential: Union[AzureKeyCredential, "AsyncTokenCredential"], **kwargs: Any
|
|
44
|
+
) -> None:
|
|
45
|
+
_endpoint = "{endpoint}/speechtotext"
|
|
46
|
+
self._config = TranscriptionClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
|
|
47
|
+
|
|
48
|
+
_policies = kwargs.pop("policies", None)
|
|
49
|
+
if _policies is None:
|
|
50
|
+
_policies = [
|
|
51
|
+
policies.RequestIdPolicy(**kwargs),
|
|
52
|
+
self._config.headers_policy,
|
|
53
|
+
self._config.user_agent_policy,
|
|
54
|
+
self._config.proxy_policy,
|
|
55
|
+
policies.ContentDecodePolicy(**kwargs),
|
|
56
|
+
self._config.redirect_policy,
|
|
57
|
+
self._config.retry_policy,
|
|
58
|
+
self._config.authentication_policy,
|
|
59
|
+
self._config.custom_hook_policy,
|
|
60
|
+
self._config.logging_policy,
|
|
61
|
+
policies.DistributedTracingPolicy(**kwargs),
|
|
62
|
+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
|
|
63
|
+
self._config.http_logging_policy,
|
|
64
|
+
]
|
|
65
|
+
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
|
|
66
|
+
|
|
67
|
+
self._serialize = Serializer()
|
|
68
|
+
self._deserialize = Deserializer()
|
|
69
|
+
self._serialize.client_side_validation = False
|
|
70
|
+
|
|
71
|
+
def send_request(
|
|
72
|
+
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
|
|
73
|
+
) -> Awaitable[AsyncHttpResponse]:
|
|
74
|
+
"""Runs the network request through the client's chained policies.
|
|
75
|
+
|
|
76
|
+
>>> from azure.core.rest import HttpRequest
|
|
77
|
+
>>> request = HttpRequest("GET", "https://www.example.org/")
|
|
78
|
+
<HttpRequest [GET], url: 'https://www.example.org/'>
|
|
79
|
+
>>> response = await client.send_request(request)
|
|
80
|
+
<AsyncHttpResponse: 200 OK>
|
|
81
|
+
|
|
82
|
+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
|
|
83
|
+
|
|
84
|
+
:param request: The network request you want to make. Required.
|
|
85
|
+
:type request: ~azure.core.rest.HttpRequest
|
|
86
|
+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
|
|
87
|
+
:return: The response of your network call. Does not do error handling on your response.
|
|
88
|
+
:rtype: ~azure.core.rest.AsyncHttpResponse
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
request_copy = deepcopy(request)
|
|
92
|
+
path_format_arguments = {
|
|
93
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
|
|
97
|
+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
|
|
98
|
+
|
|
99
|
+
async def close(self) -> None:
|
|
100
|
+
await self._client.close()
|
|
101
|
+
|
|
102
|
+
async def __aenter__(self) -> Self:
|
|
103
|
+
await self._client.__aenter__()
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
async def __aexit__(self, *exc_details: Any) -> None:
|
|
107
|
+
await self._client.__aexit__(*exc_details)
|
|
@@ -0,0 +1,75 @@
|
|
|
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_async import AsyncTokenCredential
|
|
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_async.AsyncTokenCredential
|
|
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__(
|
|
40
|
+
self, endpoint: str, credential: Union[AzureKeyCredential, "AsyncTokenCredential"], **kwargs: Any
|
|
41
|
+
) -> None:
|
|
42
|
+
api_version: str = kwargs.pop("api_version", "2025-10-15")
|
|
43
|
+
|
|
44
|
+
if endpoint is None:
|
|
45
|
+
raise ValueError("Parameter 'endpoint' must not be None.")
|
|
46
|
+
if credential is None:
|
|
47
|
+
raise ValueError("Parameter 'credential' must not be None.")
|
|
48
|
+
|
|
49
|
+
self.endpoint = endpoint
|
|
50
|
+
self.credential = credential
|
|
51
|
+
self.api_version = api_version
|
|
52
|
+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
|
|
53
|
+
kwargs.setdefault("sdk_moniker", "ai-transcription/{}".format(VERSION))
|
|
54
|
+
self.polling_interval = kwargs.get("polling_interval", 30)
|
|
55
|
+
self._configure(**kwargs)
|
|
56
|
+
|
|
57
|
+
def _infer_policy(self, **kwargs):
|
|
58
|
+
if isinstance(self.credential, AzureKeyCredential):
|
|
59
|
+
return policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
|
|
60
|
+
if hasattr(self.credential, "get_token"):
|
|
61
|
+
return policies.AsyncBearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
|
|
62
|
+
raise TypeError(f"Unsupported credential: {self.credential}")
|
|
63
|
+
|
|
64
|
+
def _configure(self, **kwargs: Any) -> None:
|
|
65
|
+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
|
|
66
|
+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
|
|
67
|
+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
|
|
68
|
+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
|
|
69
|
+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
|
|
70
|
+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
|
|
71
|
+
self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs)
|
|
72
|
+
self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs)
|
|
73
|
+
self.authentication_policy = kwargs.get("authentication_policy")
|
|
74
|
+
if self.credential and not self.authentication_policy:
|
|
75
|
+
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,131 @@
|
|
|
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
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
7
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
8
|
+
# --------------------------------------------------------------------------
|
|
9
|
+
from collections.abc import MutableMapping
|
|
10
|
+
from typing import Any, Callable, Optional, TypeVar, Union, overload
|
|
11
|
+
|
|
12
|
+
from azure.core import AsyncPipelineClient
|
|
13
|
+
from azure.core.exceptions import (
|
|
14
|
+
ClientAuthenticationError,
|
|
15
|
+
HttpResponseError,
|
|
16
|
+
ResourceExistsError,
|
|
17
|
+
ResourceNotFoundError,
|
|
18
|
+
ResourceNotModifiedError,
|
|
19
|
+
StreamClosedError,
|
|
20
|
+
StreamConsumedError,
|
|
21
|
+
map_error,
|
|
22
|
+
)
|
|
23
|
+
from azure.core.pipeline import PipelineResponse
|
|
24
|
+
from azure.core.rest import AsyncHttpResponse, HttpRequest
|
|
25
|
+
from azure.core.tracing.decorator_async import distributed_trace_async
|
|
26
|
+
|
|
27
|
+
from ... import models as _models
|
|
28
|
+
from ..._operations._operations import build_transcription_transcribe_request
|
|
29
|
+
from ..._utils.model_base import Model as _Model, _deserialize
|
|
30
|
+
from ..._utils.utils import ClientMixinABC, prepare_multipart_form_data
|
|
31
|
+
from .._configuration import TranscriptionClientConfiguration
|
|
32
|
+
|
|
33
|
+
JSON = MutableMapping[str, Any]
|
|
34
|
+
T = TypeVar("T")
|
|
35
|
+
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class _TranscriptionClientOperationsMixin(
|
|
39
|
+
ClientMixinABC[AsyncPipelineClient[HttpRequest, AsyncHttpResponse], TranscriptionClientConfiguration]
|
|
40
|
+
):
|
|
41
|
+
|
|
42
|
+
@overload
|
|
43
|
+
async def transcribe(self, body: _models.TranscriptionContent, **kwargs: Any) -> _models.TranscriptionResult:
|
|
44
|
+
"""Transcribes the provided audio stream.
|
|
45
|
+
|
|
46
|
+
:param body: The body of the multipart request. Required.
|
|
47
|
+
:type body: ~azure.ai.transcription.models.TranscriptionContent
|
|
48
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
49
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
50
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
@overload
|
|
54
|
+
async def transcribe(self, body: JSON, **kwargs: Any) -> _models.TranscriptionResult:
|
|
55
|
+
"""Transcribes the provided audio stream.
|
|
56
|
+
|
|
57
|
+
:param body: The body of the multipart request. Required.
|
|
58
|
+
:type body: JSON
|
|
59
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
60
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
61
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
@distributed_trace_async
|
|
65
|
+
async def transcribe(
|
|
66
|
+
self, body: Union[_models.TranscriptionContent, JSON], **kwargs: Any
|
|
67
|
+
) -> _models.TranscriptionResult:
|
|
68
|
+
"""Transcribes the provided audio stream.
|
|
69
|
+
|
|
70
|
+
:param body: The body of the multipart request. Is either a TranscriptionContent type or a JSON
|
|
71
|
+
type. Required.
|
|
72
|
+
:type body: ~azure.ai.transcription.models.TranscriptionContent or JSON
|
|
73
|
+
:return: TranscriptionResult. The TranscriptionResult is compatible with MutableMapping
|
|
74
|
+
:rtype: ~azure.ai.transcription.models.TranscriptionResult
|
|
75
|
+
:raises ~azure.core.exceptions.HttpResponseError:
|
|
76
|
+
"""
|
|
77
|
+
error_map: MutableMapping = {
|
|
78
|
+
401: ClientAuthenticationError,
|
|
79
|
+
404: ResourceNotFoundError,
|
|
80
|
+
409: ResourceExistsError,
|
|
81
|
+
304: ResourceNotModifiedError,
|
|
82
|
+
}
|
|
83
|
+
error_map.update(kwargs.pop("error_map", {}) or {})
|
|
84
|
+
|
|
85
|
+
_headers = kwargs.pop("headers", {}) or {}
|
|
86
|
+
_params = kwargs.pop("params", {}) or {}
|
|
87
|
+
|
|
88
|
+
cls: ClsType[_models.TranscriptionResult] = kwargs.pop("cls", None)
|
|
89
|
+
|
|
90
|
+
_body = body.as_dict() if isinstance(body, _Model) else body
|
|
91
|
+
_file_fields: list[str] = ["audio"]
|
|
92
|
+
_data_fields: list[str] = ["definition"]
|
|
93
|
+
_files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields)
|
|
94
|
+
|
|
95
|
+
_request = build_transcription_transcribe_request(
|
|
96
|
+
api_version=self._config.api_version,
|
|
97
|
+
files=_files,
|
|
98
|
+
data=_data,
|
|
99
|
+
headers=_headers,
|
|
100
|
+
params=_params,
|
|
101
|
+
)
|
|
102
|
+
path_format_arguments = {
|
|
103
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
104
|
+
}
|
|
105
|
+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
|
|
106
|
+
|
|
107
|
+
_stream = kwargs.pop("stream", False)
|
|
108
|
+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
|
|
109
|
+
_request, stream=_stream, **kwargs
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
response = pipeline_response.http_response
|
|
113
|
+
|
|
114
|
+
if response.status_code not in [200]:
|
|
115
|
+
if _stream:
|
|
116
|
+
try:
|
|
117
|
+
await response.read() # Load the body in memory and close the socket
|
|
118
|
+
except (StreamConsumedError, StreamClosedError):
|
|
119
|
+
pass
|
|
120
|
+
map_error(status_code=response.status_code, response=response, error_map=error_map)
|
|
121
|
+
raise HttpResponseError(response=response)
|
|
122
|
+
|
|
123
|
+
if _stream:
|
|
124
|
+
deserialized = response.iter_bytes()
|
|
125
|
+
else:
|
|
126
|
+
deserialized = _deserialize(_models.TranscriptionResult, response.json())
|
|
127
|
+
|
|
128
|
+
if cls:
|
|
129
|
+
return cls(pipeline_response, deserialized, {}) # type: ignore
|
|
130
|
+
|
|
131
|
+
return deserialized # type: ignore
|
|
@@ -0,0 +1,116 @@
|
|
|
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_async import distributed_trace_async
|
|
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._operations import build_transcription_transcribe_request
|
|
20
|
+
from ._operations import (
|
|
21
|
+
_TranscriptionClientOperationsMixin as _TranscriptionClientOperationsMixinGenerated,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
JSON = MutableMapping[str, Any]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _TranscriptionClientOperationsMixin(_TranscriptionClientOperationsMixinGenerated):
|
|
28
|
+
"""Custom async operations mixin for TranscriptionClient."""
|
|
29
|
+
|
|
30
|
+
@distributed_trace_async
|
|
31
|
+
async 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/async_samples/sample_transcribe_from_url_async.py
|
|
52
|
+
:start-after: [START transcribe_from_url_async]
|
|
53
|
+
:end-before: [END transcribe_from_url_async]
|
|
54
|
+
:language: python
|
|
55
|
+
:dedent: 4
|
|
56
|
+
:caption: Transcribe audio from a URL asynchronously.
|
|
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
|
+
_headers["Accept"] = "application/json"
|
|
77
|
+
|
|
78
|
+
# Serialize definition as JSON string for multipart
|
|
79
|
+
definition_json = json.dumps(options.as_dict(), cls=SdkJSONEncoder, exclude_readonly=True)
|
|
80
|
+
|
|
81
|
+
# Build multipart request - pass definition through files to ensure multipart encoding
|
|
82
|
+
# The definition needs to be in files list with explicit content-type to trigger multipart/form-data
|
|
83
|
+
_request = build_transcription_transcribe_request(
|
|
84
|
+
api_version=self._config.api_version,
|
|
85
|
+
files=[("definition", (None, definition_json, "application/json"))],
|
|
86
|
+
headers=_headers,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
path_format_arguments = {
|
|
90
|
+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
|
|
91
|
+
}
|
|
92
|
+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
|
|
93
|
+
|
|
94
|
+
pipeline_response = await self._client._pipeline.run(_request, stream=False, **kwargs) # pylint: disable=protected-access
|
|
95
|
+
response = pipeline_response.http_response
|
|
96
|
+
|
|
97
|
+
if response.status_code not in [200]:
|
|
98
|
+
map_error(status_code=response.status_code, response=response, error_map=error_map)
|
|
99
|
+
raise HttpResponseError(response=response)
|
|
100
|
+
|
|
101
|
+
deserialized = _deserialize(_models.TranscriptionResult, response.json())
|
|
102
|
+
return deserialized
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
__all__: list[str] = [
|
|
106
|
+
"_TranscriptionClientOperationsMixin"
|
|
107
|
+
] # Add all objects you want publicly available to users at this package level
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def patch_sdk():
|
|
111
|
+
"""Do not remove from this file.
|
|
112
|
+
|
|
113
|
+
`patch_sdk` is a last resort escape hatch that allows you to do customizations
|
|
114
|
+
you can't accomplish using the techniques described in
|
|
115
|
+
https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
116
|
+
"""
|
|
@@ -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,48 @@
|
|
|
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
|
+
|
|
16
|
+
from ._models import ( # type: ignore
|
|
17
|
+
ChannelCombinedPhrases,
|
|
18
|
+
EnhancedModeProperties,
|
|
19
|
+
PhraseListProperties,
|
|
20
|
+
TranscribedPhrase,
|
|
21
|
+
TranscribedWord,
|
|
22
|
+
TranscriptionContent,
|
|
23
|
+
TranscriptionDiarizationOptions,
|
|
24
|
+
TranscriptionOptions,
|
|
25
|
+
TranscriptionResult,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
from ._enums import ( # type: ignore
|
|
29
|
+
ProfanityFilterMode,
|
|
30
|
+
)
|
|
31
|
+
from ._patch import __all__ as _patch_all
|
|
32
|
+
from ._patch import *
|
|
33
|
+
from ._patch import patch_sdk as _patch_sdk
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"ChannelCombinedPhrases",
|
|
37
|
+
"EnhancedModeProperties",
|
|
38
|
+
"PhraseListProperties",
|
|
39
|
+
"TranscribedPhrase",
|
|
40
|
+
"TranscribedWord",
|
|
41
|
+
"TranscriptionContent",
|
|
42
|
+
"TranscriptionDiarizationOptions",
|
|
43
|
+
"TranscriptionOptions",
|
|
44
|
+
"TranscriptionResult",
|
|
45
|
+
"ProfanityFilterMode",
|
|
46
|
+
]
|
|
47
|
+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
|
|
48
|
+
_patch_sdk()
|
|
@@ -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
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from azure.core import CaseInsensitiveEnumMeta
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ProfanityFilterMode(str, Enum, metaclass=CaseInsensitiveEnumMeta):
|
|
14
|
+
"""Mode of profanity filtering."""
|
|
15
|
+
|
|
16
|
+
NONE = "None"
|
|
17
|
+
"""Disable profanity filtering."""
|
|
18
|
+
REMOVED = "Removed"
|
|
19
|
+
"""Remove profanity."""
|
|
20
|
+
TAGS = "Tags"
|
|
21
|
+
"""Add "profanity" XML tags</Profanity>"""
|
|
22
|
+
MASKED = "Masked"
|
|
23
|
+
"""Mask the profanity with * except of the first letter, e.g., f***"""
|