murf 1.2.0__tar.gz → 1.2.2__tar.gz
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.
Potentially problematic release.
This version of murf might be problematic. Click here for more details.
- {murf-1.2.0 → murf-1.2.2}/PKG-INFO +4 -4
- {murf-1.2.0 → murf-1.2.2}/README.md +3 -3
- {murf-1.2.0 → murf-1.2.2}/pyproject.toml +1 -1
- {murf-1.2.0 → murf-1.2.2}/src/murf/__init__.py +15 -3
- {murf-1.2.0 → murf-1.2.2}/src/murf/base_client.py +8 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/client_wrapper.py +1 -1
- murf-1.2.2/src/murf/text/__init__.py +2 -0
- murf-1.2.2/src/murf/text/client.py +262 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/text_to_speech/client.py +314 -2
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/__init__.py +12 -2
- murf-1.2.2/src/murf/types/character_count.py +20 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/generate_speech_response.py +11 -15
- murf-1.2.2/src/murf/types/metadata.py +22 -0
- murf-1.2.2/src/murf/types/murf_api_translation_response.py +22 -0
- murf-1.2.2/src/murf/types/speech_to_speech_response.py +47 -0
- murf-1.2.2/src/murf/types/translation.py +20 -0
- murf-1.2.0/src/murf/types/word_duration.py → murf-1.2.2/src/murf/types/word_duration_response.py +19 -5
- murf-1.2.2/src/murf/voice_changer/__init__.py +2 -0
- murf-1.2.2/src/murf/voice_changer/client.py +431 -0
- {murf-1.2.0 → murf-1.2.2}/LICENSE +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/auth/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/auth/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/api_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/datetime_utils.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/file.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/http_client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/jsonable_encoder.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/pydantic_utilities.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/query_encoder.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/remove_none_from_dict.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/request_options.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/core/serialization.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/jobs/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/jobs/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/jobs/types/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/jobs/types/jobs_create_request_priority.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/jobs/types/jobs_create_with_project_id_request_priority.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/languages/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/languages/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/projects/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/projects/client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/projects/types/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing/projects/types/api_create_project_request_dubbing_type.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/dubbing_client.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/environment.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/bad_request_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/forbidden_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/internal_server_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/payment_required_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/service_unavailable_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/errors/unauthorized_error.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/py.typed +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/text_to_speech/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/text_to_speech/types/__init__.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/text_to_speech/types/generate_speech_request_model_version.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_job_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_job_response_dubbing_type.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_job_response_priority.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_project_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_project_response_dubbing_type.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_voice.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/api_voice_gender.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/auth_token_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/dub_api_detail_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/dub_job_status_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/form_data_content_disposition.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/group_api_project_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/locale_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/locale_response_supports_item.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/pronunciation_detail.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/pronunciation_detail_type.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/source_locale_response.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/types/style_details.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/utils.py +0 -0
- {murf-1.2.0 → murf-1.2.2}/src/murf/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: murf
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary:
|
|
5
5
|
Requires-Python: >=3.8,<4.0
|
|
6
6
|
Classifier: Intended Audience :: Developers
|
|
@@ -48,7 +48,7 @@ Description-Content-Type: text/markdown
|
|
|
48
48
|
|
|
49
49
|
## Overview
|
|
50
50
|
|
|
51
|
-
The Murf Python SDK offers seamless integration with the [Murf AI](https://murf.ai/) [text-to-speech software](https://murf.ai/text-to-speech), enabling developers and creators to convert text into lifelike speech effortlessly. With over 130 natural-sounding voices across
|
|
51
|
+
The Murf Python SDK offers seamless integration with the [Murf AI](https://murf.ai/) [text-to-speech software](https://murf.ai/text-to-speech), enabling developers and creators to convert text into lifelike speech effortlessly. With over 130 natural-sounding voices across 21 languages and 20+ speaking styles, Murf provides unparalleled speech customization for a wide range of applications. The SDK is designed for both synchronous and asynchronous workflows, featuring robust error handling, advanced configuration options, and support for real-time applications.
|
|
52
52
|
|
|
53
53
|
---
|
|
54
54
|
|
|
@@ -89,9 +89,9 @@ For more detailed information, refer to the [official documentation](https://mur
|
|
|
89
89
|
## Features
|
|
90
90
|
|
|
91
91
|
- **Text-to-Speech Conversion:** Transform text into natural-sounding speech.
|
|
92
|
-
- **Multilingual Support:** Access voices in over
|
|
92
|
+
- **Multilingual Support:** Access voices in over 21 languages, including English, French, German, Spanish, Italian, Hindi, Portuguese, Dutch, Korean, Chinese (Mandarin), Bengali, Tamil, Polish, Japanese, Turkish, Indonesian, Croatian, Greek, Romanian, Slovak, and Bulgarian.
|
|
93
93
|
|
|
94
|
-

|
|
95
95
|
|
|
96
96
|
- **Multiple Voice Styles:** Choose from 20+ speaking styles to suit your application's needs.
|
|
97
97
|
- **Advanced Voice Customization:** Adjust parameters like pitch, speed, pauses, and pronunciation for optimal output. Fine-grained controls let you tailor the voice output to match your specific requirements.
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
## Overview
|
|
24
24
|
|
|
25
|
-
The Murf Python SDK offers seamless integration with the [Murf AI](https://murf.ai/) [text-to-speech software](https://murf.ai/text-to-speech), enabling developers and creators to convert text into lifelike speech effortlessly. With over 130 natural-sounding voices across
|
|
25
|
+
The Murf Python SDK offers seamless integration with the [Murf AI](https://murf.ai/) [text-to-speech software](https://murf.ai/text-to-speech), enabling developers and creators to convert text into lifelike speech effortlessly. With over 130 natural-sounding voices across 21 languages and 20+ speaking styles, Murf provides unparalleled speech customization for a wide range of applications. The SDK is designed for both synchronous and asynchronous workflows, featuring robust error handling, advanced configuration options, and support for real-time applications.
|
|
26
26
|
|
|
27
27
|
---
|
|
28
28
|
|
|
@@ -63,9 +63,9 @@ For more detailed information, refer to the [official documentation](https://mur
|
|
|
63
63
|
## Features
|
|
64
64
|
|
|
65
65
|
- **Text-to-Speech Conversion:** Transform text into natural-sounding speech.
|
|
66
|
-
- **Multilingual Support:** Access voices in over
|
|
66
|
+
- **Multilingual Support:** Access voices in over 21 languages, including English, French, German, Spanish, Italian, Hindi, Portuguese, Dutch, Korean, Chinese (Mandarin), Bengali, Tamil, Polish, Japanese, Turkish, Indonesian, Croatian, Greek, Romanian, Slovak, and Bulgarian.
|
|
67
67
|
|
|
68
|
-

|
|
69
69
|
|
|
70
70
|
- **Multiple Voice Styles:** Choose from 20+ speaking styles to suit your application's needs.
|
|
71
71
|
- **Advanced Voice Customization:** Adjust parameters like pitch, speed, pauses, and pronunciation for optimal output. Fine-grained controls let you tailor the voice output to match your specific requirements.
|
|
@@ -9,6 +9,7 @@ from .types import (
|
|
|
9
9
|
ApiVoice,
|
|
10
10
|
ApiVoiceGender,
|
|
11
11
|
AuthTokenResponse,
|
|
12
|
+
CharacterCount,
|
|
12
13
|
DubApiDetailResponse,
|
|
13
14
|
DubJobStatusResponse,
|
|
14
15
|
FormDataContentDisposition,
|
|
@@ -16,11 +17,15 @@ from .types import (
|
|
|
16
17
|
GroupApiProjectResponse,
|
|
17
18
|
LocaleResponse,
|
|
18
19
|
LocaleResponseSupportsItem,
|
|
20
|
+
Metadata,
|
|
21
|
+
MurfApiTranslationResponse,
|
|
19
22
|
PronunciationDetail,
|
|
20
23
|
PronunciationDetailType,
|
|
21
24
|
SourceLocaleResponse,
|
|
25
|
+
SpeechToSpeechResponse,
|
|
22
26
|
StyleDetails,
|
|
23
|
-
|
|
27
|
+
Translation,
|
|
28
|
+
WordDurationResponse,
|
|
24
29
|
)
|
|
25
30
|
from .errors import (
|
|
26
31
|
BadRequestError,
|
|
@@ -30,7 +35,7 @@ from .errors import (
|
|
|
30
35
|
ServiceUnavailableError,
|
|
31
36
|
UnauthorizedError,
|
|
32
37
|
)
|
|
33
|
-
from . import auth, dubbing, text_to_speech
|
|
38
|
+
from . import auth, dubbing, text, text_to_speech, voice_changer
|
|
34
39
|
from .client import AsyncMurf, Murf
|
|
35
40
|
from .dubbing_client import MurfDub
|
|
36
41
|
from .environment import MurfEnvironment
|
|
@@ -48,6 +53,7 @@ __all__ = [
|
|
|
48
53
|
"AsyncMurf",
|
|
49
54
|
"AuthTokenResponse",
|
|
50
55
|
"BadRequestError",
|
|
56
|
+
"CharacterCount",
|
|
51
57
|
"DubApiDetailResponse",
|
|
52
58
|
"DubJobStatusResponse",
|
|
53
59
|
"ForbiddenError",
|
|
@@ -58,7 +64,9 @@ __all__ = [
|
|
|
58
64
|
"InternalServerError",
|
|
59
65
|
"LocaleResponse",
|
|
60
66
|
"LocaleResponseSupportsItem",
|
|
67
|
+
"Metadata",
|
|
61
68
|
"Murf",
|
|
69
|
+
"MurfApiTranslationResponse",
|
|
62
70
|
"MurfDub",
|
|
63
71
|
"MurfEnvironment",
|
|
64
72
|
"PaymentRequiredError",
|
|
@@ -66,11 +74,15 @@ __all__ = [
|
|
|
66
74
|
"PronunciationDetailType",
|
|
67
75
|
"ServiceUnavailableError",
|
|
68
76
|
"SourceLocaleResponse",
|
|
77
|
+
"SpeechToSpeechResponse",
|
|
69
78
|
"StyleDetails",
|
|
79
|
+
"Translation",
|
|
70
80
|
"UnauthorizedError",
|
|
71
|
-
"
|
|
81
|
+
"WordDurationResponse",
|
|
72
82
|
"__version__",
|
|
73
83
|
"auth",
|
|
74
84
|
"dubbing",
|
|
85
|
+
"text",
|
|
75
86
|
"text_to_speech",
|
|
87
|
+
"voice_changer",
|
|
76
88
|
]
|
|
@@ -6,10 +6,14 @@ import httpx
|
|
|
6
6
|
from .core.client_wrapper import SyncClientWrapper
|
|
7
7
|
from .auth.client import AuthClient
|
|
8
8
|
from .text_to_speech.client import TextToSpeechClient
|
|
9
|
+
from .text.client import TextClient
|
|
10
|
+
from .voice_changer.client import VoiceChangerClient
|
|
9
11
|
from .dubbing.client import DubbingClient
|
|
10
12
|
from .core.client_wrapper import AsyncClientWrapper
|
|
11
13
|
from .auth.client import AsyncAuthClient
|
|
12
14
|
from .text_to_speech.client import AsyncTextToSpeechClient
|
|
15
|
+
from .text.client import AsyncTextClient
|
|
16
|
+
from .voice_changer.client import AsyncVoiceChangerClient
|
|
13
17
|
from .dubbing.client import AsyncDubbingClient
|
|
14
18
|
|
|
15
19
|
|
|
@@ -73,6 +77,8 @@ class BaseClient:
|
|
|
73
77
|
)
|
|
74
78
|
self.auth = AuthClient(client_wrapper=self._client_wrapper)
|
|
75
79
|
self.text_to_speech = TextToSpeechClient(client_wrapper=self._client_wrapper)
|
|
80
|
+
self.text = TextClient(client_wrapper=self._client_wrapper)
|
|
81
|
+
self.voice_changer = VoiceChangerClient(client_wrapper=self._client_wrapper)
|
|
76
82
|
self.dubbing = DubbingClient(client_wrapper=self._client_wrapper)
|
|
77
83
|
|
|
78
84
|
|
|
@@ -136,6 +142,8 @@ class AsyncBaseClient:
|
|
|
136
142
|
)
|
|
137
143
|
self.auth = AsyncAuthClient(client_wrapper=self._client_wrapper)
|
|
138
144
|
self.text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
|
|
145
|
+
self.text = AsyncTextClient(client_wrapper=self._client_wrapper)
|
|
146
|
+
self.voice_changer = AsyncVoiceChangerClient(client_wrapper=self._client_wrapper)
|
|
139
147
|
self.dubbing = AsyncDubbingClient(client_wrapper=self._client_wrapper)
|
|
140
148
|
|
|
141
149
|
|
|
@@ -16,7 +16,7 @@ class BaseClientWrapper:
|
|
|
16
16
|
headers: typing.Dict[str, str] = {
|
|
17
17
|
"X-Fern-Language": "Python",
|
|
18
18
|
"X-Fern-SDK-Name": "murf",
|
|
19
|
-
"X-Fern-SDK-Version": "1.2.
|
|
19
|
+
"X-Fern-SDK-Version": "1.2.2",
|
|
20
20
|
}
|
|
21
21
|
if self._api_key is not None:
|
|
22
22
|
headers["api-key"] = self._api_key
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from ..core.client_wrapper import SyncClientWrapper
|
|
5
|
+
from ..core.request_options import RequestOptions
|
|
6
|
+
from ..types.murf_api_translation_response import MurfApiTranslationResponse
|
|
7
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
8
|
+
from ..errors.bad_request_error import BadRequestError
|
|
9
|
+
from ..errors.payment_required_error import PaymentRequiredError
|
|
10
|
+
from ..errors.forbidden_error import ForbiddenError
|
|
11
|
+
from ..errors.internal_server_error import InternalServerError
|
|
12
|
+
from ..errors.service_unavailable_error import ServiceUnavailableError
|
|
13
|
+
from json.decoder import JSONDecodeError
|
|
14
|
+
from ..core.api_error import ApiError
|
|
15
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
|
16
|
+
|
|
17
|
+
# this is used as the default value for optional parameters
|
|
18
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TextClient:
|
|
22
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
23
|
+
self._client_wrapper = client_wrapper
|
|
24
|
+
|
|
25
|
+
def translate(
|
|
26
|
+
self,
|
|
27
|
+
*,
|
|
28
|
+
target_language: str,
|
|
29
|
+
texts: typing.Sequence[str],
|
|
30
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
31
|
+
) -> MurfApiTranslationResponse:
|
|
32
|
+
"""
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
target_language : str
|
|
36
|
+
The language code for the target translation
|
|
37
|
+
|
|
38
|
+
texts : typing.Sequence[str]
|
|
39
|
+
List of texts to translate
|
|
40
|
+
|
|
41
|
+
request_options : typing.Optional[RequestOptions]
|
|
42
|
+
Request-specific configuration.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
MurfApiTranslationResponse
|
|
47
|
+
Ok
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
from murf import Murf
|
|
52
|
+
|
|
53
|
+
client = Murf(
|
|
54
|
+
api_key="YOUR_API_KEY",
|
|
55
|
+
)
|
|
56
|
+
client.text.translate(
|
|
57
|
+
target_language="es-ES",
|
|
58
|
+
texts=["Hello, world.", "How are you?"],
|
|
59
|
+
)
|
|
60
|
+
"""
|
|
61
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
62
|
+
"v1/text/translate",
|
|
63
|
+
method="POST",
|
|
64
|
+
json={
|
|
65
|
+
"targetLanguage": target_language,
|
|
66
|
+
"texts": texts,
|
|
67
|
+
},
|
|
68
|
+
headers={
|
|
69
|
+
"content-type": "application/json",
|
|
70
|
+
},
|
|
71
|
+
request_options=request_options,
|
|
72
|
+
omit=OMIT,
|
|
73
|
+
)
|
|
74
|
+
try:
|
|
75
|
+
if 200 <= _response.status_code < 300:
|
|
76
|
+
return typing.cast(
|
|
77
|
+
MurfApiTranslationResponse,
|
|
78
|
+
parse_obj_as(
|
|
79
|
+
type_=MurfApiTranslationResponse, # type: ignore
|
|
80
|
+
object_=_response.json(),
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
if _response.status_code == 400:
|
|
84
|
+
raise BadRequestError(
|
|
85
|
+
typing.cast(
|
|
86
|
+
typing.Optional[typing.Any],
|
|
87
|
+
parse_obj_as(
|
|
88
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
89
|
+
object_=_response.json(),
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
if _response.status_code == 402:
|
|
94
|
+
raise PaymentRequiredError(
|
|
95
|
+
typing.cast(
|
|
96
|
+
typing.Optional[typing.Any],
|
|
97
|
+
parse_obj_as(
|
|
98
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
99
|
+
object_=_response.json(),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
)
|
|
103
|
+
if _response.status_code == 403:
|
|
104
|
+
raise ForbiddenError(
|
|
105
|
+
typing.cast(
|
|
106
|
+
typing.Optional[typing.Any],
|
|
107
|
+
parse_obj_as(
|
|
108
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
109
|
+
object_=_response.json(),
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
if _response.status_code == 500:
|
|
114
|
+
raise InternalServerError(
|
|
115
|
+
typing.cast(
|
|
116
|
+
typing.Optional[typing.Any],
|
|
117
|
+
parse_obj_as(
|
|
118
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
119
|
+
object_=_response.json(),
|
|
120
|
+
),
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
if _response.status_code == 503:
|
|
124
|
+
raise ServiceUnavailableError(
|
|
125
|
+
typing.cast(
|
|
126
|
+
typing.Optional[typing.Any],
|
|
127
|
+
parse_obj_as(
|
|
128
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
129
|
+
object_=_response.json(),
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
_response_json = _response.json()
|
|
134
|
+
except JSONDecodeError:
|
|
135
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
136
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class AsyncTextClient:
|
|
140
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
141
|
+
self._client_wrapper = client_wrapper
|
|
142
|
+
|
|
143
|
+
async def translate(
|
|
144
|
+
self,
|
|
145
|
+
*,
|
|
146
|
+
target_language: str,
|
|
147
|
+
texts: typing.Sequence[str],
|
|
148
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
149
|
+
) -> MurfApiTranslationResponse:
|
|
150
|
+
"""
|
|
151
|
+
Parameters
|
|
152
|
+
----------
|
|
153
|
+
target_language : str
|
|
154
|
+
The language code for the target translation
|
|
155
|
+
|
|
156
|
+
texts : typing.Sequence[str]
|
|
157
|
+
List of texts to translate
|
|
158
|
+
|
|
159
|
+
request_options : typing.Optional[RequestOptions]
|
|
160
|
+
Request-specific configuration.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
MurfApiTranslationResponse
|
|
165
|
+
Ok
|
|
166
|
+
|
|
167
|
+
Examples
|
|
168
|
+
--------
|
|
169
|
+
import asyncio
|
|
170
|
+
|
|
171
|
+
from murf import AsyncMurf
|
|
172
|
+
|
|
173
|
+
client = AsyncMurf(
|
|
174
|
+
api_key="YOUR_API_KEY",
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
async def main() -> None:
|
|
179
|
+
await client.text.translate(
|
|
180
|
+
target_language="es-ES",
|
|
181
|
+
texts=["Hello, world.", "How are you?"],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
asyncio.run(main())
|
|
186
|
+
"""
|
|
187
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
188
|
+
"v1/text/translate",
|
|
189
|
+
method="POST",
|
|
190
|
+
json={
|
|
191
|
+
"targetLanguage": target_language,
|
|
192
|
+
"texts": texts,
|
|
193
|
+
},
|
|
194
|
+
headers={
|
|
195
|
+
"content-type": "application/json",
|
|
196
|
+
},
|
|
197
|
+
request_options=request_options,
|
|
198
|
+
omit=OMIT,
|
|
199
|
+
)
|
|
200
|
+
try:
|
|
201
|
+
if 200 <= _response.status_code < 300:
|
|
202
|
+
return typing.cast(
|
|
203
|
+
MurfApiTranslationResponse,
|
|
204
|
+
parse_obj_as(
|
|
205
|
+
type_=MurfApiTranslationResponse, # type: ignore
|
|
206
|
+
object_=_response.json(),
|
|
207
|
+
),
|
|
208
|
+
)
|
|
209
|
+
if _response.status_code == 400:
|
|
210
|
+
raise BadRequestError(
|
|
211
|
+
typing.cast(
|
|
212
|
+
typing.Optional[typing.Any],
|
|
213
|
+
parse_obj_as(
|
|
214
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
215
|
+
object_=_response.json(),
|
|
216
|
+
),
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
if _response.status_code == 402:
|
|
220
|
+
raise PaymentRequiredError(
|
|
221
|
+
typing.cast(
|
|
222
|
+
typing.Optional[typing.Any],
|
|
223
|
+
parse_obj_as(
|
|
224
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
225
|
+
object_=_response.json(),
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
if _response.status_code == 403:
|
|
230
|
+
raise ForbiddenError(
|
|
231
|
+
typing.cast(
|
|
232
|
+
typing.Optional[typing.Any],
|
|
233
|
+
parse_obj_as(
|
|
234
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
235
|
+
object_=_response.json(),
|
|
236
|
+
),
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
if _response.status_code == 500:
|
|
240
|
+
raise InternalServerError(
|
|
241
|
+
typing.cast(
|
|
242
|
+
typing.Optional[typing.Any],
|
|
243
|
+
parse_obj_as(
|
|
244
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
245
|
+
object_=_response.json(),
|
|
246
|
+
),
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
if _response.status_code == 503:
|
|
250
|
+
raise ServiceUnavailableError(
|
|
251
|
+
typing.cast(
|
|
252
|
+
typing.Optional[typing.Any],
|
|
253
|
+
parse_obj_as(
|
|
254
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
255
|
+
object_=_response.json(),
|
|
256
|
+
),
|
|
257
|
+
)
|
|
258
|
+
)
|
|
259
|
+
_response_json = _response.json()
|
|
260
|
+
except JSONDecodeError:
|
|
261
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
262
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|