talksign 0.2.0__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.
- talksign/__init__.py +57 -0
- talksign/_base.py +244 -0
- talksign/_client.py +240 -0
- talksign/_echo.py +391 -0
- talksign/_errors.py +171 -0
- talksign/_requests.py +309 -0
- talksign/_resources.py +775 -0
- talksign/_splitter.py +124 -0
- talksign/_version.py +1 -0
- talksign/py.typed +0 -0
- talksign/types.py +379 -0
- talksign/video.py +625 -0
- talksign-0.2.0.dist-info/METADATA +188 -0
- talksign-0.2.0.dist-info/RECORD +16 -0
- talksign-0.2.0.dist-info/WHEEL +4 -0
- talksign-0.2.0.dist-info/licenses/LICENSE +191 -0
talksign/_requests.py
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"""Request builders: one function per endpoint, shared by the sync and async resources."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json as _json
|
|
6
|
+
from collections.abc import Mapping, Sequence
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import quote
|
|
9
|
+
|
|
10
|
+
from ._base import FileInput, Req, clean
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _p(value: str) -> str:
|
|
14
|
+
if not value:
|
|
15
|
+
raise ValueError("id must be a non-empty string")
|
|
16
|
+
return quote(str(value), safe="")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _sign_body(
|
|
20
|
+
text: str | None,
|
|
21
|
+
language: str | None,
|
|
22
|
+
avatar: str | None,
|
|
23
|
+
model: str | None,
|
|
24
|
+
duration_seconds: float | None,
|
|
25
|
+
config: Mapping[str, Any] | None,
|
|
26
|
+
) -> dict[str, Any]:
|
|
27
|
+
return clean(
|
|
28
|
+
{
|
|
29
|
+
"text": text,
|
|
30
|
+
"language": language,
|
|
31
|
+
"avatar": avatar,
|
|
32
|
+
"model": model,
|
|
33
|
+
"durationSeconds": duration_seconds,
|
|
34
|
+
"config": dict(config) if config is not None else None,
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def realtime(
|
|
40
|
+
text: str | None,
|
|
41
|
+
*,
|
|
42
|
+
audio: FileInput | None,
|
|
43
|
+
language: str | None,
|
|
44
|
+
avatar: str | None,
|
|
45
|
+
model: str | None,
|
|
46
|
+
duration_seconds: float | None,
|
|
47
|
+
spoken_language: str | None,
|
|
48
|
+
config: Mapping[str, Any] | None,
|
|
49
|
+
idempotency_key: str | None,
|
|
50
|
+
timeout: float | None,
|
|
51
|
+
) -> Req:
|
|
52
|
+
if audio is not None:
|
|
53
|
+
if text is not None:
|
|
54
|
+
raise ValueError("Pass either text or audio, not both.")
|
|
55
|
+
return Req(
|
|
56
|
+
"POST",
|
|
57
|
+
"/speech-to-sign/realtime",
|
|
58
|
+
files={"audio": audio},
|
|
59
|
+
data=clean({"language": language, "avatar": avatar, "spokenLanguage": spoken_language}),
|
|
60
|
+
idempotency_key=idempotency_key,
|
|
61
|
+
timeout=timeout,
|
|
62
|
+
)
|
|
63
|
+
if not text:
|
|
64
|
+
raise ValueError("text (or audio) is required.")
|
|
65
|
+
return Req(
|
|
66
|
+
"POST",
|
|
67
|
+
"/speech-to-sign/realtime",
|
|
68
|
+
json=_sign_body(text, language, avatar, model, duration_seconds, config),
|
|
69
|
+
idempotency_key=idempotency_key,
|
|
70
|
+
timeout=timeout,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def create(
|
|
75
|
+
text: str,
|
|
76
|
+
*,
|
|
77
|
+
mode: str | None,
|
|
78
|
+
language: str | None,
|
|
79
|
+
avatar: str | None,
|
|
80
|
+
model: str | None,
|
|
81
|
+
duration_seconds: float | None,
|
|
82
|
+
config: Mapping[str, Any] | None,
|
|
83
|
+
idempotency_key: str | None,
|
|
84
|
+
timeout: float | None,
|
|
85
|
+
) -> Req:
|
|
86
|
+
body = _sign_body(text, language, avatar, model, duration_seconds, config)
|
|
87
|
+
if mode is not None:
|
|
88
|
+
body["mode"] = mode
|
|
89
|
+
return Req("POST", "/speech-to-sign", json=body, idempotency_key=idempotency_key, timeout=timeout)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def studio(
|
|
93
|
+
text: str,
|
|
94
|
+
*,
|
|
95
|
+
language: str | None,
|
|
96
|
+
avatar: str | None,
|
|
97
|
+
model: str | None,
|
|
98
|
+
duration_seconds: float | None,
|
|
99
|
+
config: Mapping[str, Any] | None,
|
|
100
|
+
async_: bool,
|
|
101
|
+
idempotency_key: str | None,
|
|
102
|
+
timeout: float | None,
|
|
103
|
+
) -> Req:
|
|
104
|
+
return Req(
|
|
105
|
+
"POST",
|
|
106
|
+
"/speech-to-sign/studio",
|
|
107
|
+
params={"async": True} if async_ else None,
|
|
108
|
+
json=_sign_body(text, language, avatar, model, duration_seconds, config),
|
|
109
|
+
idempotency_key=idempotency_key,
|
|
110
|
+
timeout=timeout,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def gloss(text: str, *, language: str | None, idempotency_key: str | None, timeout: float | None) -> Req:
|
|
115
|
+
return Req(
|
|
116
|
+
"POST",
|
|
117
|
+
"/speech-to-sign/gloss",
|
|
118
|
+
json=clean({"text": text, "language": language}),
|
|
119
|
+
idempotency_key=idempotency_key,
|
|
120
|
+
timeout=timeout,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def video(request_id: str, *, timeout: float | None) -> Req:
|
|
125
|
+
return Req("GET", f"/speech-to-sign/video/{_p(request_id)}", binary=True, timeout=timeout)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# -- avatars --------------------------------------------------------------
|
|
129
|
+
def avatars_list(language: str | None = None) -> Req:
|
|
130
|
+
return Req("GET", "/avatars", params=clean({"language": language}) or None)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def avatars_get(avatar_id: str, language: str | None = None) -> Req:
|
|
134
|
+
return Req("GET", f"/avatars/{_p(avatar_id)}", params=clean({"language": language}) or None)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def avatars_create(
|
|
138
|
+
file: FileInput, *, name: str | None, strict: bool | None, idempotency_key: str | None, timeout: float | None
|
|
139
|
+
) -> Req:
|
|
140
|
+
return Req(
|
|
141
|
+
"POST",
|
|
142
|
+
"/avatars",
|
|
143
|
+
files={"file": file},
|
|
144
|
+
data=clean({"name": name, "strict": strict}),
|
|
145
|
+
idempotency_key=idempotency_key,
|
|
146
|
+
timeout=timeout,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def avatars_delete(avatar_id: str) -> Req:
|
|
151
|
+
return Req("DELETE", f"/avatars/{_p(avatar_id)}")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def avatars_validate(file: FileInput, *, timeout: float | None) -> Req:
|
|
155
|
+
return Req("POST", "/avatars/validate", files={"file": file}, timeout=timeout)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# -- other services ---------------------------------------------------------
|
|
159
|
+
def sign_to_speech(video: FileInput | None, fields: Mapping[str, Any]) -> Req:
|
|
160
|
+
if video is not None:
|
|
161
|
+
return Req("POST", "/sign-to-speech", files={"video": video}, data=dict(fields))
|
|
162
|
+
return Req("POST", "/sign-to-speech", json=dict(fields))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def speech_to_speech(
|
|
166
|
+
text: str,
|
|
167
|
+
*,
|
|
168
|
+
to_lang: str,
|
|
169
|
+
from_lang: str | None,
|
|
170
|
+
model: str | None,
|
|
171
|
+
duration_seconds: float | None,
|
|
172
|
+
idempotency_key: str | None,
|
|
173
|
+
timeout: float | None,
|
|
174
|
+
) -> Req:
|
|
175
|
+
return Req(
|
|
176
|
+
"POST",
|
|
177
|
+
"/speech-to-speech",
|
|
178
|
+
json=clean(
|
|
179
|
+
{
|
|
180
|
+
"text": text,
|
|
181
|
+
"toLang": to_lang,
|
|
182
|
+
"fromLang": from_lang,
|
|
183
|
+
"model": model,
|
|
184
|
+
"durationSeconds": duration_seconds,
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
idempotency_key=idempotency_key,
|
|
188
|
+
timeout=timeout,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def voice_create(
|
|
193
|
+
text: str, *, voice: str | None, response_format: str | None, idempotency_key: str | None, timeout: float | None
|
|
194
|
+
) -> Req:
|
|
195
|
+
return Req(
|
|
196
|
+
"POST",
|
|
197
|
+
"/voice",
|
|
198
|
+
json=clean({"text": text, "voice": voice, "response_format": response_format}),
|
|
199
|
+
binary=response_format != "json",
|
|
200
|
+
idempotency_key=idempotency_key,
|
|
201
|
+
timeout=timeout,
|
|
202
|
+
headers={"Accept": "application/json" if response_format == "json" else "audio/mpeg, application/json"},
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def voice_voices() -> Req:
|
|
207
|
+
return Req("GET", "/voice/voices")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# -- jobs -------------------------------------------------------------------
|
|
211
|
+
def jobs_create(
|
|
212
|
+
type: str, # noqa: A002
|
|
213
|
+
*,
|
|
214
|
+
files: Mapping[str, FileInput | None],
|
|
215
|
+
fields: Mapping[str, Any],
|
|
216
|
+
idempotency_key: str | None,
|
|
217
|
+
timeout: float | None,
|
|
218
|
+
) -> Req:
|
|
219
|
+
present = {k: v for k, v in files.items() if v is not None}
|
|
220
|
+
body = clean({"type": type, **fields})
|
|
221
|
+
if present:
|
|
222
|
+
form = {k: (_json.dumps(v) if isinstance(v, (list, dict)) else v) for k, v in body.items()}
|
|
223
|
+
return Req("POST", "/jobs", files=present, data=form, idempotency_key=idempotency_key, timeout=timeout)
|
|
224
|
+
return Req("POST", "/jobs", json=body, idempotency_key=idempotency_key, timeout=timeout)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def jobs_get(job_id: str) -> Req:
|
|
228
|
+
return Req("GET", f"/jobs/{_p(job_id)}")
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def jobs_list(limit: int | None, starting_after: str | None) -> Req:
|
|
232
|
+
return Req("GET", "/jobs", params=clean({"limit": limit, "starting_after": starting_after}))
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def jobs_cancel(job_id: str) -> Req:
|
|
236
|
+
return Req("POST", f"/jobs/{_p(job_id)}/cancel")
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def uploads_create(content_type: str, size_bytes: int) -> Req:
|
|
240
|
+
return Req("POST", "/uploads", json={"content_type": content_type, "size_bytes": int(size_bytes)})
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# -- meetings ---------------------------------------------------------------
|
|
244
|
+
def meetings_create(
|
|
245
|
+
meeting_url: str,
|
|
246
|
+
*,
|
|
247
|
+
disclosure_accepted: bool,
|
|
248
|
+
avatar: str | None,
|
|
249
|
+
background: str | None,
|
|
250
|
+
idempotency_key: str | None,
|
|
251
|
+
) -> Req:
|
|
252
|
+
return Req(
|
|
253
|
+
"POST",
|
|
254
|
+
"/meetings",
|
|
255
|
+
json=clean(
|
|
256
|
+
{
|
|
257
|
+
"meeting_url": meeting_url,
|
|
258
|
+
"disclosure_accepted": disclosure_accepted,
|
|
259
|
+
"avatar": avatar,
|
|
260
|
+
"background": background,
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
idempotency_key=idempotency_key,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def meetings_get(meeting_id: str) -> Req:
|
|
268
|
+
return Req("GET", f"/meetings/{_p(meeting_id)}")
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def meetings_stop(meeting_id: str) -> Req:
|
|
272
|
+
return Req("POST", f"/meetings/{_p(meeting_id)}/stop")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# -- account / meta ---------------------------------------------------------
|
|
276
|
+
def models_list() -> Req:
|
|
277
|
+
return Req("GET", "/models")
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def warmup() -> Req:
|
|
281
|
+
return Req("POST", "/warmup")
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def usage_list(from_: str | int | None, to: str | int | None, limit: int | None, starting_after: str | None) -> Req:
|
|
285
|
+
return Req(
|
|
286
|
+
"GET", "/usage", params=clean({"from": from_, "to": to, "limit": limit, "starting_after": starting_after})
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def tokens_create(expires_in: int | None, allowed_origins: Sequence[str] | None, scopes: Sequence[str] | None) -> Req:
|
|
291
|
+
body = clean(
|
|
292
|
+
{
|
|
293
|
+
"expires_in": expires_in,
|
|
294
|
+
"allowed_origins": list(allowed_origins) if allowed_origins is not None else None,
|
|
295
|
+
"scopes": list(scopes) if scopes is not None else None,
|
|
296
|
+
}
|
|
297
|
+
)
|
|
298
|
+
return Req("POST", "/tokens", json=body)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def balance() -> Req:
|
|
302
|
+
return Req("GET", "/balance")
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def openapi() -> Req:
|
|
306
|
+
return Req("GET", "/openapi.json")
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
TERMINAL_JOB_STATUSES: Sequence[str] = ("succeeded", "failed", "canceled")
|