vocalstack 1.0.0a9__tar.gz → 1.0.0a11__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.
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/PKG-INFO +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/pyproject.toml +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/__init__.py +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/_models.py +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/realtime.py +54 -2
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/.gitignore +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/LICENSE +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/README.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/SKILL.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/skills/vocalstack/SKILL.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/_http.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/client.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/errors.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a11}/src/vocalstack/resources.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vocalstack
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0a11
|
|
4
4
|
Summary: VocalStack speech API SDK (asyncio): one client grouped by resource, typed models from the API contract, realtime WebSocket streaming.
|
|
5
5
|
Project-URL: Homepage, https://vocalstack.com
|
|
6
6
|
License-Expression: MIT
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vocalstack"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.0a11"
|
|
8
8
|
description = "VocalStack speech API SDK (asyncio): one client grouped by resource, typed models from the API contract, realtime WebSocket streaming."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -1516,7 +1516,6 @@ class SessionOptions(_Base):
|
|
|
1516
1516
|
translate: Optional[List[str]] = None
|
|
1517
1517
|
voice: Optional[List[str]] = None
|
|
1518
1518
|
voice_by_lang: Optional[Dict[str, str]] = Field(default=None, alias="voiceByLang")
|
|
1519
|
-
voice_cast: Optional[bool] = Field(default=None, alias="voiceCast")
|
|
1520
1519
|
voice_cloning: Optional[bool] = Field(default=None, alias="voiceCloning")
|
|
1521
1520
|
|
|
1522
1521
|
|
|
@@ -1874,6 +1873,7 @@ class VoiceCatalogue(_Base):
|
|
|
1874
1873
|
|
|
1875
1874
|
|
|
1876
1875
|
class VoiceTrack(_Base):
|
|
1876
|
+
chosen_for: Optional[List[str]] = Field(default=None, alias="chosenFor")
|
|
1877
1877
|
clip_dur: Optional[Dict[str, float]] = Field(default=None, alias="clipDur")
|
|
1878
1878
|
clip_parts: Optional[Dict[str, int]] = Field(default=None, alias="clipParts")
|
|
1879
1879
|
clip_rev: Optional[Dict[str, str]] = Field(default=None, alias="clipRev")
|
|
@@ -54,7 +54,10 @@ def upgrade_refused(status: int, body: Optional[bytes]) -> VocalStackError:
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
RESTART_CLOSE = 1012
|
|
57
|
+
LOST_WAITS_S = [1.0, 2.0, 4.0, 8.0, 15.0, 15.0, 15.0, 15.0]
|
|
57
58
|
RESTART_TRIES = 3
|
|
59
|
+
STEADY_S = 30.0
|
|
60
|
+
EARLY_RECOVERIES = 1
|
|
58
61
|
MAX_PENDING_BYTES = 4 * 1024 * 1024
|
|
59
62
|
|
|
60
63
|
|
|
@@ -88,6 +91,8 @@ class RealtimeSession:
|
|
|
88
91
|
self._ready_deadline_s = ready_deadline_s
|
|
89
92
|
self._reconnecting = False
|
|
90
93
|
self._reconnects = 0
|
|
94
|
+
self._opened_at = time.monotonic()
|
|
95
|
+
self._early_recoveries = 0
|
|
91
96
|
self._pending: List[Union[str, bytes]] = []
|
|
92
97
|
self._pending_bytes = 0
|
|
93
98
|
|
|
@@ -127,7 +132,9 @@ class RealtimeSession:
|
|
|
127
132
|
try:
|
|
128
133
|
ws = await websockets.connect(stream_url, max_size=None, open_timeout=ready_deadline_s, close_timeout=2)
|
|
129
134
|
except websockets.InvalidStatus as e:
|
|
130
|
-
|
|
135
|
+
refused = upgrade_refused(e.response.status_code, e.response.body)
|
|
136
|
+
refused._answered = True
|
|
137
|
+
raise refused from e
|
|
131
138
|
except TimeoutError as e:
|
|
132
139
|
raise VocalStackError(
|
|
133
140
|
"capacity_exceeded", f"the upgrade was not answered within {ready_deadline_s}s", retryable=True
|
|
@@ -194,8 +201,12 @@ class RealtimeSession:
|
|
|
194
201
|
async def _reconnect(self) -> None:
|
|
195
202
|
"""The relay restarting: open the same ``stream_url`` again (1, 2,
|
|
196
203
|
4 s apart), send what waited, and go on as the same session. Out
|
|
197
|
-
of tries: ``engine_lost``.
|
|
204
|
+
of tries: ``engine_lost``. A socket that stayed open ``STEADY_S``
|
|
205
|
+
before the restart close starts the tries anew, so a long session
|
|
206
|
+
goes through any number of restarts."""
|
|
198
207
|
self._reconnecting = True
|
|
208
|
+
if time.monotonic() - self._opened_at >= STEADY_S:
|
|
209
|
+
self._reconnects = 0
|
|
199
210
|
try:
|
|
200
211
|
while self._reconnects < RESTART_TRIES and not self._closed and self._stream_url:
|
|
201
212
|
await asyncio.sleep(2 ** self._reconnects)
|
|
@@ -207,6 +218,7 @@ class RealtimeSession:
|
|
|
207
218
|
raise
|
|
208
219
|
continue
|
|
209
220
|
self._ws = ws
|
|
221
|
+
self._opened_at = time.monotonic()
|
|
210
222
|
self._reconnecting = False
|
|
211
223
|
waiting, self._pending, self._pending_bytes = self._pending, [], 0
|
|
212
224
|
for d in waiting:
|
|
@@ -216,6 +228,36 @@ class RealtimeSession:
|
|
|
216
228
|
finally:
|
|
217
229
|
self._reconnecting = False
|
|
218
230
|
|
|
231
|
+
async def _recover(self) -> None:
|
|
232
|
+
"""The socket dropped with no close frame (the server it was on
|
|
233
|
+
stopped answering): open the same ``stream_url`` again, ``LOST_WAITS_S``
|
|
234
|
+
apart, for as long as the server answers "try again" (a retryable
|
|
235
|
+
refusal of the upgrade), send what waited, and go on as the same
|
|
236
|
+
session. A refusal for good, no answer at all, or the last try
|
|
237
|
+
spent: ``engine_lost``, as before."""
|
|
238
|
+
self._reconnecting = True
|
|
239
|
+
try:
|
|
240
|
+
for wait in LOST_WAITS_S:
|
|
241
|
+
await asyncio.sleep(wait)
|
|
242
|
+
if self._closed or not self._stream_url:
|
|
243
|
+
break
|
|
244
|
+
try:
|
|
245
|
+
ws = await self._open_ready(self._stream_url, self._ready_deadline_s, self._on_frame)
|
|
246
|
+
except Exception as e:
|
|
247
|
+
if isinstance(e, VocalStackError) and e.retryable and getattr(e, "_answered", False):
|
|
248
|
+
continue
|
|
249
|
+
break
|
|
250
|
+
self._ws = ws
|
|
251
|
+
self._opened_at = time.monotonic()
|
|
252
|
+
self._reconnecting = False
|
|
253
|
+
waiting, self._pending, self._pending_bytes = self._pending, [], 0
|
|
254
|
+
for d in waiting:
|
|
255
|
+
await self._send(d)
|
|
256
|
+
return
|
|
257
|
+
raise engine_lost()
|
|
258
|
+
finally:
|
|
259
|
+
self._reconnecting = False
|
|
260
|
+
|
|
219
261
|
async def send_file(
|
|
220
262
|
self,
|
|
221
263
|
source: Union[str, bytes, bytearray, "os.PathLike[str]"],
|
|
@@ -314,6 +356,16 @@ class RealtimeSession:
|
|
|
314
356
|
self._error = err
|
|
315
357
|
raise
|
|
316
358
|
continue
|
|
359
|
+
young = time.monotonic() - self._opened_at < STEADY_S
|
|
360
|
+
if e.rcvd is None and (not young or self._early_recoveries < EARLY_RECOVERIES):
|
|
361
|
+
if young:
|
|
362
|
+
self._early_recoveries += 1
|
|
363
|
+
try:
|
|
364
|
+
await self._recover()
|
|
365
|
+
except VocalStackError as err:
|
|
366
|
+
self._error = err
|
|
367
|
+
raise err from e
|
|
368
|
+
continue
|
|
317
369
|
self._error = engine_lost(e.rcvd.code if e.rcvd else None)
|
|
318
370
|
raise self._error from e
|
|
319
371
|
if isinstance(raw, bytes):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|