vocalstack 1.1.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.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.5
2
+ Name: vocalstack
3
+ Version: 1.2.2
4
+ Summary: VocalStack speech API SDK (asyncio): one client grouped by resource, typed models from the API contract, realtime WebSocket streaming.
5
+ Project-URL: Homepage, https://vocalstack.com
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: httpx>=0.27
10
+ Requires-Dist: pydantic>=2.7
11
+ Requires-Dist: websockets>=13
12
+ Description-Content-Type: text/markdown
13
+
14
+ # vocalstack
15
+
16
+ The VocalStack speech API for Python (3.10 or newer, asyncio): one client,
17
+ `VocalStack`, with one group per resource. Requests go through `httpx`; answers
18
+ are pydantic models generated from the API's one OpenAPI document
19
+ (`/v1/openapi.json`), with snake_case attributes.
20
+
21
+ Read more about the [VocalStack Python SDK](https://vocalstack.com/#developers) and our other SDKs on the [VocalStack website](https://vocalstack.com/).
22
+
23
+ ```python
24
+ import asyncio, os
25
+ from vocalstack import VocalStack
26
+
27
+ async def main():
28
+ async with VocalStack(api_key=os.environ["VOCALSTACK_API_KEY"]) as vs: # base_url defaults to https://api.vocalstack.com
29
+ tx = await vs.transcriptions.create(url="https://example.com/talk.mp3") # or file="talk.mp3"
30
+ job = await vs.jobs.wait(tx.job.recording_id) # done | failed | cropping
31
+ snap = await vs.recordings.transcript(job.recording_id)
32
+ print(" ".join(s.text for s in snap.sentences))
33
+ open("talk.srt", "wb").write(await vs.recordings.export(job.recording_id, "srt"))
34
+
35
+ asyncio.run(main())
36
+ ```
37
+
38
+ <!-- sdk-docs: generated from the VocalStack API guides; edits here are overwritten -->
39
+
40
+ ## Install
41
+
42
+ ```sh
43
+ pip install vocalstack
44
+ ```
45
+
46
+ ## Guides
47
+
48
+ - [Quickstart](https://github.com/vocalstack/python-sdk/blob/main/docs/quickstart.md): An API key, the SDK, and your first transcript in a dozen lines.
49
+ - [Transcribe a file](https://github.com/vocalstack/python-sdk/blob/main/docs/transcribe-a-file.md): Upload a file, wait for its job, read the transcript and export it. Asynchronous; nothing to keep open.
50
+ - [Transcribe a link](https://github.com/vocalstack/python-sdk/blob/main/docs/transcribe-a-link.md): The server fetches a public URL, a YouTube video or a post on a video or audio site, then transcribes it like a file. Asynchronous, with a fetch phase first.
51
+ - [Search your transcriptions](https://github.com/vocalstack/python-sdk/blob/main/docs/search-transcriptions.md): Find transcriptions by words in their name or link, site, language, kind, tag and date, keep the shared ones, and play each with its share code.
52
+ - [Stream a microphone](https://github.com/vocalstack/python-sdk/blob/main/docs/stream-a-microphone.md): Live audio in, transcript events out, over one WebSocket. Drafts replace the live tail; commits append.
53
+ - [Stream a file at full speed](https://github.com/vocalstack/python-sdk/blob/main/docs/stream-a-file.md): Send a file's bytes through a realtime session and read the transcript as fast as the server makes it. Nothing is stored.
54
+ - [Go live](https://github.com/vocalstack/python-sdk/blob/main/docs/go-live.md): Publish live audio to a stored transcription, and put it on a broadcast link listeners open. Control is HTTP; audio is one WebSocket.
55
+ - [Listen](https://github.com/vocalstack/python-sdk/blob/main/docs/listen.md): Follow a transcription as it happens, in any language: subscribe, catch up from a snapshot, then apply live frames in order.
56
+ - [Live translation and spoken translations](https://github.com/vocalstack/python-sdk/blob/main/docs/translation-and-voices.md): Translate a stream as it is spoken, and have each translated sentence spoken back in a voice. Text frames and audio clips, over the same socket.
57
+ - [Connect an app with one click](https://github.com/vocalstack/python-sdk/blob/main/docs/connect-an-app.md): Let the people who use your app connect their VocalStack account with one Authenticate click — OAuth 2.0 authorization code with PKCE, where the access token is an API key — instead of pasting a key.
58
+ - [Errors, retries and limits](https://github.com/vocalstack/python-sdk/blob/main/docs/errors-and-limits.md): One error envelope everywhere; what to retry (429, 503 unavailable) and how to make a retry safe (Idempotency-Key); credit, plan limits and the 402s.
59
+
60
+ <!-- /sdk-docs -->
61
+
62
+ ## What is what
63
+
64
+ | Name | What it is | Group |
65
+ |---|---|---|
66
+ | realtime session | a signed token plus one socket; nothing stored | `vs.realtime` |
67
+ | broadcast | the link listeners open | `vs.broadcasts` |
68
+ | transcription | a file, link, microphone or stream, transcribed and stored | `vs.transcriptions` |
69
+ | recording | one take inside a broadcast or a transcription | `vs.recordings` |
70
+ | job | a file or link recording's transcription work | `vs.jobs` |
71
+
72
+ The other groups: `vs.corrections`, `vs.share_links`, `vs.speakers`,
73
+ `vs.voices`, `vs.search`, `vs.me`, `vs.languages`, `vs.rtmp`, `vs.events`, `vs.meta`.
74
+ Method names are the document's `operationId`s in snake_case
75
+ (`broadcasts.start_recording` is `POST /v1/broadcasts/{id}/recordings`).
76
+ Request fields are keyword arguments, in snake_case or the wire's camelCase
77
+ (`settings={"spokenLanguage": "en"}`); lists return lists; binary answers
78
+ (`recordings.export`, `recordings.clip`, `speakers.sample`, ...) return bytes.
79
+
80
+ ```python
81
+ VocalStack(
82
+ base_url=None, # default https://api.vocalstack.com
83
+ api_key=None, # an API key (vs_key_...), for a server
84
+ token=None, # or: an access token / browser token, or a callable returning one
85
+ acting_principal=None, # act for an organization (X-Acting-Principal)
86
+ device_id=None,
87
+ max_retries=2, # 429s, and 503 unavailable on safe calls, retried after Retry-After
88
+ timeout=300.0,
89
+ ready_deadline_s=30.0, # how long a socket may take to report ready
90
+ )
91
+ ```
92
+
93
+ ## Realtime sessions and live recordings
94
+
95
+ ```python
96
+ async with VocalStack(api_key=key) as vs:
97
+ # Nothing stored: a file through one socket.
98
+ result = await vs.realtime.transcribe_file("meeting.mp3", spoken_language="en")
99
+ print(result.text)
100
+
101
+ # A stored live transcription: start a recording, stream raw PCM
102
+ # (f32le, 16 kHz, mono) into the publisher socket.
103
+ tx = await vs.transcriptions.create_live(name="Standup")
104
+ grant = await vs.transcriptions.start_recording(tx.id)
105
+ async with await vs.recordings.publish(grant) as stream:
106
+ asyncio.create_task(pace_realtime(stream, pcm)) # then eof()
107
+ async for event in stream:
108
+ if event.type == "transcript.committed":
109
+ print(event.segment.speaker, event.segment.text)
110
+ ```
111
+
112
+ - `transcript.draft` frames **fully replace** the live tail; never append them.
113
+ - `transcript.committed` segments are immutable, gapless by `segment.seq`,
114
+ and carry word timings.
115
+ - A reconnect of a live session says `last_seq=<n>` in the stream URL's query,
116
+ the highest `seq` of the committed lines it received (nothing before the
117
+ first), so the server sends only the lines after it. A server that does not
118
+ read it sends first the committed lines the client may not have received,
119
+ with their own `seq` and `sentenceId`, and a line that did arrive then comes
120
+ a second time: the session's events deliver it twice (keep lines by `seq`).
121
+ - A connection that dies without closing (a network change, a frozen path) is
122
+ noticed: every connect says `heartbeat=1` in the stream URL's query, and a
123
+ server that answers with `heartbeatS` on `session.ready` sends a
124
+ `session.heartbeat` frame that often, whatever the session is doing. When
125
+ nothing at all arrived for three times `heartbeatS` (12 s at most: the server
126
+ says 1 to 4 s) the socket is dropped and the session goes on as after a socket lost
127
+ with no close frame. That reconnect offers the audio still kept
128
+ (`kept_from=<byte>`), and sends it again from the byte `session.ready` names
129
+ (`resumeFrom`), so what the dead socket swallowed is not lost; when it names
130
+ none, nothing is sent again. A server that sends no `heartbeatS` is never
131
+ judged by its silence, and a client whose own timers stood still (a blocked
132
+ thread, a sleeping machine) starts the count again. `heartbeat=False` on `connect` and `publish`
133
+ turns it off.
134
+ `transcribe_file` and `transcribe_url`, and their `on_commit`, are for file and link sessions, which start over instead; they keep one line per
135
+ `seq`, the last received.
136
+ - A reconnect try after such a drop that gets no answer at all is
137
+ made again on the same waits, four such tries at most (about 1, 2, 3 and 4
138
+ seconds apart, the last within 13 seconds of the drop), then the session ends with `engine_lost`; an answered
139
+ refusal for good still ends it at once.
140
+ - A dropped connection ends the realtime session (to go on, create a new one), except after a restart close (1012) or when the server it was on died: the SDK then reconnects to the same `streamUrl` and the realtime session goes on. A restart close that comes before `session.ready` is followed the same way inside `connect` (about 1, 2 and 4 s apart, three more tries at most), so it is not an error of the first connect.
141
+ - After a restart close (1012, a server being replaced), when the server says
142
+ how many bytes it took (`taken=`, said only for `input.kind` `live`), the SDK
143
+ sends the audio after that byte again. For this a session keeps
144
+ the last 30 seconds of audio sent, about 1.9 MB at 16 kHz mono.
145
+ `resend_buffer_s` (or `resend_buffer_bytes`) on `connect` and `publish`
146
+ changes the size, `0` keeps nothing, and `on_audio_lost(bytes)` is called
147
+ when some audio could not be sent again. A file given to `send_file` or
148
+ `transcribe_file` is not kept: on a live session it is read again from the
149
+ byte the server named; on a file session (`input.kind` `file`), where the
150
+ server names no byte and keeps nothing of an upload it did not finish, it is
151
+ sent again from its first byte. So give a path or bytes rather than a source
152
+ that can be read only once (a FIFO, a device: with one a reconnect ends the
153
+ file session with `engine_lost`). The session
154
+ does the reconnecting in a task of its own as soon as the close is seen, so
155
+ a caller that only sends audio and iterates later is carried on as well;
156
+ the frames read meanwhile are kept for the iterator.
157
+ `publish` sizes the buffer for the publisher's format, 16 kHz mono f32le
158
+ (64,000 bytes a second).
159
+ - When the session could not be carried on (the reconnect was refused for
160
+ good, or its tries ran out) it ends with an error. A caller that only sends
161
+ learns of it without iterating: `on_audio_lost` is called with the bytes
162
+ that were waiting for the next socket and then with the size of every
163
+ `send_audio` made after the end; iterating the session raises the error.
164
+ `send_audio` itself never raises it.
165
+ - A file or link session's socket URL says `refile=1` when the client can
166
+ start over: for a file, that it can be read and sent again; for a link, that
167
+ whoever collects the lines drops them when the run starts again. Only then
168
+ does the server, when its machine stops or its engine is lost mid-way, drop
169
+ the socket and transcribe again from the start on the next one; without
170
+ `refile` such a session ends with a retryable `engine_lost` (create a new
171
+ session). `transcribe_file` says it by itself for a source it can read again and
172
+ `transcribe_url` always does; with `connect`, pass `refile=True` when you send a file
173
+ you can read again with `send_file`, or collect a link's lines yourself and
174
+ start them over. When a run starts again the transcript starts over:
175
+ `seq` and `sentenceId` begin at 0 again, times are those of the new run, and
176
+ `on_commit` and the session's events deliver the lines again from the first.
177
+ `transcribe_file` and `transcribe_url` return the last run alone.
178
+ - The first connect follows an upgrade answered 503 with `Retry-After` (a
179
+ server that is stopping while another has a place): it waits that long, 30
180
+ seconds at most, and opens the same `streamUrl` again, three more tries at
181
+ most, the same tries a restart close before `session.ready` gets. A 503
182
+ without `Retry-After` is the connect's error, as before.
183
+ - `send_file` returns when `eof` is written or waits for the next socket, and
184
+ also when the session ended first: closed by you, ended by the server, or
185
+ failed. How a session ended comes once, from the iterator, which raises the
186
+ session's error (also a file that changed or could not be read again after a
187
+ restart). `send_file` raises only what reading the source raises on its first
188
+ pass (`OSError`: no such file), and the session is then closed. So
189
+ `asyncio.create_task(session.send_file(path))` beside an `async for` loop is
190
+ safe.
191
+ - Every connect of a session that keeps audio adds `resend=<ms>` to the stream
192
+ URL's query, the length of its buffer in milliseconds (`resend=30000` by
193
+ default), so the server knows this client sends again after a restart and
194
+ how far back; a session with the buffer set to `0` does not. With a buffer
195
+ under 22 seconds the server keeps the old behaviour on a restart.
196
+ - A reconnect the server answers with 503 "try again" is tried for up to about
197
+ 95 seconds before the session ends with `engine_lost` (it was about 7
198
+ seconds: three tries). To stop sooner, `close()` the session yourself, or
199
+ lower `vocalstack.realtime.REFUSED_TOTAL_S` (90 by default).
200
+ - A 503 that carries `Retry-After` is tried again after exactly that long
201
+ (spread upward only, by 30% at most), not after the longer of it and the
202
+ session's own 1, 2, 4, 8, 15 s waits, and does not move those waits on; a
203
+ 503 without it keeps them. The 90 seconds in all are the same.
204
+ - A connect that fails before the server answers raises `VocalStackError`
205
+ `engine_unavailable`, on the first connect too (the library's own exception
206
+ is its `__cause__`); a stream URL that is not one is not retryable.
207
+ - Cancelling the task that iterates a session while it reconnects closes the
208
+ session.
209
+
210
+ ## Errors
211
+
212
+ `VocalStackError` carries `code` (the contract's closed enum), `message`,
213
+ `status`, `retryable`, `details` (quota numbers, code suggestions), `headers`
214
+ and `retry_after`.
215
+
216
+ Verified against a language-agnostic conformance suite shared by every
217
+ VocalStack SDK and against a running API. For agents: `SKILL.md`.
@@ -0,0 +1,204 @@
1
+ # vocalstack
2
+
3
+ The VocalStack speech API for Python (3.10 or newer, asyncio): one client,
4
+ `VocalStack`, with one group per resource. Requests go through `httpx`; answers
5
+ are pydantic models generated from the API's one OpenAPI document
6
+ (`/v1/openapi.json`), with snake_case attributes.
7
+
8
+ Read more about the [VocalStack Python SDK](https://vocalstack.com/#developers) and our other SDKs on the [VocalStack website](https://vocalstack.com/).
9
+
10
+ ```python
11
+ import asyncio, os
12
+ from vocalstack import VocalStack
13
+
14
+ async def main():
15
+ async with VocalStack(api_key=os.environ["VOCALSTACK_API_KEY"]) as vs: # base_url defaults to https://api.vocalstack.com
16
+ tx = await vs.transcriptions.create(url="https://example.com/talk.mp3") # or file="talk.mp3"
17
+ job = await vs.jobs.wait(tx.job.recording_id) # done | failed | cropping
18
+ snap = await vs.recordings.transcript(job.recording_id)
19
+ print(" ".join(s.text for s in snap.sentences))
20
+ open("talk.srt", "wb").write(await vs.recordings.export(job.recording_id, "srt"))
21
+
22
+ asyncio.run(main())
23
+ ```
24
+
25
+ <!-- sdk-docs: generated from the VocalStack API guides; edits here are overwritten -->
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ pip install vocalstack
31
+ ```
32
+
33
+ ## Guides
34
+
35
+ - [Quickstart](https://github.com/vocalstack/python-sdk/blob/main/docs/quickstart.md): An API key, the SDK, and your first transcript in a dozen lines.
36
+ - [Transcribe a file](https://github.com/vocalstack/python-sdk/blob/main/docs/transcribe-a-file.md): Upload a file, wait for its job, read the transcript and export it. Asynchronous; nothing to keep open.
37
+ - [Transcribe a link](https://github.com/vocalstack/python-sdk/blob/main/docs/transcribe-a-link.md): The server fetches a public URL, a YouTube video or a post on a video or audio site, then transcribes it like a file. Asynchronous, with a fetch phase first.
38
+ - [Search your transcriptions](https://github.com/vocalstack/python-sdk/blob/main/docs/search-transcriptions.md): Find transcriptions by words in their name or link, site, language, kind, tag and date, keep the shared ones, and play each with its share code.
39
+ - [Stream a microphone](https://github.com/vocalstack/python-sdk/blob/main/docs/stream-a-microphone.md): Live audio in, transcript events out, over one WebSocket. Drafts replace the live tail; commits append.
40
+ - [Stream a file at full speed](https://github.com/vocalstack/python-sdk/blob/main/docs/stream-a-file.md): Send a file's bytes through a realtime session and read the transcript as fast as the server makes it. Nothing is stored.
41
+ - [Go live](https://github.com/vocalstack/python-sdk/blob/main/docs/go-live.md): Publish live audio to a stored transcription, and put it on a broadcast link listeners open. Control is HTTP; audio is one WebSocket.
42
+ - [Listen](https://github.com/vocalstack/python-sdk/blob/main/docs/listen.md): Follow a transcription as it happens, in any language: subscribe, catch up from a snapshot, then apply live frames in order.
43
+ - [Live translation and spoken translations](https://github.com/vocalstack/python-sdk/blob/main/docs/translation-and-voices.md): Translate a stream as it is spoken, and have each translated sentence spoken back in a voice. Text frames and audio clips, over the same socket.
44
+ - [Connect an app with one click](https://github.com/vocalstack/python-sdk/blob/main/docs/connect-an-app.md): Let the people who use your app connect their VocalStack account with one Authenticate click — OAuth 2.0 authorization code with PKCE, where the access token is an API key — instead of pasting a key.
45
+ - [Errors, retries and limits](https://github.com/vocalstack/python-sdk/blob/main/docs/errors-and-limits.md): One error envelope everywhere; what to retry (429, 503 unavailable) and how to make a retry safe (Idempotency-Key); credit, plan limits and the 402s.
46
+
47
+ <!-- /sdk-docs -->
48
+
49
+ ## What is what
50
+
51
+ | Name | What it is | Group |
52
+ |---|---|---|
53
+ | realtime session | a signed token plus one socket; nothing stored | `vs.realtime` |
54
+ | broadcast | the link listeners open | `vs.broadcasts` |
55
+ | transcription | a file, link, microphone or stream, transcribed and stored | `vs.transcriptions` |
56
+ | recording | one take inside a broadcast or a transcription | `vs.recordings` |
57
+ | job | a file or link recording's transcription work | `vs.jobs` |
58
+
59
+ The other groups: `vs.corrections`, `vs.share_links`, `vs.speakers`,
60
+ `vs.voices`, `vs.search`, `vs.me`, `vs.languages`, `vs.rtmp`, `vs.events`, `vs.meta`.
61
+ Method names are the document's `operationId`s in snake_case
62
+ (`broadcasts.start_recording` is `POST /v1/broadcasts/{id}/recordings`).
63
+ Request fields are keyword arguments, in snake_case or the wire's camelCase
64
+ (`settings={"spokenLanguage": "en"}`); lists return lists; binary answers
65
+ (`recordings.export`, `recordings.clip`, `speakers.sample`, ...) return bytes.
66
+
67
+ ```python
68
+ VocalStack(
69
+ base_url=None, # default https://api.vocalstack.com
70
+ api_key=None, # an API key (vs_key_...), for a server
71
+ token=None, # or: an access token / browser token, or a callable returning one
72
+ acting_principal=None, # act for an organization (X-Acting-Principal)
73
+ device_id=None,
74
+ max_retries=2, # 429s, and 503 unavailable on safe calls, retried after Retry-After
75
+ timeout=300.0,
76
+ ready_deadline_s=30.0, # how long a socket may take to report ready
77
+ )
78
+ ```
79
+
80
+ ## Realtime sessions and live recordings
81
+
82
+ ```python
83
+ async with VocalStack(api_key=key) as vs:
84
+ # Nothing stored: a file through one socket.
85
+ result = await vs.realtime.transcribe_file("meeting.mp3", spoken_language="en")
86
+ print(result.text)
87
+
88
+ # A stored live transcription: start a recording, stream raw PCM
89
+ # (f32le, 16 kHz, mono) into the publisher socket.
90
+ tx = await vs.transcriptions.create_live(name="Standup")
91
+ grant = await vs.transcriptions.start_recording(tx.id)
92
+ async with await vs.recordings.publish(grant) as stream:
93
+ asyncio.create_task(pace_realtime(stream, pcm)) # then eof()
94
+ async for event in stream:
95
+ if event.type == "transcript.committed":
96
+ print(event.segment.speaker, event.segment.text)
97
+ ```
98
+
99
+ - `transcript.draft` frames **fully replace** the live tail; never append them.
100
+ - `transcript.committed` segments are immutable, gapless by `segment.seq`,
101
+ and carry word timings.
102
+ - A reconnect of a live session says `last_seq=<n>` in the stream URL's query,
103
+ the highest `seq` of the committed lines it received (nothing before the
104
+ first), so the server sends only the lines after it. A server that does not
105
+ read it sends first the committed lines the client may not have received,
106
+ with their own `seq` and `sentenceId`, and a line that did arrive then comes
107
+ a second time: the session's events deliver it twice (keep lines by `seq`).
108
+ - A connection that dies without closing (a network change, a frozen path) is
109
+ noticed: every connect says `heartbeat=1` in the stream URL's query, and a
110
+ server that answers with `heartbeatS` on `session.ready` sends a
111
+ `session.heartbeat` frame that often, whatever the session is doing. When
112
+ nothing at all arrived for three times `heartbeatS` (12 s at most: the server
113
+ says 1 to 4 s) the socket is dropped and the session goes on as after a socket lost
114
+ with no close frame. That reconnect offers the audio still kept
115
+ (`kept_from=<byte>`), and sends it again from the byte `session.ready` names
116
+ (`resumeFrom`), so what the dead socket swallowed is not lost; when it names
117
+ none, nothing is sent again. A server that sends no `heartbeatS` is never
118
+ judged by its silence, and a client whose own timers stood still (a blocked
119
+ thread, a sleeping machine) starts the count again. `heartbeat=False` on `connect` and `publish`
120
+ turns it off.
121
+ `transcribe_file` and `transcribe_url`, and their `on_commit`, are for file and link sessions, which start over instead; they keep one line per
122
+ `seq`, the last received.
123
+ - A reconnect try after such a drop that gets no answer at all is
124
+ made again on the same waits, four such tries at most (about 1, 2, 3 and 4
125
+ seconds apart, the last within 13 seconds of the drop), then the session ends with `engine_lost`; an answered
126
+ refusal for good still ends it at once.
127
+ - A dropped connection ends the realtime session (to go on, create a new one), except after a restart close (1012) or when the server it was on died: the SDK then reconnects to the same `streamUrl` and the realtime session goes on. A restart close that comes before `session.ready` is followed the same way inside `connect` (about 1, 2 and 4 s apart, three more tries at most), so it is not an error of the first connect.
128
+ - After a restart close (1012, a server being replaced), when the server says
129
+ how many bytes it took (`taken=`, said only for `input.kind` `live`), the SDK
130
+ sends the audio after that byte again. For this a session keeps
131
+ the last 30 seconds of audio sent, about 1.9 MB at 16 kHz mono.
132
+ `resend_buffer_s` (or `resend_buffer_bytes`) on `connect` and `publish`
133
+ changes the size, `0` keeps nothing, and `on_audio_lost(bytes)` is called
134
+ when some audio could not be sent again. A file given to `send_file` or
135
+ `transcribe_file` is not kept: on a live session it is read again from the
136
+ byte the server named; on a file session (`input.kind` `file`), where the
137
+ server names no byte and keeps nothing of an upload it did not finish, it is
138
+ sent again from its first byte. So give a path or bytes rather than a source
139
+ that can be read only once (a FIFO, a device: with one a reconnect ends the
140
+ file session with `engine_lost`). The session
141
+ does the reconnecting in a task of its own as soon as the close is seen, so
142
+ a caller that only sends audio and iterates later is carried on as well;
143
+ the frames read meanwhile are kept for the iterator.
144
+ `publish` sizes the buffer for the publisher's format, 16 kHz mono f32le
145
+ (64,000 bytes a second).
146
+ - When the session could not be carried on (the reconnect was refused for
147
+ good, or its tries ran out) it ends with an error. A caller that only sends
148
+ learns of it without iterating: `on_audio_lost` is called with the bytes
149
+ that were waiting for the next socket and then with the size of every
150
+ `send_audio` made after the end; iterating the session raises the error.
151
+ `send_audio` itself never raises it.
152
+ - A file or link session's socket URL says `refile=1` when the client can
153
+ start over: for a file, that it can be read and sent again; for a link, that
154
+ whoever collects the lines drops them when the run starts again. Only then
155
+ does the server, when its machine stops or its engine is lost mid-way, drop
156
+ the socket and transcribe again from the start on the next one; without
157
+ `refile` such a session ends with a retryable `engine_lost` (create a new
158
+ session). `transcribe_file` says it by itself for a source it can read again and
159
+ `transcribe_url` always does; with `connect`, pass `refile=True` when you send a file
160
+ you can read again with `send_file`, or collect a link's lines yourself and
161
+ start them over. When a run starts again the transcript starts over:
162
+ `seq` and `sentenceId` begin at 0 again, times are those of the new run, and
163
+ `on_commit` and the session's events deliver the lines again from the first.
164
+ `transcribe_file` and `transcribe_url` return the last run alone.
165
+ - The first connect follows an upgrade answered 503 with `Retry-After` (a
166
+ server that is stopping while another has a place): it waits that long, 30
167
+ seconds at most, and opens the same `streamUrl` again, three more tries at
168
+ most, the same tries a restart close before `session.ready` gets. A 503
169
+ without `Retry-After` is the connect's error, as before.
170
+ - `send_file` returns when `eof` is written or waits for the next socket, and
171
+ also when the session ended first: closed by you, ended by the server, or
172
+ failed. How a session ended comes once, from the iterator, which raises the
173
+ session's error (also a file that changed or could not be read again after a
174
+ restart). `send_file` raises only what reading the source raises on its first
175
+ pass (`OSError`: no such file), and the session is then closed. So
176
+ `asyncio.create_task(session.send_file(path))` beside an `async for` loop is
177
+ safe.
178
+ - Every connect of a session that keeps audio adds `resend=<ms>` to the stream
179
+ URL's query, the length of its buffer in milliseconds (`resend=30000` by
180
+ default), so the server knows this client sends again after a restart and
181
+ how far back; a session with the buffer set to `0` does not. With a buffer
182
+ under 22 seconds the server keeps the old behaviour on a restart.
183
+ - A reconnect the server answers with 503 "try again" is tried for up to about
184
+ 95 seconds before the session ends with `engine_lost` (it was about 7
185
+ seconds: three tries). To stop sooner, `close()` the session yourself, or
186
+ lower `vocalstack.realtime.REFUSED_TOTAL_S` (90 by default).
187
+ - A 503 that carries `Retry-After` is tried again after exactly that long
188
+ (spread upward only, by 30% at most), not after the longer of it and the
189
+ session's own 1, 2, 4, 8, 15 s waits, and does not move those waits on; a
190
+ 503 without it keeps them. The 90 seconds in all are the same.
191
+ - A connect that fails before the server answers raises `VocalStackError`
192
+ `engine_unavailable`, on the first connect too (the library's own exception
193
+ is its `__cause__`); a stream URL that is not one is not retryable.
194
+ - Cancelling the task that iterates a session while it reconnects closes the
195
+ session.
196
+
197
+ ## Errors
198
+
199
+ `VocalStackError` carries `code` (the contract's closed enum), `message`,
200
+ `status`, `retryable`, `details` (quota numbers, code suggestions), `headers`
201
+ and `retry_after`.
202
+
203
+ Verified against a language-agnostic conformance suite shared by every
204
+ VocalStack SDK and against a running API. For agents: `SKILL.md`.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "vocalstack"
7
- version = "1.1.0"
7
+ version = "1.2.2"
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"
@@ -29,7 +29,7 @@ from .errors import VocalStackError
29
29
  from .realtime import RealtimeTranscript
30
30
  from .realtime import RealtimeSession, pace_realtime
31
31
 
32
- __version__ = "1.1.0"
32
+ __version__ = "1.2.2"
33
33
 
34
34
  __all__ = [
35
35
  "DEFAULT_BASE_URL",
@@ -85,6 +85,8 @@ SentenceStatus = Union[Literal["open", "closed", "dropped"], str]
85
85
 
86
86
  VoiceStatusState = Union[Literal["preparing", "unavailable"], str]
87
87
 
88
+ ServiceLevel = Union[Literal["operational", "degraded", "outage", "unknown"], str]
89
+
88
90
 
89
91
  class AccountClosing(_Base):
90
92
  at: str
@@ -1318,6 +1320,7 @@ class StreamIngest(_Base):
1318
1320
  bytes_in: int = Field(alias="bytesIn")
1319
1321
  detected: Optional[str] = None
1320
1322
  error: Optional[str] = None
1323
+ error_code: Optional[str] = Field(default=None, alias="errorCode")
1321
1324
  failures: int
1322
1325
  finished_at: Optional[str] = Field(default=None, alias="finishedAt")
1323
1326
  last_audio_at: Optional[str] = Field(default=None, alias="lastAudioAt")
@@ -1591,6 +1594,33 @@ class SessionStats(_Base):
1591
1594
  realtime_factor: float = Field(alias="realtimeFactor")
1592
1595
 
1593
1596
 
1597
+ class ServiceDay(_Base):
1598
+ date: str
1599
+ uptime: Optional[float] = None
1600
+
1601
+
1602
+ class ServiceComponent(_Base):
1603
+ days: List["ServiceDay"]
1604
+ id: str
1605
+ name: str
1606
+ since: Optional[str] = None
1607
+ status: ServiceLevel
1608
+ uptime: Optional[float] = None
1609
+
1610
+
1611
+ class ServiceIncident(_Base):
1612
+ component: str
1613
+ ended_at: Optional[str] = Field(default=None, alias="endedAt")
1614
+ started_at: str = Field(alias="startedAt")
1615
+
1616
+
1617
+ class ServiceStatus(_Base):
1618
+ checked_at: Optional[str] = Field(default=None, alias="checkedAt")
1619
+ components: List["ServiceComponent"]
1620
+ incidents: List["ServiceIncident"]
1621
+ status: ServiceLevel
1622
+
1623
+
1594
1624
  class SessionOptions(_Base):
1595
1625
  audio: Optional["AudioFormat"] = None
1596
1626
  events: Optional["EventOptions"] = None
@@ -2012,9 +2042,15 @@ class SessionQueued(_Base):
2012
2042
 
2013
2043
 
2014
2044
  class SessionReady(_Base):
2045
+ heartbeat_s: Optional[int] = Field(default=None, alias="heartbeatS")
2046
+ resume_from: Optional[int] = Field(default=None, alias="resumeFrom")
2015
2047
  type: Literal["session.ready"] = "session.ready"
2016
2048
 
2017
2049
 
2050
+ class SessionHeartbeat(_Base):
2051
+ type: Literal["session.heartbeat"] = "session.heartbeat"
2052
+
2053
+
2018
2054
  class TranscriptCommitted(_Base):
2019
2055
  segment: "CommittedSegment"
2020
2056
  type: Literal["transcript.committed"] = "transcript.committed"
@@ -2191,7 +2227,7 @@ class ErrorFrame(_Base):
2191
2227
  type: Literal["error"] = "error"
2192
2228
 
2193
2229
 
2194
- ServerFrame = Annotated[Union[SessionLoading, SessionQueued, SessionReady, TranscriptCommitted, TranscriptDraft, TranscriptWords, TranscriptAmended, TranscriptLatency, TranscriptSpeaker, TranscriptSpeakerGender, TranscriptSpeakerIdentified, TranscriptSpeakerNumbers, TranscriptSentence, TranscriptTranslated, TranscriptVoice, TranscriptVoiceStatus, TranscriptLanguageStatus, TranscriptRetracted, TranscriptHeld, TranscriptProgress, StreamPull, SourceProgress, SourcePrepared, SessionDone, ErrorFrame], Field(discriminator="type")]
2230
+ ServerFrame = Annotated[Union[SessionLoading, SessionQueued, SessionReady, SessionHeartbeat, TranscriptCommitted, TranscriptDraft, TranscriptWords, TranscriptAmended, TranscriptLatency, TranscriptSpeaker, TranscriptSpeakerGender, TranscriptSpeakerIdentified, TranscriptSpeakerNumbers, TranscriptSentence, TranscriptTranslated, TranscriptVoice, TranscriptVoiceStatus, TranscriptLanguageStatus, TranscriptRetracted, TranscriptHeld, TranscriptProgress, StreamPull, SourceProgress, SourcePrepared, SessionDone, ErrorFrame], Field(discriminator="type")]
2195
2231
 
2196
2232
  class SubscribeUpdate(_Base):
2197
2233
  audio: Optional[bool] = None
@@ -2316,6 +2352,7 @@ class SpeakerVoice(_Base):
2316
2352
  class StreamIngest(_Base):
2317
2353
  detected: Optional[str] = None
2318
2354
  error: Optional[str] = None
2355
+ error_code: Optional[str] = Field(default=None, alias="errorCode")
2319
2356
  failures: Optional[int] = None
2320
2357
  last_audio_at: Optional[str] = Field(default=None, alias="lastAudioAt")
2321
2358
  state: IngestState
@@ -2343,11 +2380,11 @@ class SubscribeGap(_Base):
2343
2380
 
2344
2381
  SubscriberFrame = Annotated[Union[SubscribeReady, RecordingState, RecordingSettings, RecordingSilence, RecordingExpiring, TranscriptCorrected, TranscriptSpeakerGender, TranscriptSpeakerIdentified, TranscriptSpeakerNamed, TranscriptSpeakerNumbers, TranscriptionStarted, JobProgress, SpeakerVoice, StreamIngest, TranscriptionEnded, Audience, SubscribeGap], Field(discriminator="type")]
2345
2382
 
2346
- SERVER_FRAME_TYPES = frozenset(["session.loading", "session.queued", "session.ready", "transcript.committed", "transcript.draft", "transcript.words", "transcript.amended", "transcript.latency", "transcript.speaker", "transcript.speakerGender", "transcript.speakerIdentified", "transcript.speakerNumbers", "transcript.sentence", "transcript.translated", "transcript.voice", "transcript.voiceStatus", "transcript.languageStatus", "transcript.retracted", "transcript.held", "transcript.progress", "stream.pull", "source.progress", "source.prepared", "session.done", "error"])
2383
+ SERVER_FRAME_TYPES = frozenset(["session.loading", "session.queued", "session.ready", "session.heartbeat", "transcript.committed", "transcript.draft", "transcript.words", "transcript.amended", "transcript.latency", "transcript.speaker", "transcript.speakerGender", "transcript.speakerIdentified", "transcript.speakerNumbers", "transcript.sentence", "transcript.translated", "transcript.voice", "transcript.voiceStatus", "transcript.languageStatus", "transcript.retracted", "transcript.held", "transcript.progress", "stream.pull", "source.progress", "source.prepared", "session.done", "error"])
2347
2384
 
2348
2385
  _server_frame_adapter: TypeAdapter[ServerFrame] = TypeAdapter(ServerFrame)
2349
2386
 
2350
- _SERVER_FRAME_CLASSES: Dict[str, Any] = {"session.loading": SessionLoading, "session.queued": SessionQueued, "session.ready": SessionReady, "transcript.committed": TranscriptCommitted, "transcript.draft": TranscriptDraft, "transcript.words": TranscriptWords, "transcript.amended": TranscriptAmended, "transcript.latency": TranscriptLatency, "transcript.speaker": TranscriptSpeaker, "transcript.speakerGender": TranscriptSpeakerGender, "transcript.speakerIdentified": TranscriptSpeakerIdentified, "transcript.speakerNumbers": TranscriptSpeakerNumbers, "transcript.sentence": TranscriptSentence, "transcript.translated": TranscriptTranslated, "transcript.voice": TranscriptVoice, "transcript.voiceStatus": TranscriptVoiceStatus, "transcript.languageStatus": TranscriptLanguageStatus, "transcript.retracted": TranscriptRetracted, "transcript.held": TranscriptHeld, "transcript.progress": TranscriptProgress, "stream.pull": StreamPull, "source.progress": SourceProgress, "source.prepared": SourcePrepared, "session.done": SessionDone, "error": ErrorFrame}
2387
+ _SERVER_FRAME_CLASSES: Dict[str, Any] = {"session.loading": SessionLoading, "session.queued": SessionQueued, "session.ready": SessionReady, "session.heartbeat": SessionHeartbeat, "transcript.committed": TranscriptCommitted, "transcript.draft": TranscriptDraft, "transcript.words": TranscriptWords, "transcript.amended": TranscriptAmended, "transcript.latency": TranscriptLatency, "transcript.speaker": TranscriptSpeaker, "transcript.speakerGender": TranscriptSpeakerGender, "transcript.speakerIdentified": TranscriptSpeakerIdentified, "transcript.speakerNumbers": TranscriptSpeakerNumbers, "transcript.sentence": TranscriptSentence, "transcript.translated": TranscriptTranslated, "transcript.voice": TranscriptVoice, "transcript.voiceStatus": TranscriptVoiceStatus, "transcript.languageStatus": TranscriptLanguageStatus, "transcript.retracted": TranscriptRetracted, "transcript.held": TranscriptHeld, "transcript.progress": TranscriptProgress, "stream.pull": StreamPull, "source.progress": SourceProgress, "source.prepared": SourcePrepared, "session.done": SessionDone, "error": ErrorFrame}
2351
2388
 
2352
2389
 
2353
2390
  TranscriptEvent = Union[TranscriptCommitted, TranscriptDraft, TranscriptWords, TranscriptAmended, TranscriptLatency, TranscriptSpeaker, TranscriptSpeakerGender, TranscriptSpeakerIdentified, TranscriptSpeakerNumbers, TranscriptSentence, TranscriptTranslated, TranscriptVoice, TranscriptVoiceStatus, TranscriptLanguageStatus, TranscriptRetracted, TranscriptHeld, TranscriptProgress]