spitch 1.27.1__py3-none-any.whl → 1.28.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.
Potentially problematic release.
This version of spitch might be problematic. Click here for more details.
- spitch/__init__.py +2 -1
- spitch/_base_client.py +34 -2
- spitch/_files.py +4 -4
- spitch/_models.py +31 -7
- spitch/_version.py +1 -1
- spitch/resources/speech.py +50 -64
- spitch/types/speech_generate_params.py +8 -7
- spitch/types/speech_transcribe_params.py +4 -2
- spitch/types/speech_transcribe_response.py +7 -9
- spitch/types/text_tone_mark_response.py +1 -3
- spitch/types/text_translate_response.py +1 -3
- {spitch-1.27.1.dist-info → spitch-1.28.0.dist-info}/METADATA +42 -10
- {spitch-1.27.1.dist-info → spitch-1.28.0.dist-info}/RECORD +15 -15
- {spitch-1.27.1.dist-info → spitch-1.28.0.dist-info}/WHEEL +0 -0
- {spitch-1.27.1.dist-info → spitch-1.28.0.dist-info}/licenses/LICENSE +0 -0
spitch/__init__.py
CHANGED
|
@@ -26,7 +26,7 @@ from ._exceptions import (
|
|
|
26
26
|
UnprocessableEntityError,
|
|
27
27
|
APIResponseValidationError,
|
|
28
28
|
)
|
|
29
|
-
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
|
|
29
|
+
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
|
|
30
30
|
from ._utils._logs import setup_logging as _setup_logging
|
|
31
31
|
|
|
32
32
|
__all__ = [
|
|
@@ -67,6 +67,7 @@ __all__ = [
|
|
|
67
67
|
"DEFAULT_CONNECTION_LIMITS",
|
|
68
68
|
"DefaultHttpxClient",
|
|
69
69
|
"DefaultAsyncHttpxClient",
|
|
70
|
+
"DefaultAioHttpClient",
|
|
70
71
|
]
|
|
71
72
|
|
|
72
73
|
if not _t.TYPE_CHECKING:
|
spitch/_base_client.py
CHANGED
|
@@ -529,6 +529,18 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
|
529
529
|
# work around https://github.com/encode/httpx/discussions/2880
|
|
530
530
|
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
|
|
531
531
|
|
|
532
|
+
is_body_allowed = options.method.lower() != "get"
|
|
533
|
+
|
|
534
|
+
if is_body_allowed:
|
|
535
|
+
if isinstance(json_data, bytes):
|
|
536
|
+
kwargs["content"] = json_data
|
|
537
|
+
else:
|
|
538
|
+
kwargs["json"] = json_data if is_given(json_data) else None
|
|
539
|
+
kwargs["files"] = files
|
|
540
|
+
else:
|
|
541
|
+
headers.pop("Content-Type", None)
|
|
542
|
+
kwargs.pop("data", None)
|
|
543
|
+
|
|
532
544
|
# TODO: report this error to httpx
|
|
533
545
|
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
|
|
534
546
|
headers=headers,
|
|
@@ -540,8 +552,6 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
|
540
552
|
# so that passing a `TypedDict` doesn't cause an error.
|
|
541
553
|
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
|
|
542
554
|
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
|
|
543
|
-
json=json_data if is_given(json_data) else None,
|
|
544
|
-
files=files,
|
|
545
555
|
**kwargs,
|
|
546
556
|
)
|
|
547
557
|
|
|
@@ -1289,6 +1299,24 @@ class _DefaultAsyncHttpxClient(httpx.AsyncClient):
|
|
|
1289
1299
|
super().__init__(**kwargs)
|
|
1290
1300
|
|
|
1291
1301
|
|
|
1302
|
+
try:
|
|
1303
|
+
import httpx_aiohttp
|
|
1304
|
+
except ImportError:
|
|
1305
|
+
|
|
1306
|
+
class _DefaultAioHttpClient(httpx.AsyncClient):
|
|
1307
|
+
def __init__(self, **_kwargs: Any) -> None:
|
|
1308
|
+
raise RuntimeError("To use the aiohttp client you must have installed the package with the `aiohttp` extra")
|
|
1309
|
+
else:
|
|
1310
|
+
|
|
1311
|
+
class _DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
|
|
1312
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
1313
|
+
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
|
|
1314
|
+
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
|
|
1315
|
+
kwargs.setdefault("follow_redirects", True)
|
|
1316
|
+
|
|
1317
|
+
super().__init__(**kwargs)
|
|
1318
|
+
|
|
1319
|
+
|
|
1292
1320
|
if TYPE_CHECKING:
|
|
1293
1321
|
DefaultAsyncHttpxClient = httpx.AsyncClient
|
|
1294
1322
|
"""An alias to `httpx.AsyncClient` that provides the same defaults that this SDK
|
|
@@ -1297,8 +1325,12 @@ if TYPE_CHECKING:
|
|
|
1297
1325
|
This is useful because overriding the `http_client` with your own instance of
|
|
1298
1326
|
`httpx.AsyncClient` will result in httpx's defaults being used, not ours.
|
|
1299
1327
|
"""
|
|
1328
|
+
|
|
1329
|
+
DefaultAioHttpClient = httpx.AsyncClient
|
|
1330
|
+
"""An alias to `httpx.AsyncClient` that changes the default HTTP transport to `aiohttp`."""
|
|
1300
1331
|
else:
|
|
1301
1332
|
DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient
|
|
1333
|
+
DefaultAioHttpClient = _DefaultAioHttpClient
|
|
1302
1334
|
|
|
1303
1335
|
|
|
1304
1336
|
class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
|
spitch/_files.py
CHANGED
|
@@ -69,12 +69,12 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
|
|
|
69
69
|
return file
|
|
70
70
|
|
|
71
71
|
if is_tuple_t(file):
|
|
72
|
-
return (file[0],
|
|
72
|
+
return (file[0], read_file_content(file[1]), *file[2:])
|
|
73
73
|
|
|
74
74
|
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def
|
|
77
|
+
def read_file_content(file: FileContent) -> HttpxFileContent:
|
|
78
78
|
if isinstance(file, os.PathLike):
|
|
79
79
|
return pathlib.Path(file).read_bytes()
|
|
80
80
|
return file
|
|
@@ -111,12 +111,12 @@ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
|
|
|
111
111
|
return file
|
|
112
112
|
|
|
113
113
|
if is_tuple_t(file):
|
|
114
|
-
return (file[0], await
|
|
114
|
+
return (file[0], await async_read_file_content(file[1]), *file[2:])
|
|
115
115
|
|
|
116
116
|
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
async def
|
|
119
|
+
async def async_read_file_content(file: FileContent) -> HttpxFileContent:
|
|
120
120
|
if isinstance(file, os.PathLike):
|
|
121
121
|
return await anyio.Path(file).read_bytes()
|
|
122
122
|
|
spitch/_models.py
CHANGED
|
@@ -2,9 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
import inspect
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, cast
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
|
|
6
6
|
from datetime import date, datetime
|
|
7
7
|
from typing_extensions import (
|
|
8
|
+
List,
|
|
8
9
|
Unpack,
|
|
9
10
|
Literal,
|
|
10
11
|
ClassVar,
|
|
@@ -206,14 +207,18 @@ class BaseModel(pydantic.BaseModel):
|
|
|
206
207
|
else:
|
|
207
208
|
fields_values[name] = field_get_default(field)
|
|
208
209
|
|
|
210
|
+
extra_field_type = _get_extra_fields_type(__cls)
|
|
211
|
+
|
|
209
212
|
_extra = {}
|
|
210
213
|
for key, value in values.items():
|
|
211
214
|
if key not in model_fields:
|
|
215
|
+
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
|
|
216
|
+
|
|
212
217
|
if PYDANTIC_V2:
|
|
213
|
-
_extra[key] =
|
|
218
|
+
_extra[key] = parsed
|
|
214
219
|
else:
|
|
215
220
|
_fields_set.add(key)
|
|
216
|
-
fields_values[key] =
|
|
221
|
+
fields_values[key] = parsed
|
|
217
222
|
|
|
218
223
|
object.__setattr__(m, "__dict__", fields_values)
|
|
219
224
|
|
|
@@ -365,7 +370,24 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
|
365
370
|
if type_ is None:
|
|
366
371
|
raise RuntimeError(f"Unexpected field type is None for {key}")
|
|
367
372
|
|
|
368
|
-
return construct_type(value=value, type_=type_)
|
|
373
|
+
return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
|
|
377
|
+
if not PYDANTIC_V2:
|
|
378
|
+
# TODO
|
|
379
|
+
return None
|
|
380
|
+
|
|
381
|
+
schema = cls.__pydantic_core_schema__
|
|
382
|
+
if schema["type"] == "model":
|
|
383
|
+
fields = schema["schema"]
|
|
384
|
+
if fields["type"] == "model-fields":
|
|
385
|
+
extras = fields.get("extras_schema")
|
|
386
|
+
if extras and "cls" in extras:
|
|
387
|
+
# mypy can't narrow the type
|
|
388
|
+
return extras["cls"] # type: ignore[no-any-return]
|
|
389
|
+
|
|
390
|
+
return None
|
|
369
391
|
|
|
370
392
|
|
|
371
393
|
def is_basemodel(type_: type) -> bool:
|
|
@@ -419,7 +441,7 @@ def construct_type_unchecked(*, value: object, type_: type[_T]) -> _T:
|
|
|
419
441
|
return cast(_T, construct_type(value=value, type_=type_))
|
|
420
442
|
|
|
421
443
|
|
|
422
|
-
def construct_type(*, value: object, type_: object) -> object:
|
|
444
|
+
def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]] = None) -> object:
|
|
423
445
|
"""Loose coercion to the expected type with construction of nested values.
|
|
424
446
|
|
|
425
447
|
If the given value does not match the expected type then it is returned as-is.
|
|
@@ -434,8 +456,10 @@ def construct_type(*, value: object, type_: object) -> object:
|
|
|
434
456
|
type_ = cast("type[object]", type_)
|
|
435
457
|
|
|
436
458
|
# unwrap `Annotated[T, ...]` -> `T`
|
|
437
|
-
if
|
|
438
|
-
meta: tuple[Any, ...] =
|
|
459
|
+
if metadata is not None and len(metadata) > 0:
|
|
460
|
+
meta: tuple[Any, ...] = tuple(metadata)
|
|
461
|
+
elif is_annotated_type(type_):
|
|
462
|
+
meta = get_args(type_)[1:]
|
|
439
463
|
type_ = extract_type_arg(type_, 0)
|
|
440
464
|
else:
|
|
441
465
|
meta = tuple()
|
spitch/_version.py
CHANGED
spitch/resources/speech.py
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Optional
|
|
6
6
|
from typing_extensions import Literal
|
|
7
7
|
|
|
8
8
|
import httpx
|
|
9
9
|
|
|
10
10
|
from ..types import speech_generate_params, speech_transcribe_params
|
|
11
11
|
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
|
|
12
|
-
from .._utils import
|
|
12
|
+
from .._utils import maybe_transform, async_maybe_transform
|
|
13
13
|
from .._compat import cached_property
|
|
14
14
|
from .._resource import SyncAPIResource, AsyncAPIResource
|
|
15
15
|
from .._response import (
|
|
@@ -66,22 +66,22 @@ class SpeechResource(SyncAPIResource):
|
|
|
66
66
|
"aliyu",
|
|
67
67
|
"hasan",
|
|
68
68
|
"zainab",
|
|
69
|
-
"ngozi",
|
|
70
|
-
"amara",
|
|
71
|
-
"ebuka",
|
|
72
|
-
"obinna",
|
|
73
|
-
"lucy",
|
|
74
|
-
"lina",
|
|
75
69
|
"john",
|
|
76
70
|
"jude",
|
|
71
|
+
"lina",
|
|
72
|
+
"lucy",
|
|
77
73
|
"henry",
|
|
78
74
|
"kani",
|
|
75
|
+
"ngozi",
|
|
76
|
+
"amara",
|
|
77
|
+
"obinna",
|
|
78
|
+
"ebuka",
|
|
79
79
|
"hana",
|
|
80
80
|
"selam",
|
|
81
81
|
"tena",
|
|
82
82
|
"tesfaye",
|
|
83
83
|
],
|
|
84
|
-
|
|
84
|
+
model: Optional[Literal["legacy"]] | NotGiven = NOT_GIVEN,
|
|
85
85
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
86
86
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
87
87
|
extra_headers: Headers | None = None,
|
|
@@ -109,15 +109,12 @@ class SpeechResource(SyncAPIResource):
|
|
|
109
109
|
"language": language,
|
|
110
110
|
"text": text,
|
|
111
111
|
"voice": voice,
|
|
112
|
+
"model": model,
|
|
112
113
|
},
|
|
113
114
|
speech_generate_params.SpeechGenerateParams,
|
|
114
115
|
),
|
|
115
116
|
options=make_request_options(
|
|
116
|
-
extra_headers=extra_headers,
|
|
117
|
-
extra_query=extra_query,
|
|
118
|
-
extra_body=extra_body,
|
|
119
|
-
timeout=timeout,
|
|
120
|
-
query=maybe_transform({"stream": stream}, speech_generate_params.SpeechGenerateParams),
|
|
117
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
121
118
|
),
|
|
122
119
|
cast_to=BinaryAPIResponse,
|
|
123
120
|
)
|
|
@@ -127,8 +124,9 @@ class SpeechResource(SyncAPIResource):
|
|
|
127
124
|
*,
|
|
128
125
|
language: Literal["yo", "en", "ha", "ig", "am"],
|
|
129
126
|
content: Optional[FileTypes] | NotGiven = NOT_GIVEN,
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
model: Optional[Literal["mansa_v1", "legacy"]] | NotGiven = NOT_GIVEN,
|
|
128
|
+
special_words: Optional[str] | NotGiven = NOT_GIVEN,
|
|
129
|
+
timestamp: Optional[Literal["sentence", "word", "none"]] | NotGiven = NOT_GIVEN,
|
|
132
130
|
url: Optional[str] | NotGiven = NOT_GIVEN,
|
|
133
131
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
134
132
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
@@ -149,24 +147,19 @@ class SpeechResource(SyncAPIResource):
|
|
|
149
147
|
|
|
150
148
|
timeout: Override the client-level default timeout for this request, in seconds
|
|
151
149
|
"""
|
|
152
|
-
body = deepcopy_minimal(
|
|
153
|
-
{
|
|
154
|
-
"language": language,
|
|
155
|
-
"content": content,
|
|
156
|
-
"multispeaker": multispeaker,
|
|
157
|
-
"timestamp": timestamp,
|
|
158
|
-
"url": url,
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
files = extract_files(cast(Mapping[str, object], body), paths=[["content"]])
|
|
162
|
-
# It should be noted that the actual Content-Type header that will be
|
|
163
|
-
# sent to the server will contain a `boundary` parameter, e.g.
|
|
164
|
-
# multipart/form-data; boundary=---abc--
|
|
165
|
-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
166
150
|
return self._post(
|
|
167
151
|
"/v1/transcriptions",
|
|
168
|
-
body=maybe_transform(
|
|
169
|
-
|
|
152
|
+
body=maybe_transform(
|
|
153
|
+
{
|
|
154
|
+
"language": language,
|
|
155
|
+
"content": content,
|
|
156
|
+
"model": model,
|
|
157
|
+
"special_words": special_words,
|
|
158
|
+
"timestamp": timestamp,
|
|
159
|
+
"url": url,
|
|
160
|
+
},
|
|
161
|
+
speech_transcribe_params.SpeechTranscribeParams,
|
|
162
|
+
),
|
|
170
163
|
options=make_request_options(
|
|
171
164
|
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
172
165
|
),
|
|
@@ -208,22 +201,22 @@ class AsyncSpeechResource(AsyncAPIResource):
|
|
|
208
201
|
"aliyu",
|
|
209
202
|
"hasan",
|
|
210
203
|
"zainab",
|
|
211
|
-
"ngozi",
|
|
212
|
-
"amara",
|
|
213
|
-
"ebuka",
|
|
214
|
-
"obinna",
|
|
215
|
-
"lucy",
|
|
216
|
-
"lina",
|
|
217
204
|
"john",
|
|
218
205
|
"jude",
|
|
206
|
+
"lina",
|
|
207
|
+
"lucy",
|
|
219
208
|
"henry",
|
|
220
209
|
"kani",
|
|
210
|
+
"ngozi",
|
|
211
|
+
"amara",
|
|
212
|
+
"obinna",
|
|
213
|
+
"ebuka",
|
|
221
214
|
"hana",
|
|
222
215
|
"selam",
|
|
223
216
|
"tena",
|
|
224
217
|
"tesfaye",
|
|
225
218
|
],
|
|
226
|
-
|
|
219
|
+
model: Optional[Literal["legacy"]] | NotGiven = NOT_GIVEN,
|
|
227
220
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
228
221
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
229
222
|
extra_headers: Headers | None = None,
|
|
@@ -251,15 +244,12 @@ class AsyncSpeechResource(AsyncAPIResource):
|
|
|
251
244
|
"language": language,
|
|
252
245
|
"text": text,
|
|
253
246
|
"voice": voice,
|
|
247
|
+
"model": model,
|
|
254
248
|
},
|
|
255
249
|
speech_generate_params.SpeechGenerateParams,
|
|
256
250
|
),
|
|
257
251
|
options=make_request_options(
|
|
258
|
-
extra_headers=extra_headers,
|
|
259
|
-
extra_query=extra_query,
|
|
260
|
-
extra_body=extra_body,
|
|
261
|
-
timeout=timeout,
|
|
262
|
-
query=await async_maybe_transform({"stream": stream}, speech_generate_params.SpeechGenerateParams),
|
|
252
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
263
253
|
),
|
|
264
254
|
cast_to=AsyncBinaryAPIResponse,
|
|
265
255
|
)
|
|
@@ -269,8 +259,9 @@ class AsyncSpeechResource(AsyncAPIResource):
|
|
|
269
259
|
*,
|
|
270
260
|
language: Literal["yo", "en", "ha", "ig", "am"],
|
|
271
261
|
content: Optional[FileTypes] | NotGiven = NOT_GIVEN,
|
|
272
|
-
|
|
273
|
-
|
|
262
|
+
model: Optional[Literal["mansa_v1", "legacy"]] | NotGiven = NOT_GIVEN,
|
|
263
|
+
special_words: Optional[str] | NotGiven = NOT_GIVEN,
|
|
264
|
+
timestamp: Optional[Literal["sentence", "word", "none"]] | NotGiven = NOT_GIVEN,
|
|
274
265
|
url: Optional[str] | NotGiven = NOT_GIVEN,
|
|
275
266
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
276
267
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
@@ -291,24 +282,19 @@ class AsyncSpeechResource(AsyncAPIResource):
|
|
|
291
282
|
|
|
292
283
|
timeout: Override the client-level default timeout for this request, in seconds
|
|
293
284
|
"""
|
|
294
|
-
body = deepcopy_minimal(
|
|
295
|
-
{
|
|
296
|
-
"language": language,
|
|
297
|
-
"content": content,
|
|
298
|
-
"multispeaker": multispeaker,
|
|
299
|
-
"timestamp": timestamp,
|
|
300
|
-
"url": url,
|
|
301
|
-
}
|
|
302
|
-
)
|
|
303
|
-
files = extract_files(cast(Mapping[str, object], body), paths=[["content"]])
|
|
304
|
-
# It should be noted that the actual Content-Type header that will be
|
|
305
|
-
# sent to the server will contain a `boundary` parameter, e.g.
|
|
306
|
-
# multipart/form-data; boundary=---abc--
|
|
307
|
-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
308
285
|
return await self._post(
|
|
309
286
|
"/v1/transcriptions",
|
|
310
|
-
body=await async_maybe_transform(
|
|
311
|
-
|
|
287
|
+
body=await async_maybe_transform(
|
|
288
|
+
{
|
|
289
|
+
"language": language,
|
|
290
|
+
"content": content,
|
|
291
|
+
"model": model,
|
|
292
|
+
"special_words": special_words,
|
|
293
|
+
"timestamp": timestamp,
|
|
294
|
+
"url": url,
|
|
295
|
+
},
|
|
296
|
+
speech_transcribe_params.SpeechTranscribeParams,
|
|
297
|
+
),
|
|
312
298
|
options=make_request_options(
|
|
313
299
|
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
314
300
|
),
|
|
@@ -348,7 +334,7 @@ class SpeechResourceWithStreamingResponse:
|
|
|
348
334
|
|
|
349
335
|
self.generate = to_custom_streamed_response_wrapper(
|
|
350
336
|
speech.generate,
|
|
351
|
-
StreamedBinaryAPIResponse
|
|
337
|
+
StreamedBinaryAPIResponse,
|
|
352
338
|
)
|
|
353
339
|
self.transcribe = to_streamed_response_wrapper(
|
|
354
340
|
speech.transcribe,
|
|
@@ -361,7 +347,7 @@ class AsyncSpeechResourceWithStreamingResponse:
|
|
|
361
347
|
|
|
362
348
|
self.generate = async_to_custom_streamed_response_wrapper(
|
|
363
349
|
speech.generate,
|
|
364
|
-
AsyncStreamedBinaryAPIResponse
|
|
350
|
+
AsyncStreamedBinaryAPIResponse,
|
|
365
351
|
)
|
|
366
352
|
self.transcribe = async_to_streamed_response_wrapper(
|
|
367
353
|
speech.transcribe,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from typing import Optional
|
|
5
6
|
from typing_extensions import Literal, Required, TypedDict
|
|
6
7
|
|
|
7
8
|
__all__ = ["SpeechGenerateParams"]
|
|
@@ -22,16 +23,16 @@ class SpeechGenerateParams(TypedDict, total=False):
|
|
|
22
23
|
"aliyu",
|
|
23
24
|
"hasan",
|
|
24
25
|
"zainab",
|
|
25
|
-
"ngozi",
|
|
26
|
-
"amara",
|
|
27
|
-
"ebuka",
|
|
28
|
-
"obinna",
|
|
29
|
-
"lucy",
|
|
30
|
-
"lina",
|
|
31
26
|
"john",
|
|
32
27
|
"jude",
|
|
28
|
+
"lina",
|
|
29
|
+
"lucy",
|
|
33
30
|
"henry",
|
|
34
31
|
"kani",
|
|
32
|
+
"ngozi",
|
|
33
|
+
"amara",
|
|
34
|
+
"obinna",
|
|
35
|
+
"ebuka",
|
|
35
36
|
"hana",
|
|
36
37
|
"selam",
|
|
37
38
|
"tena",
|
|
@@ -39,4 +40,4 @@ class SpeechGenerateParams(TypedDict, total=False):
|
|
|
39
40
|
]
|
|
40
41
|
]
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
model: Optional[Literal["legacy"]]
|
|
@@ -15,8 +15,10 @@ class SpeechTranscribeParams(TypedDict, total=False):
|
|
|
15
15
|
|
|
16
16
|
content: Optional[FileTypes]
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
model: Optional[Literal["mansa_v1", "legacy"]]
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
special_words: Optional[str]
|
|
21
|
+
|
|
22
|
+
timestamp: Optional[Literal["sentence", "word", "none"]]
|
|
21
23
|
|
|
22
24
|
url: Optional[str]
|
|
@@ -4,22 +4,20 @@ from typing import List, Optional
|
|
|
4
4
|
|
|
5
5
|
from .._models import BaseModel
|
|
6
6
|
|
|
7
|
-
__all__ = ["SpeechTranscribeResponse", "
|
|
7
|
+
__all__ = ["SpeechTranscribeResponse", "Timestamp"]
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
11
|
-
end:
|
|
10
|
+
class Timestamp(BaseModel):
|
|
11
|
+
end: float
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
start: float
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
text: Optional[int] = None
|
|
15
|
+
text: str
|
|
18
16
|
|
|
19
17
|
|
|
20
18
|
class SpeechTranscribeResponse(BaseModel):
|
|
21
19
|
request_id: str
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
text: str
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
timestamps: Optional[List[Timestamp]] = None
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
3
|
from .._models import BaseModel
|
|
6
4
|
|
|
7
5
|
__all__ = ["TextToneMarkResponse"]
|
|
@@ -10,4 +8,4 @@ __all__ = ["TextToneMarkResponse"]
|
|
|
10
8
|
class TextToneMarkResponse(BaseModel):
|
|
11
9
|
request_id: str
|
|
12
10
|
|
|
13
|
-
text:
|
|
11
|
+
text: str
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
3
|
from .._models import BaseModel
|
|
6
4
|
|
|
7
5
|
__all__ = ["TextTranslateResponse"]
|
|
@@ -10,4 +8,4 @@ __all__ = ["TextTranslateResponse"]
|
|
|
10
8
|
class TextTranslateResponse(BaseModel):
|
|
11
9
|
request_id: str
|
|
12
10
|
|
|
13
|
-
text:
|
|
11
|
+
text: str
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: spitch
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.28.0
|
|
4
4
|
Summary: The official Python library for the spitch API
|
|
5
5
|
Project-URL: Homepage, https://github.com/spi-tch/spitch-python
|
|
6
6
|
Project-URL: Repository, https://github.com/spi-tch/spitch-python
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
23
|
Classifier: Typing :: Typed
|
|
23
24
|
Requires-Python: >=3.8
|
|
@@ -28,11 +29,15 @@ Requires-Dist: httpx<0.28.0,>=0.23.0
|
|
|
28
29
|
Requires-Dist: pydantic<3,>=1.9.0
|
|
29
30
|
Requires-Dist: sniffio
|
|
30
31
|
Requires-Dist: typing-extensions<5,>=4.7
|
|
32
|
+
Provides-Extra: aiohttp
|
|
33
|
+
Requires-Dist: aiohttp; extra == 'aiohttp'
|
|
34
|
+
Requires-Dist: httpx-aiohttp>=0.1.8; extra == 'aiohttp'
|
|
31
35
|
Description-Content-Type: text/markdown
|
|
32
36
|
|
|
33
37
|
# Spitch Python API library
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
<!-- prettier-ignore -->
|
|
40
|
+
[)](https://pypi.org/project/spitch/)
|
|
36
41
|
|
|
37
42
|
The Spitch Python library provides convenient access to the Spitch REST API from any Python 3.8+
|
|
38
43
|
application. The library includes type definitions for all request params and response fields,
|
|
@@ -56,12 +61,9 @@ pip install spitch
|
|
|
56
61
|
The full API of this library can be found in [api.md](https://github.com/spi-tch/spitch-python/tree/main/api.md).
|
|
57
62
|
|
|
58
63
|
```python
|
|
59
|
-
import os
|
|
60
64
|
from spitch import Spitch
|
|
61
65
|
|
|
62
|
-
client = Spitch(
|
|
63
|
-
api_key=os.environ.get("SPITCH_API_KEY"), # This is the default and can be omitted
|
|
64
|
-
)
|
|
66
|
+
client = Spitch()
|
|
65
67
|
|
|
66
68
|
response = client.speech.generate(
|
|
67
69
|
language="yo",
|
|
@@ -80,13 +82,10 @@ so that your API Key is not stored in source control.
|
|
|
80
82
|
Simply import `AsyncSpitch` instead of `Spitch` and use `await` with each API call:
|
|
81
83
|
|
|
82
84
|
```python
|
|
83
|
-
import os
|
|
84
85
|
import asyncio
|
|
85
86
|
from spitch import AsyncSpitch
|
|
86
87
|
|
|
87
|
-
client = AsyncSpitch(
|
|
88
|
-
api_key=os.environ.get("SPITCH_API_KEY"), # This is the default and can be omitted
|
|
89
|
-
)
|
|
88
|
+
client = AsyncSpitch()
|
|
90
89
|
|
|
91
90
|
|
|
92
91
|
async def main() -> None:
|
|
@@ -102,6 +101,39 @@ asyncio.run(main())
|
|
|
102
101
|
|
|
103
102
|
Functionality between the synchronous and asynchronous clients is otherwise identical.
|
|
104
103
|
|
|
104
|
+
### With aiohttp
|
|
105
|
+
|
|
106
|
+
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
|
|
107
|
+
|
|
108
|
+
You can enable this by installing `aiohttp`:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
# install from PyPI
|
|
112
|
+
pip install spitch[aiohttp]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import asyncio
|
|
119
|
+
from spitch import DefaultAioHttpClient
|
|
120
|
+
from spitch import AsyncSpitch
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
async def main() -> None:
|
|
124
|
+
async with AsyncSpitch(
|
|
125
|
+
http_client=DefaultAioHttpClient(),
|
|
126
|
+
) as client:
|
|
127
|
+
response = await client.speech.generate(
|
|
128
|
+
language="yo",
|
|
129
|
+
text="text",
|
|
130
|
+
voice="sade",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
asyncio.run(main())
|
|
135
|
+
```
|
|
136
|
+
|
|
105
137
|
## Using types
|
|
106
138
|
|
|
107
139
|
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
spitch/__init__.py,sha256=
|
|
2
|
-
spitch/_base_client.py,sha256=
|
|
1
|
+
spitch/__init__.py,sha256=sQOgCAf6E5lLXjLxqutfq2FtM-qUuiad1OJ9dd5SIic,2560
|
|
2
|
+
spitch/_base_client.py,sha256=cxA_HOlsFL-GCV5en3woq4oArccJuwWzStBOLLSeEvU,67164
|
|
3
3
|
spitch/_client.py,sha256=edWlodXy44ArTu9KY7M_zXYKMhs66gptWUqSuMwN0SI,15438
|
|
4
4
|
spitch/_compat.py,sha256=fQkXUY7reJc8m_yguMWSjHBfO8lNzw4wOAxtkhP9d1Q,6607
|
|
5
5
|
spitch/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
|
|
6
6
|
spitch/_exceptions.py,sha256=xsQtKJTiIdz2X1bQDQFZcSW7WBofLazdQm9nMCyPEVM,3220
|
|
7
|
-
spitch/_files.py,sha256=
|
|
8
|
-
spitch/_models.py,sha256=
|
|
7
|
+
spitch/_files.py,sha256=PoVmzgMIaWGfUgEPaDtFolxtpEHXsmENhH4lXlaGSoU,3613
|
|
8
|
+
spitch/_models.py,sha256=xZcpLpLUiguvwNSYxIHwN3oa2gsbk1Nua06MayCY7eQ,29832
|
|
9
9
|
spitch/_qs.py,sha256=AOkSz4rHtK4YI3ZU_kzea-zpwBUgEY8WniGmTPyEimc,4846
|
|
10
10
|
spitch/_resource.py,sha256=TLFPcOOmtxZOQLh3XCNPB_BdrQpp0MIYoKoH52aRAu8,1100
|
|
11
11
|
spitch/_response.py,sha256=-1LLK1wjPW3Hcro9NXjf_SnPRArU1ozdctNIStvxbWo,28690
|
|
12
12
|
spitch/_streaming.py,sha256=5SpId2EIfF8Ee8UUYmJxqgHUGP1ZdHCUHhHCdNJREFA,10100
|
|
13
13
|
spitch/_types.py,sha256=lccvqVi8E6-4SKt0rn1e9XXNePb0WwdDc10sPVSCygI,6221
|
|
14
|
-
spitch/_version.py,sha256=
|
|
14
|
+
spitch/_version.py,sha256=tqKmPO2OinIl6TSVqJd5lgKPyrWIhaI-iyxtZA74GfU,159
|
|
15
15
|
spitch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
spitch/_utils/__init__.py,sha256=k266EatJr88V8Zseb7xUimTlCeno9SynRfLwadHP1b4,2016
|
|
17
17
|
spitch/_utils/_logs.py,sha256=ApRyYK_WgZfEr_ygBUBXWMlTgeMr2tdNOGlH8jE4oJc,774
|
|
@@ -25,17 +25,17 @@ spitch/_utils/_typing.py,sha256=9UuSEnmE7dgm1SG45Mt-ga1sBhnvZHpq3f2dXbhW1NM,3939
|
|
|
25
25
|
spitch/_utils/_utils.py,sha256=ts4CiiuNpFiGB6YMdkQRh2SZvYvsl7mAF-JWHCcLDf4,12312
|
|
26
26
|
spitch/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
27
27
|
spitch/resources/__init__.py,sha256=KT6rAvIlWHQk9QdM4Jp8ABziKILaBrrtiO7LCB5Wa5E,976
|
|
28
|
-
spitch/resources/speech.py,sha256=
|
|
28
|
+
spitch/resources/speech.py,sha256=ordd1bN-y6f3JkjrkZe-RzYrYjqzz5Ql-NMVHBInwD8,12458
|
|
29
29
|
spitch/resources/text.py,sha256=wWIE7uyvthKfhkOtoodTBDv_0s6YgWgAqxwICquDSyo,9680
|
|
30
30
|
spitch/types/__init__.py,sha256=xBZbzXwV3WlBdawp4Mb4IqoQG4VfaLbi-4FMqPbwqlE,704
|
|
31
|
-
spitch/types/speech_generate_params.py,sha256=
|
|
32
|
-
spitch/types/speech_transcribe_params.py,sha256=
|
|
33
|
-
spitch/types/speech_transcribe_response.py,sha256=
|
|
31
|
+
spitch/types/speech_generate_params.py,sha256=m5FQnPfVxcikB5UJTn-2WjttOP5tJ8BMO0LbGPktMe0,939
|
|
32
|
+
spitch/types/speech_transcribe_params.py,sha256=g-hyQWfiuMbwAuX7YUSwb-j6GKITRc6xcpX0d7mor1Y,604
|
|
33
|
+
spitch/types/speech_transcribe_response.py,sha256=SjqMDTT_VPvN8H7P_be33vlhRBSiLhehTIrNrYOMeIk,415
|
|
34
34
|
spitch/types/text_tone_mark_params.py,sha256=MEnWzcSjPT_Z_8Mio96LgwYbx2BngG5By-MoeSt0Sms,355
|
|
35
|
-
spitch/types/text_tone_mark_response.py,sha256=
|
|
35
|
+
spitch/types/text_tone_mark_response.py,sha256=AtLA2N7tzhxzuTYxS3PwJfPgjGQxIlgTZmTzIUdxKMA,231
|
|
36
36
|
spitch/types/text_translate_params.py,sha256=skEeG7oTZUSl_gugnqL4Mb7HE_pEFhKNygZPTvci2hA,416
|
|
37
|
-
spitch/types/text_translate_response.py,sha256=
|
|
38
|
-
spitch-1.
|
|
39
|
-
spitch-1.
|
|
40
|
-
spitch-1.
|
|
41
|
-
spitch-1.
|
|
37
|
+
spitch/types/text_translate_response.py,sha256=oehUy3S8jyHTLUFhHTV9LtVhkPGxSasENXEPoK4F6-M,233
|
|
38
|
+
spitch-1.28.0.dist-info/METADATA,sha256=n7OxLyoGXim2ywo7cK2pwy77NWCVm96EQRsmH_7hbyI,14036
|
|
39
|
+
spitch-1.28.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
40
|
+
spitch-1.28.0.dist-info/licenses/LICENSE,sha256=C0lDWY-no8IxmnqzQA9BA7Z8jeh_bogVPfeWSgeDDcc,11336
|
|
41
|
+
spitch-1.28.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|