typecast-python 0.3.6__py3-none-any.whl → 0.3.7__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.
- typecast/_user_agent.py +70 -0
- typecast/async_client.py +7 -2
- typecast/client.py +10 -2
- {typecast_python-0.3.6.dist-info → typecast_python-0.3.7.dist-info}/METADATA +1 -1
- {typecast_python-0.3.6.dist-info → typecast_python-0.3.7.dist-info}/RECORD +7 -6
- {typecast_python-0.3.6.dist-info → typecast_python-0.3.7.dist-info}/WHEEL +0 -0
- {typecast_python-0.3.6.dist-info → typecast_python-0.3.7.dist-info}/licenses/LICENSE +0 -0
typecast/_user_agent.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
import sys
|
|
3
|
+
from importlib import metadata
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
from . import conf
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _package_version(package_name: str) -> str:
|
|
12
|
+
try:
|
|
13
|
+
return metadata.version(package_name)
|
|
14
|
+
except metadata.PackageNotFoundError:
|
|
15
|
+
return "dev"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _os_name() -> str:
|
|
19
|
+
system = platform.system().lower()
|
|
20
|
+
if system == "darwin":
|
|
21
|
+
return "macos"
|
|
22
|
+
if system.startswith("windows"):
|
|
23
|
+
return "windows"
|
|
24
|
+
return system or "unknown"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _arch_name() -> str:
|
|
28
|
+
machine = platform.machine().lower()
|
|
29
|
+
if machine in {"x86_64", "amd64"}:
|
|
30
|
+
return "x64"
|
|
31
|
+
if machine in {"aarch64", "arm64"}:
|
|
32
|
+
return "arm64"
|
|
33
|
+
return machine or "unknown"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build_user_agent(
|
|
37
|
+
*,
|
|
38
|
+
mode: str,
|
|
39
|
+
http_library: str,
|
|
40
|
+
host: str,
|
|
41
|
+
transport: str = "rest",
|
|
42
|
+
) -> str:
|
|
43
|
+
sdk_version = _package_version("typecast-python")
|
|
44
|
+
base = "default" if conf.is_default_host(host) else "custom"
|
|
45
|
+
return (
|
|
46
|
+
f"typecast-python/{sdk_version} "
|
|
47
|
+
f"Python/{sys.version_info.major}.{sys.version_info.minor} "
|
|
48
|
+
f"{platform.python_implementation()}/{platform.python_version()} "
|
|
49
|
+
f"{http_library} "
|
|
50
|
+
f"(mode={mode}; base={base}; transport={transport}; "
|
|
51
|
+
f"os={_os_name()}; arch={_arch_name()}; sdk_env=python; platform=server)"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def requests_user_agent(host: str, transport: str = "rest") -> str:
|
|
56
|
+
return build_user_agent(
|
|
57
|
+
mode="sync",
|
|
58
|
+
http_library=f"requests/{requests.__version__}",
|
|
59
|
+
host=host,
|
|
60
|
+
transport=transport,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def aiohttp_user_agent(host: str, transport: str = "rest") -> str:
|
|
65
|
+
return build_user_agent(
|
|
66
|
+
mode="async",
|
|
67
|
+
http_library=f"aiohttp/{aiohttp.__version__}",
|
|
68
|
+
host=host,
|
|
69
|
+
transport=transport,
|
|
70
|
+
)
|
typecast/async_client.py
CHANGED
|
@@ -11,6 +11,7 @@ from ._voice_clone import (
|
|
|
11
11
|
validate_clone_inputs,
|
|
12
12
|
validate_custom_voice_id,
|
|
13
13
|
)
|
|
14
|
+
from ._user_agent import aiohttp_user_agent
|
|
14
15
|
from .client import _guess_audio_mime
|
|
15
16
|
from .client import _output_with_inferred_format
|
|
16
17
|
from .client import _validate_output_path
|
|
@@ -81,7 +82,7 @@ class AsyncTypecast:
|
|
|
81
82
|
async def __aenter__(self):
|
|
82
83
|
# Auth header at session scope; per-request Content-Type is set by aiohttp
|
|
83
84
|
# (json= auto-sets application/json, data=FormData() auto-sets multipart).
|
|
84
|
-
headers = {}
|
|
85
|
+
headers = {"User-Agent": aiohttp_user_agent(self.host)}
|
|
85
86
|
if self.api_key:
|
|
86
87
|
headers["X-API-KEY"] = self.api_key
|
|
87
88
|
self.session = aiohttp.ClientSession(headers=headers)
|
|
@@ -203,7 +204,11 @@ class AsyncTypecast:
|
|
|
203
204
|
NotFoundError, UnprocessableEntityError, RateLimitError,
|
|
204
205
|
InternalServerError, TypecastError: depending on response status.
|
|
205
206
|
"""
|
|
206
|
-
if
|
|
207
|
+
if (
|
|
208
|
+
not isinstance(chunk_size, int)
|
|
209
|
+
or isinstance(chunk_size, bool)
|
|
210
|
+
or chunk_size < 1
|
|
211
|
+
):
|
|
207
212
|
raise ValueError("chunk_size must be a positive integer")
|
|
208
213
|
if not self.session:
|
|
209
214
|
raise TypecastError("Client session not initialized. Use async with.")
|
typecast/client.py
CHANGED
|
@@ -10,6 +10,7 @@ from ._voice_clone import (
|
|
|
10
10
|
validate_clone_inputs,
|
|
11
11
|
validate_custom_voice_id,
|
|
12
12
|
)
|
|
13
|
+
from ._user_agent import requests_user_agent
|
|
13
14
|
from .composer import SpeechComposer
|
|
14
15
|
from .exceptions import (
|
|
15
16
|
BadRequestError,
|
|
@@ -111,7 +112,10 @@ class Typecast:
|
|
|
111
112
|
if not self.api_key and conf.is_default_host(self.host):
|
|
112
113
|
raise ValueError("API key is required for the default Typecast API host")
|
|
113
114
|
self.session = requests.Session()
|
|
114
|
-
headers = {
|
|
115
|
+
headers = {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
"User-Agent": requests_user_agent(self.host),
|
|
118
|
+
}
|
|
115
119
|
if self.api_key:
|
|
116
120
|
headers["X-API-KEY"] = self.api_key
|
|
117
121
|
self.session.headers.update(headers)
|
|
@@ -236,7 +240,11 @@ class Typecast:
|
|
|
236
240
|
NotFoundError, UnprocessableEntityError, RateLimitError,
|
|
237
241
|
InternalServerError, TypecastError: depending on response status.
|
|
238
242
|
"""
|
|
239
|
-
if
|
|
243
|
+
if (
|
|
244
|
+
not isinstance(chunk_size, int)
|
|
245
|
+
or isinstance(chunk_size, bool)
|
|
246
|
+
or chunk_size < 1
|
|
247
|
+
):
|
|
240
248
|
raise ValueError("chunk_size must be a positive integer")
|
|
241
249
|
endpoint = "/v1/text-to-speech/stream"
|
|
242
250
|
response = self.session.post(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: typecast-python
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
4
4
|
Summary: Official Typecast Python SDK - Convert text to lifelike speech using AI-powered voices
|
|
5
5
|
Project-URL: Homepage, https://typecast.ai
|
|
6
6
|
Project-URL: Documentation, https://typecast.ai/docs/overview
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
typecast/__init__.py,sha256=3pdJqNkXCZ7svzqab4sBR_qwyoM5E2sPjfuci1g1Ub8,1047
|
|
2
|
+
typecast/_user_agent.py,sha256=R_0eSKpuP9jLp_wDJcJGFvFtUh9BZwEgsT1buVeHRAA,1786
|
|
2
3
|
typecast/_voice_clone.py,sha256=TN2tbB3b5lC5uFCBnbERhz37bNJlbv6VZ-vj70EfTs4,3464
|
|
3
|
-
typecast/async_client.py,sha256=
|
|
4
|
-
typecast/client.py,sha256=
|
|
4
|
+
typecast/async_client.py,sha256=65dx24vxiZGpNAGMzxr_7CsG51qZMNAraCuzKjW0e-E,18746
|
|
5
|
+
typecast/client.py,sha256=jFts3z0vmtGb32rGJ8_Wcswu6mo6oXVNzdW9MD3GqGE,17974
|
|
5
6
|
typecast/composer.py,sha256=r1kpRGlSJ1s4C1PkE7yIpGwnKtxYfIdFSLWaf8v1RAQ,9422
|
|
6
7
|
typecast/conf.py,sha256=yfOHYZDvIshWWMriN5wE0GFPR8AX3zv4Rg2655OvA9Q,724
|
|
7
8
|
typecast/exceptions.py,sha256=Y0ZzYebe8zOSOSAHbXfKR0G_RJgdmZXxi15Z7ZxPLIk,1568
|
|
@@ -11,7 +12,7 @@ typecast/models/error.py,sha256=XomIjx7jvlCjItqzJuCAT4mXC9jwTjxR8lLDUk6P8KA,152
|
|
|
11
12
|
typecast/models/subscription.py,sha256=EIaAAo3cCRw8LYT_O6D9AVwxqIHrWCijzl4UTx7FZB8,894
|
|
12
13
|
typecast/models/tts.py,sha256=W2Bp9M-xPJPODlk89P9CnLA2fwb__4SR4yoMkG_O8kA,16453
|
|
13
14
|
typecast/models/voices.py,sha256=-EXP35jDy7_G30k5bDnVrFJHp6svEDTA5jJ8oHAgXNQ,2310
|
|
14
|
-
typecast_python-0.3.
|
|
15
|
-
typecast_python-0.3.
|
|
16
|
-
typecast_python-0.3.
|
|
17
|
-
typecast_python-0.3.
|
|
15
|
+
typecast_python-0.3.7.dist-info/METADATA,sha256=louuBNIHV_BGlSbchFiyXEaxSW4B-NxyH4AThzJqSAc,25530
|
|
16
|
+
typecast_python-0.3.7.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
17
|
+
typecast_python-0.3.7.dist-info/licenses/LICENSE,sha256=HvtJ-S89uUkuYmt-OvVk4MRxmzwtbn84__qJtSrGU2Q,11348
|
|
18
|
+
typecast_python-0.3.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|