bakbak-python 1.0.0rc2__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.
- bakbak/__init__.py +77 -0
- bakbak/_base_client.py +642 -0
- bakbak/_client.py +219 -0
- bakbak/_constants.py +43 -0
- bakbak/_exceptions.py +410 -0
- bakbak/_models.py +93 -0
- bakbak/_response.py +51 -0
- bakbak/_retry.py +52 -0
- bakbak/_sse.py +68 -0
- bakbak/_streaming.py +432 -0
- bakbak/_types.py +79 -0
- bakbak/_utils.py +62 -0
- bakbak/_version.py +3 -0
- bakbak/_ws/__init__.py +1 -0
- bakbak/_ws/_async.py +657 -0
- bakbak/_ws/_common.py +176 -0
- bakbak/_ws/_core.py +819 -0
- bakbak/_ws/_sync.py +649 -0
- bakbak/_ws/events.py +67 -0
- bakbak/audio.py +75 -0
- bakbak/py.typed +0 -0
- bakbak/resources/__init__.py +6 -0
- bakbak/resources/tts.py +339 -0
- bakbak/resources/voices.py +139 -0
- bakbak/text.py +463 -0
- bakbak/types.py +100 -0
- bakbak/websocket.py +23 -0
- bakbak_python-1.0.0rc2.dist-info/METADATA +416 -0
- bakbak_python-1.0.0rc2.dist-info/RECORD +31 -0
- bakbak_python-1.0.0rc2.dist-info/WHEEL +4 -0
- bakbak_python-1.0.0rc2.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bakbak-python
|
|
3
|
+
Version: 1.0.0-rc.2
|
|
4
|
+
Summary: Official Python SDK for the Bakbak text-to-speech API by Raya
|
|
5
|
+
Project-URL: Documentation, https://docs.litwizlabs.com/documentation/sdk-python
|
|
6
|
+
Project-URL: Repository, https://github.com/raya-voice-ai/bakbak-python
|
|
7
|
+
Project-URL: Issues, https://github.com/raya-voice-ai/bakbak-python/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/raya-voice-ai/bakbak-python/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Raya Voice AI <support@getraya.app>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: bakbak,hindi,indic,raya,speech,text-to-speech,tts,voice
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: httpx<1,>=0.27
|
|
27
|
+
Requires-Dist: typing-extensions>=4.10
|
|
28
|
+
Requires-Dist: websockets<18,>=14.2
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Bakbak Python SDK
|
|
32
|
+
|
|
33
|
+
The official Python client for the **Bakbak text-to-speech API** by Raya: natural
|
|
34
|
+
speech in Hindi, English and other Indian languages, as whole files, as a stream,
|
|
35
|
+
or over a WebSocket built for voice agents.
|
|
36
|
+
|
|
37
|
+
- Sync (`Bakbak`) and asyncio (`AsyncBakbak`) clients with identical surfaces
|
|
38
|
+
- Whole files, Server-Sent Events streams, and a multiplexed WebSocket
|
|
39
|
+
- Sentence segmentation for LLM token streams, built in
|
|
40
|
+
- Automatic, safe retries: never after audio has been delivered
|
|
41
|
+
- Typed throughout (`py.typed`), with three runtime dependencies: `httpx`, `websockets`, `typing-extensions`
|
|
42
|
+
|
|
43
|
+
Documentation: [Python SDK guide](https://docs.litwizlabs.com/documentation/sdk-python) ·
|
|
44
|
+
[WebSocket API reference](https://docs.litwizlabs.com/api-reference/tts-websocket) ·
|
|
45
|
+
[Errors](https://docs.litwizlabs.com/documentation/tts-errors)
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
pip install --pre bakbak-python # 1.0 is in release candidates; drop --pre after 1.0.0
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The package is `bakbak-python` on PyPI; you import it as `bakbak`.
|
|
54
|
+
|
|
55
|
+
Python 3.10 or newer.
|
|
56
|
+
|
|
57
|
+
## Quickstart
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from bakbak import Bakbak
|
|
61
|
+
|
|
62
|
+
client = Bakbak() # reads BAKBAK_API_KEY
|
|
63
|
+
|
|
64
|
+
audio = client.tts.generate(
|
|
65
|
+
text="नमस्ते, आप कैसे हैं?",
|
|
66
|
+
voice_id="009ae8b5-4a03-492d-af1c-3055989ac734", # Anika M1
|
|
67
|
+
language="hi",
|
|
68
|
+
model="m1",
|
|
69
|
+
)
|
|
70
|
+
audio.save("hello.wav")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The same with asyncio:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import asyncio
|
|
77
|
+
from bakbak import AsyncBakbak
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def main() -> None:
|
|
81
|
+
async with AsyncBakbak() as client:
|
|
82
|
+
audio = await client.tts.generate(text="नमस्ते!", voice_id="…", language="hi", model="m1")
|
|
83
|
+
audio.save("hello.wav")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
asyncio.run(main())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Every example in [`examples/`](examples) runs as is with `BAKBAK_API_KEY` set.
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from bakbak import Bakbak, Timeout
|
|
95
|
+
|
|
96
|
+
client = Bakbak(
|
|
97
|
+
api_key="…", # default: BAKBAK_API_KEY
|
|
98
|
+
base_url="https://hub.getraya.app", # default: BAKBAK_BASE_URL, then this
|
|
99
|
+
timeout=Timeout(connect=5, read=60, total=None),
|
|
100
|
+
max_retries=2,
|
|
101
|
+
default_headers={"X-Team": "voice"},
|
|
102
|
+
http_client=None, # your own httpx.Client, e.g. with a proxy
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Option | Default | Meaning |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `api_key` | `BAKBAK_API_KEY` | Sent as `X-API-Key`. Environment variables are read when the client is constructed, never at import. |
|
|
109
|
+
| `base_url` | `BAKBAK_BASE_URL`, then `https://hub.getraya.app` | The WebSocket URL is derived from it (`https` → `wss`). |
|
|
110
|
+
| `timeout` | 5 s connect, 60 s read | A `Timeout(connect, read, total)`; a number, which sets the read timeout (and caps connect at it); or `None` for none. The read timeout includes the time to first audio. `total` limits a whole call, retries included. |
|
|
111
|
+
| `max_retries` | `2` | Retries of a failed request before any audio, so at most 3 attempts. |
|
|
112
|
+
| `default_headers` | none | Added to every request. |
|
|
113
|
+
| `http_client` | a pooled `httpx.Client` | Bring your own (`httpx.AsyncClient` for `AsyncBakbak`). The SDK does not close it. |
|
|
114
|
+
|
|
115
|
+
Every HTTP method also takes `timeout`, `max_retries`, `extra_headers` and (for
|
|
116
|
+
synthesis) `extra_body`. `client.with_options(...)` returns a copy with some
|
|
117
|
+
options changed that shares the connection pool:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
patient = client.with_options(timeout=120, max_retries=4)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Whole files
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
audio = client.tts.generate(
|
|
127
|
+
text="आपका ऑर्डर कल पहुँचेगा।",
|
|
128
|
+
voice_id=voice_id,
|
|
129
|
+
language="hi",
|
|
130
|
+
model="m1",
|
|
131
|
+
speed=1.1, # 0.5 to 1.5
|
|
132
|
+
output_format={"container": "wav", "encoding": "pcm_s16le", "sample_rate": 24000},
|
|
133
|
+
)
|
|
134
|
+
audio.data # bytes, exactly as received
|
|
135
|
+
audio.request_id # quote it to support
|
|
136
|
+
audio.content_type # audio/wav, audio/mpeg, audio/pcm, audio/basic, application/octet-stream
|
|
137
|
+
audio.encoding, audio.sample_rate # from X-Audio-Format / X-Audio-Sample-Rate
|
|
138
|
+
audio.save("out.wav")
|
|
139
|
+
audio.to_wav() # WAV bytes; raw PCM, mu-law and A-law get a header
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`output_format`:
|
|
143
|
+
|
|
144
|
+
| Field | Values | Notes |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| `container` | `raw`, `wav`, `mp3` | Streams (SSE and WebSocket) accept only `raw`. |
|
|
147
|
+
| `encoding` | `pcm_f32le`, `pcm_s16le`, `pcm_mulaw`, `pcm_alaw` | Required for `raw` and `wav`; leave it out for `mp3`. Mono. |
|
|
148
|
+
| `sample_rate` | `8000`, `16000`, `22050`, `24000` | Default 24000. |
|
|
149
|
+
|
|
150
|
+
Without `output_format`, a whole file is 24 kHz WAV and a stream is 24 kHz
|
|
151
|
+
32-bit float PCM. Languages, models and encodings are typed as the known values
|
|
152
|
+
plus any string, so a value the server adds later needs no SDK release.
|
|
153
|
+
|
|
154
|
+
## Streaming (SSE)
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
with client.tts.stream(
|
|
158
|
+
text="आपका पैकेज आज शाम तक पहुँच जाएगा।",
|
|
159
|
+
voice_id=voice_id,
|
|
160
|
+
language="hi",
|
|
161
|
+
model="m1",
|
|
162
|
+
output_format={"container": "raw", "encoding": "pcm_s16le", "sample_rate": 24000},
|
|
163
|
+
) as stream:
|
|
164
|
+
for chunk in stream: # AudioChunk(audio, step_time, request_id)
|
|
165
|
+
player.write(chunk.audio)
|
|
166
|
+
print(stream.request_id, stream.audio_bytes)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The request is sent when the stream is entered or first iterated. A chunk always
|
|
170
|
+
holds whole samples: if the server splits a sample across two events, the SDK
|
|
171
|
+
carries the remainder over. A stream also has `iter_audio()` (bytes only),
|
|
172
|
+
`read()` (all of it) and `save(path)`. It can be read once. On `AsyncBakbak` it is
|
|
173
|
+
`async with` / `async for`, and `read()`, `save()` and `close()` are awaitable.
|
|
174
|
+
|
|
175
|
+
## WebSocket: many requests, one connection
|
|
176
|
+
|
|
177
|
+
The WebSocket carries any number of streaming requests over one connection, and
|
|
178
|
+
saves the per-request connection and gateway cost. It is the fastest path to
|
|
179
|
+
first audio and the one to use for voice agents.
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
async with client.tts.websocket(
|
|
183
|
+
voice_id=voice_id,
|
|
184
|
+
language="hi",
|
|
185
|
+
model="m1",
|
|
186
|
+
output_format={"container": "raw", "encoding": "pcm_s16le", "sample_rate": 16000},
|
|
187
|
+
) as ws: # opens the socket now (prewarm)
|
|
188
|
+
ctx = ws.context() # requests on a context play in order
|
|
189
|
+
await ctx.send(text="पहला वाक्य।")
|
|
190
|
+
await ctx.send(text="दूसरा वाक्य।")
|
|
191
|
+
ctx.end_input()
|
|
192
|
+
async for audio in ctx.audio(): # bytes, in order; raises the first failure
|
|
193
|
+
player.write(audio)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- **Contexts.** `ws.context(context_id=None, **defaults)` returns a context; the
|
|
197
|
+
id defaults to a random `ctx_…`. Requests on one context run one after another;
|
|
198
|
+
different contexts run at the same time. Fields left out of `send()` come from
|
|
199
|
+
the context's defaults, then the WebSocket's.
|
|
200
|
+
- **Events.** `ctx.events()` yields `Chunk(audio, request)`, `Done(request)`,
|
|
201
|
+
`Failed(request, error)` and `Cancelled(request)` in order, and ends after
|
|
202
|
+
`end_input()` once every request has an outcome. An error ends its own request
|
|
203
|
+
only. `ctx.audio()` yields just the bytes.
|
|
204
|
+
- **Request handles.** `send()` returns a handle: `await handle` gives
|
|
205
|
+
`RequestResult(request_id, audio_bytes, cancelled)` or raises the request's
|
|
206
|
+
error, and `async for audio in handle` yields that request's audio.
|
|
207
|
+
- **Cancel.** `await ctx.cancel()` stops the context at once: unfinished requests
|
|
208
|
+
end as `Cancelled`, all of its audio not yet handed to you is dropped, and a
|
|
209
|
+
`send_stream` feeding it stops sending and returns. The cancel still reaches the
|
|
210
|
+
server if the task calling it is itself cancelled. The context stays usable.
|
|
211
|
+
- **Connection management.** The first send opens the socket if you did not.
|
|
212
|
+
Server restarts (close 1001, or a draining refusal) are handled by resending on
|
|
213
|
+
a new connection; a dropped connection fails only the requests that already
|
|
214
|
+
had audio (`StreamInterruptedError`) and resends the rest. Every unfinished
|
|
215
|
+
request always gets an outcome, and cancelling the task awaiting `send()` never
|
|
216
|
+
leaves a half-sent request behind. `send()` waits only if the connection's
|
|
217
|
+
limits (64 unfinished requests, 16 busy contexts) are reached; open more
|
|
218
|
+
WebSockets for more parallelism. A WebSocket can live for days: finished
|
|
219
|
+
contexts are released, so its memory does not grow with the requests it serves.
|
|
220
|
+
- **Connection-level errors.** Errors about no request in particular go to
|
|
221
|
+
`client.tts.websocket(on_error=callback)`.
|
|
222
|
+
|
|
223
|
+
The sync client has the same API; it reads the socket on a background thread,
|
|
224
|
+
so read `ctx.audio()` on one thread while another sends:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
with client.tts.websocket(voice_id=voice_id, language="hi", model="m1") as ws:
|
|
228
|
+
ctx = ws.context()
|
|
229
|
+
handle = ctx.send(text="नमस्ते।")
|
|
230
|
+
ctx.end_input()
|
|
231
|
+
audio = b"".join(ctx.audio())
|
|
232
|
+
print(handle.result().request_id)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Speaking an LLM's reply as it is written
|
|
236
|
+
|
|
237
|
+
`ctx.send_stream(tokens)` splits text that arrives in pieces into sentences and
|
|
238
|
+
sends each one the moment it is complete, then calls `end_input()`. It takes
|
|
239
|
+
strings, or the stream events of OpenAI-, Anthropic- and Gemini-style SDKs
|
|
240
|
+
directly: the text delta is found by duck typing (`choices[0].delta.content`,
|
|
241
|
+
`content_block_delta` → `delta.text`, `.text`), and tool calls or reasoning
|
|
242
|
+
deltas are skipped. No LLM SDK is imported.
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from openai import AsyncOpenAI
|
|
246
|
+
|
|
247
|
+
llm = AsyncOpenAI()
|
|
248
|
+
tokens = await llm.chat.completions.create(model="…", messages=messages, stream=True)
|
|
249
|
+
|
|
250
|
+
ctx = ws.context()
|
|
251
|
+
sender = asyncio.create_task(ctx.send_stream(tokens))
|
|
252
|
+
async for audio in ctx.audio():
|
|
253
|
+
player.write(audio)
|
|
254
|
+
await sender
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
See [`examples/llm_streaming.py`](examples/llm_streaming.py).
|
|
258
|
+
|
|
259
|
+
## Voices
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
voices = client.voices.list(model="m1", language="hi") # filtered by the SDK
|
|
263
|
+
for voice in voices:
|
|
264
|
+
print(voice.id, voice.name, voice.language, voice.model)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
A voice belongs to one model; `m1` voices use `en` for English.
|
|
268
|
+
|
|
269
|
+
## Sentence segmentation
|
|
270
|
+
|
|
271
|
+
The splitter `send_stream` uses is public:
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
from bakbak.text import Segmenter, split_sentences
|
|
275
|
+
|
|
276
|
+
split_sentences("Dr. Rao will call at 5 p.m. today. Please stay on the line.")
|
|
277
|
+
# ['Dr. Rao will call at 5 p.m. today.', 'Please stay on the line.']
|
|
278
|
+
|
|
279
|
+
segmenter = Segmenter(eager_first_clause=True) # first audio sooner on a long first sentence
|
|
280
|
+
for token in tokens:
|
|
281
|
+
for sentence in segmenter.push(token):
|
|
282
|
+
...
|
|
283
|
+
remaining = segmenter.flush()
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
It understands the danda (।, ॥), titles and initials (`Dr.`, `डॉ.`, `A. P. J.`),
|
|
287
|
+
decimals and domains (`3.14`, `getraya.app`), list markers and abbreviations, and
|
|
288
|
+
never splits inside an Indic conjunct. Options: `min_chars` (20),
|
|
289
|
+
`first_min_chars` (1), `max_chars` (400, at most 5,000), `eager_first_clause`
|
|
290
|
+
(False), `first_clause_min_chars` (24). Lengths are counted in code points. The
|
|
291
|
+
JavaScript SDK and the LiveKit plugin split every text exactly the same way.
|
|
292
|
+
|
|
293
|
+
## Audio helpers
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
from bakbak.audio import to_wav
|
|
297
|
+
|
|
298
|
+
wav = to_wav(raw_bytes, "pcm_mulaw", 8000)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
`pcm_s16le` gets the canonical 44-byte header; `pcm_f32le`, `pcm_alaw` and
|
|
302
|
+
`pcm_mulaw` get the 58-byte header (with a `fact` chunk) that their WAV formats
|
|
303
|
+
require. There are no playback helpers: hand the bytes to your audio library.
|
|
304
|
+
|
|
305
|
+
## Errors
|
|
306
|
+
|
|
307
|
+
Every error derives from `bakbak.BakbakError`:
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
BakbakError
|
|
311
|
+
├── APIError the service answered, or a stream broke
|
|
312
|
+
│ ├── APIStatusError an HTTP status, or an in-band error before audio
|
|
313
|
+
│ │ ├── BadRequestError (400), AuthenticationError (401),
|
|
314
|
+
│ │ ├── InsufficientCreditsError (402), PermissionDeniedError (403),
|
|
315
|
+
│ │ ├── NotFoundError (404), RequestTooLargeError (413),
|
|
316
|
+
│ │ ├── UnprocessableEntityError (422), RateLimitError (429),
|
|
317
|
+
│ │ └── InternalServerError (≥ 500)
|
|
318
|
+
│ └── StreamInterruptedError failed after audio was delivered
|
|
319
|
+
└── APIConnectionError no usable answer: network, TLS, DNS
|
|
320
|
+
├── APITimeoutError
|
|
321
|
+
└── WebSocketClosedError
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
`APIError` has `status`, `error_code`, `message`, `retryable`, `request_id` and
|
|
325
|
+
`body` (the parsed JSON, so fields such as `required_inr` stay readable).
|
|
326
|
+
`StreamInterruptedError` adds `audio_bytes`: how much audio you received.
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
import bakbak
|
|
330
|
+
|
|
331
|
+
try:
|
|
332
|
+
audio = client.tts.generate(text=text, voice_id=voice_id, language="hi")
|
|
333
|
+
except bakbak.InsufficientCreditsError as e:
|
|
334
|
+
print("Top up:", e.body["required_inr"])
|
|
335
|
+
except bakbak.APIStatusError as e:
|
|
336
|
+
print(e.status, e.error_code, e.message, e.request_id)
|
|
337
|
+
except bakbak.APIConnectionError:
|
|
338
|
+
print("Could not reach the API")
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Errors never contain your API key or request headers, in any attribute, `str()`,
|
|
342
|
+
`repr()` or chained cause. A key with whitespace, control or non-ASCII characters
|
|
343
|
+
(a copy-paste slip) is refused when the client is created, without echoing it.
|
|
344
|
+
The SDK never follows redirects, on HTTP or the WebSocket: a 3xx is an
|
|
345
|
+
`APIStatusError`, so the key is never sent to another origin. See the
|
|
346
|
+
[error reference](https://docs.litwizlabs.com/documentation/tts-errors) for every
|
|
347
|
+
`error_code`.
|
|
348
|
+
|
|
349
|
+
## Retries and timeouts
|
|
350
|
+
|
|
351
|
+
Before any audio arrives, the SDK retries connection errors, timeouts, and errors
|
|
352
|
+
whose `retryable` is true (by default 408, 429, 500, 502, 503 and 504): up to
|
|
353
|
+
`max_retries` times, waiting `Retry-After` when the server sends it (at most
|
|
354
|
+
60 s), otherwise 0.5 s, 1 s, 2 s … with jitter. **Once audio has been delivered
|
|
355
|
+
it never retries**: the start would play twice, and the request has already been
|
|
356
|
+
charged. You get `StreamInterruptedError` with the `request_id` and `audio_bytes`
|
|
357
|
+
instead.
|
|
358
|
+
|
|
359
|
+
On the WebSocket, a retryable refusal is resent on its context only if no later
|
|
360
|
+
request of that context was already sent; otherwise resending would break the
|
|
361
|
+
order, and the error is delivered.
|
|
362
|
+
|
|
363
|
+
## Raw responses
|
|
364
|
+
|
|
365
|
+
```python
|
|
366
|
+
raw = client.tts.with_raw_response.generate(text=text, voice_id=voice_id, language="hi")
|
|
367
|
+
raw.headers, raw.status_code, raw.request_id, raw.retries_taken
|
|
368
|
+
audio = raw.parse()
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## Forward compatibility
|
|
372
|
+
|
|
373
|
+
Fields the SDK does not model yet go in `extra_body` (merged into the request
|
|
374
|
+
body) and `extra_headers`. Unknown response fields and stream events are
|
|
375
|
+
ignored. The SDK sends exactly the fields you give it; the server validates them.
|
|
376
|
+
|
|
377
|
+
## Latency tips
|
|
378
|
+
|
|
379
|
+
- **Reuse one client.** It keeps connections alive; `client.prewarm()` opens one
|
|
380
|
+
ahead of the first request.
|
|
381
|
+
- **Use the WebSocket for agents.** Open it early (`await ws.connect()`, or
|
|
382
|
+
`async with`), so the first request pays no handshake. Measured against a
|
|
383
|
+
staging deployment of the API (m1, 20 sequential requests each, kept-alive
|
|
384
|
+
connections, `examples/bench_ttfa.py`): time to first audio p50 **20.7 ms over
|
|
385
|
+
the WebSocket** versus 33.3 ms over SSE.
|
|
386
|
+
- **Stream sentence by sentence** with `send_stream`, and consider
|
|
387
|
+
`Segmenter(eager_first_clause=True)` when first sentences are long.
|
|
388
|
+
- **Ask for the format you play.** For phone calls use
|
|
389
|
+
`{"container": "raw", "encoding": "pcm_mulaw", "sample_rate": 8000}`, and skip
|
|
390
|
+
resampling and transcoding (see [`examples/telephony.py`](examples/telephony.py)).
|
|
391
|
+
- **Keep the event loop free.** `send_stream` reads a sync iterable on the event
|
|
392
|
+
loop; pass an async iterable from an async LLM client.
|
|
393
|
+
|
|
394
|
+
## Logging
|
|
395
|
+
|
|
396
|
+
The SDK logs to `logging.getLogger("bakbak")` at DEBUG level only: request ids,
|
|
397
|
+
statuses, timings and sizes. It never logs the API key or any text.
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
import logging
|
|
401
|
+
|
|
402
|
+
logging.basicConfig()
|
|
403
|
+
logging.getLogger("bakbak").setLevel(logging.DEBUG)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## More
|
|
407
|
+
|
|
408
|
+
- [Python SDK guide](https://docs.litwizlabs.com/documentation/sdk-python)
|
|
409
|
+
- [WebSocket API reference](https://docs.litwizlabs.com/api-reference/tts-websocket)
|
|
410
|
+
- [Errors and error codes](https://docs.litwizlabs.com/documentation/tts-errors)
|
|
411
|
+
- [`examples/`](examples): runnable scripts for each feature
|
|
412
|
+
- [`conformance/BEHAVIOR.md`](conformance/BEHAVIOR.md): the behaviour every official
|
|
413
|
+
Bakbak client follows, and the API in one page
|
|
414
|
+
- [CHANGELOG](CHANGELOG.md) · [CONTRIBUTING](CONTRIBUTING.md) · [SECURITY](SECURITY.md)
|
|
415
|
+
|
|
416
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
bakbak/__init__.py,sha256=4jyHYIkUwR9YqDTttwAyH-LZVsZDH20MZIdBz_5L6IE,1933
|
|
2
|
+
bakbak/_base_client.py,sha256=zr-8VzXrrh2x-o2LicrcRr21IgzmLsmRyr-Q7Pyg9ak,24074
|
|
3
|
+
bakbak/_client.py,sha256=BMcqCopcWQUMmTEtnflyVl9LNI3WUL8Yx1LVs9qsMwI,7240
|
|
4
|
+
bakbak/_constants.py,sha256=BGLaL0XjJauvw9llrn32tGOCWD9mzFdYSFM5I7ETLr4,1546
|
|
5
|
+
bakbak/_exceptions.py,sha256=_EOIvvUUVpmyBbXRR029kkkNQ8wKgd9sV55fw2dyh5A,12282
|
|
6
|
+
bakbak/_models.py,sha256=ztHAz1BHW5e0aaUOVk5cMTMqut8l5FNb9dLJK1vDv78,2947
|
|
7
|
+
bakbak/_response.py,sha256=4FsjJQ2RpvQed9n6pNcGi-J3Xr8yRHPbMWL0S_dbb2Y,1410
|
|
8
|
+
bakbak/_retry.py,sha256=-VczQl0Nvw11rqHezWKtQJ3WgEQRxK2SZm924xRG-4g,1845
|
|
9
|
+
bakbak/_sse.py,sha256=6aRsKzEc5qbKHhwQmDF246Y4PWkEerRCf8SdF3aV7z4,2203
|
|
10
|
+
bakbak/_streaming.py,sha256=XQbrZx07QUVE-BMOY_jxWz_KOneA5piq6tPZ1VXwwF8,15093
|
|
11
|
+
bakbak/_types.py,sha256=aaT2kE7JKVhqqHbT5NeEaF_4Gtz9W7sAHXwW-Fv37sI,2715
|
|
12
|
+
bakbak/_utils.py,sha256=tELuXn6_oB6G-FDvl33iRE3CoD2jvYb7x91dHNXJmzs,2105
|
|
13
|
+
bakbak/_version.py,sha256=2MitBX9zPPZlEIY5BizpjzKW0FEbnzwyCeIrwd3pNQI,151
|
|
14
|
+
bakbak/audio.py,sha256=iwptZOtZQPqzG44NITjN9xMG3nNS4h8dRZ1JQjLV99Y,2934
|
|
15
|
+
bakbak/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
bakbak/text.py,sha256=JLZ8CyRZtCOyPhh3eXzKidI5XOUYPJKN8iZQTzY_LO0,17539
|
|
17
|
+
bakbak/types.py,sha256=kJEnP-_egiZ0-f-cBo8hvNOvSKuxVqN80jSV85hI-uY,2769
|
|
18
|
+
bakbak/websocket.py,sha256=ZqDQaW9LMuKLy0SlNF50E5VsxRihNlxDOA4NTNAEtFQ,616
|
|
19
|
+
bakbak/_ws/__init__.py,sha256=NboBl7L4CfWSqx-iFrcLKrfkDqyhEH01RzNgEiDN1EY,92
|
|
20
|
+
bakbak/_ws/_async.py,sha256=7QRSEkx5FgYFA-VTi9I2HyEusUjKYqrsftrTkksvbCk,24230
|
|
21
|
+
bakbak/_ws/_common.py,sha256=W72XcjTBX9L2KvJUMDmPB2-E8f3rOZbYIHOSGkspDCE,6595
|
|
22
|
+
bakbak/_ws/_core.py,sha256=l1KFWnJSSwdU-lFtmFOBVWfT09u0n16SHCX3wsKASeU,31561
|
|
23
|
+
bakbak/_ws/_sync.py,sha256=1cXqasKMoUmq5wqjJUIQBfbb5G0pj6fW0Nd0luqBKJ8,23689
|
|
24
|
+
bakbak/_ws/events.py,sha256=XivGexveJ0S8pCn3QzHpDNhmNCYzUo6DKxi6fLMzsMI,1504
|
|
25
|
+
bakbak/resources/__init__.py,sha256=_N8VT-6LIFPNYfPMXXyLAiYYMUNii065LJhc9Dw8uGk,187
|
|
26
|
+
bakbak/resources/tts.py,sha256=sVNSnH0WMe9a171gS8mMPxlXqj02y7iI1PIt1RkEYwk,12100
|
|
27
|
+
bakbak/resources/voices.py,sha256=VelLLUMUdcwwdNkUyCGk9Sa0jQiGCWbNz7PKGZHRGuE,4380
|
|
28
|
+
bakbak_python-1.0.0rc2.dist-info/METADATA,sha256=N12uMwiVG6UEsKwxNxZxnpsYxDRvfRmVrYE_MRJovtQ,17203
|
|
29
|
+
bakbak_python-1.0.0rc2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
30
|
+
bakbak_python-1.0.0rc2.dist-info/licenses/LICENSE,sha256=JzJTNbYfc4Z87_ufzTAg5U2SChNgyYTsgJ9aq0kv74I,11344
|
|
31
|
+
bakbak_python-1.0.0rc2.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Raya Voice AI
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|