wss://api.pascalai.co/v1/text-to-speech/realtime
Text to speech realtime
Send a finished sentence and receive audio on the same WebSocket.
wss://api.pascalai.co/v1/text-to-speech/realtime?model=sarvam-bulbul-live
Send an API key as Authorization: Bearer. A browser sends the key as api_key on the query string. File synthesis stays on Text to speech.
| Field | Type | Description |
|---|---|---|
modelRequired | string | Catalogue id of the live model. piper-en-us-lessac-medium, matcha-en-ljspeech, or pocket-tts. |
api_key | string | API key, sent on the query string. |
Client messages
Wait for session.created. Send one session.update, then each speak. session.update is accepted only before the first sentence. The server answers with binary PCM16 frames.
| Field | Type | Description |
|---|---|---|
session.update | object | JSON text frame. session holds the fields in the Session section. Send it once, before the first speak. |
speak | object | JSON text frame. text is one finished sentence. |
session.close | object | JSON text frame. Ends the session and closes the socket. |
Session
These fields are the session object inside session.update.
| Field | Type | Description |
|---|---|---|
speak.textRequired | string | The words to speak. Same field on every live TTS model. |
session.speedDefault 1 | number | Piper and Matcha only. 0.5 to 2. Default 1. Omit on Pocket. |
session.voiceDefault alba | string | Pocket TTS Realtime only. One of 26 speakers. Default alba. Omit on Piper and Matcha. |
Server events
| Field | Type | Description |
|---|---|---|
session.created | object | The socket is open. session.id, session.model, and session.prepaid_seconds. |
binary frame | bytes | Little-endian PCM16, mono. A JSON frame carries sample_rate before the audio. |
response.done | object | The current sentence has finished. |
error | object | error.type, error.code, error.message, and error.param. The socket then closes. |
Billing
A session is charged $0.05 plus the audio produced, at $0.00333 per minute. 60 seconds of audio is one minute. 61 seconds is two minutes. The text length is checked before the sentence starts, at about 14 characters per second. A session runs for up to 5 hours of audio. The socket closes after 30 seconds without a message.
Example
const socket = new WebSocket(
'wss://api.pascalai.co/v1/text-to-speech/realtime?model=sarvam-bulbul-live&api_key=' + key
);
socket.binaryType = 'arraybuffer';
socket.onmessage = (event) => {
if (typeof event.data !== 'string') return;
const payload = JSON.parse(event.data);
if (payload.type === 'session.created') {
socket.send(JSON.stringify({ type: 'session.update', session: { speed: 1 } }));
socket.send(JSON.stringify({
type: 'speak',
text: 'Keep walking toward the river.',
}));
}
};
// binary Int16 PCM16 frames, then response.doneModels
sarvam-bulbul-liveLive Bulbul. $30 per million characters. linear16 at 24 kHz.deepgram-aura-2-liveLive Aura-2. $30 per million characters. Same voices as the file model.deepgram-aura-1-liveLive Aura-1. $15 per million characters.deepgram-flux-liveLive Flux speech. $45 per million characters.piper-en-us-lessac-mediumLive Piper Lessac Medium. WebSocket only. $0.00333 / min plus the $0.05 request fee.matcha-en-ljspeechLive Matcha LJSpeech. WebSocket only. $0.00333 / min plus the $0.05 request fee.pocket-ttsLive Pocket TTS. WebSocket only. $0.00333 / min plus the $0.05 request fee.