Gradium Text-to-Speech
Gradium TTS is a proprietary text-to-speech model that converts text input into audio output.
Model details
Example usage
Gradium TTS is a proprietary text-to-speech model built to convert written text into spoken audio. It's designed as a streaming model, meaning it doesn't operate under fixed context or output limits the way many token-based models do — instead of capping input length or output duration, it can process and generate audio continuously as a stream, which is well-suited for real-time or long-form speech applications.
Modalities: The model accepts text as input and produces audio as its only output, making it a straightforward, purpose-built TTS system rather than a multimodal model.
Licensing: The model is released under a proprietary license. Gradium does permit commercial use of the model's outputs, and the specifics of permitted use are outlined in Gradium's Terms of Service.
See full documentation.
The model runs over a websocket: the client sends a JSON setup object (voice and output format), streams the text, and signals end-of-text, while the server streams back a ready message with the sample rate followed by raw audio chunks.
1import asyncio
2
3from gradium import GradiumClient
4from gradium.client import SOURCE
5
6MODEL_ID = "" #Get from Baseten dashboard
7
8class SelfHostedTTSClient(GradiumClient):
9 """GradiumClient for a self-hosted / Baseten deployment."""
10
11 @property
12 def headers(self) -> dict:
13 return {
14 "Authorization": f"Api-Key {self._api_key}",
15 "x-api-source": SOURCE,
16 }
17
18client = SelfHostedTTSClient(
19 base_url=f"https://model-{MODEL_ID}.api.baseten.co/environments/production/",
20 api_key=os.getenv("BASETEN_API_KEY"),
21 tts_route="websocket"
22)
23setup = {"voice_id": "NbpkqMVS3CJeq2j8", "output_format": "wav"}
24
25stream = await client.tts_stream(setup, "Hello from Baseten!")
26
27audio = bytearray()
28async for chunk in stream.iter_bytes():
29 audio += chunk
30
31with open("output.wav", "wb") as f:
32 f.write(audio)
33print(f"wrote {len(audio)} bytes")1[
2 {
3 "type": "ready",
4 "model_name": "",
5 "sample_rate": 48000,
6 "frame_size": 3840,
7 "audio_stream_names": [
8 "tts"
9 ],
10 "text_stream_names": [
11 "tts"
12 ],
13 "request_id": "req",
14 "client_req_id": ""
15 },
16 {
17 "type": "audio",
18 "audio": "UklGRv////9XQVZFZm10IBAAAAABAAEAgLsAAAB3AQACABAAZGF0Yf////8=",
19 "start_s": 0,
20 "stop_s": 0,
21 "stream_id": 0,
22 "client_req_id": ""
23 },
24 {
25 "type": "need_more_text",
26 "client_req_id": ""
27 },
28 {
29 "type": "text",
30 "text": "Hello",
31 "start_s": 0.24,
32 "stop_s": 0.64,
33 "stream_id": 0,
34 "client_req_id": ""
35 },
36 {
37 "type": "audio",
38 "audio": "+//w/+///f8QAB0AGQARABEAFAAWABkAGwAeACAAIwAlACgAKgAtAC8AMgA0AA==",
39 "start_s": 0,
40 "stop_s": 0.08,
41 "stream_id": 0,
42 "client_req_id": ""
43 },
44 {
45 "type": "text",
46 "text": "from",
47 "start_s": 0.64,
48 "stop_s": 1.04,
49 "stream_id": 0,
50 "client_req_id": ""
51 },
52 {
53 "type": "text",
54 "text": "Baseten!",
55 "start_s": 1.04,
56 "stop_s": 2.16,
57 "stream_id": 0,
58 "client_req_id": ""
59 },
60 {
61 "type": "end_of_stream"
62 }
63]