เชื่อมต่อครั้งเดียว ส่ง start แล้วสลับส่ง text flush cancel และ end การเชื่อมต่อที่เปิดอยู่ถือหนึ่งช่องคำขอพร้อมกันฝั่งเสียงพูดของแพ็กเกจจนกว่าจะปิด คู่มือเสียงพูดสดสองทาง อธิบายวงจรการเชื่อมต่อและค่าบริการ
เฮดเดอร์#
authorizationBearer pxa_...จำเป็นAuthorization: Bearer pxa_... (recommended).
x-api-keypxa_...Alternative to the Authorization header. Ignored when Authorization is present.
การเชื่อมต่อ#
wss://api.paxalabs.com/v1/tts/live Binary frames carry audio in the session's format. JSON text frames carry control, billing, and timing events.
ข้อความฝั่งไคลเอนต์#
startConfigures the session. Must be the first frame; exactly one per connection.
type"start"จำเป็นmodelstringจำเป็นTTS model id, for example paxa-tts-flash-v2.
voicestringจำเป็นVoice id, resolved as on POST /v1/tts. A designed voice serves the connection until it closes, even if it is deleted meanwhile.
format"mp3" or "opus" or "wav" or "pcm" or "mulaw" or "alaw"Audio format for the session's binary frames, as format on POST /v1/tts.
sample_rate8000 or 16000 or 22050 or 24000 or 32000 or 44100 or 48000Sample rate of pcm and wav, in Hz. Paxa TTS Flash v2 serves 8000, 16000, 22050, 24000, 32000, 44100, 48000, and Paxa TTS Flash serves 24000 only. For any other format the value may only restate that format's own rate, which is 8000 for mulaw and alaw. Fixed for the connection, like format. A rate the model doesn't serve answers unsupported_format. A request costs the same at every rate.
timestamps"word" or "sentence" or "utterance"Adds timing events to the session at 1.25x the standard rate, applied to the connection's cumulative character count.
speednumberSpeaking rate, as a multiplier on the voice's own design speed. It runs from 0.5 to 1.5, and 1 is the voice as designed. Rate changes how the audio sounds. It does not change how many characters were sent. A request costs the same at every rate. Values round to the nearest 0.05. Fixed for the connection, like model and voice.
language"auto" or "th" or "en" or "zh"Sets how codes, digits, and symbols are read. Words keep the language of their script, and a number inside Thai or Chinese text keeps that text's language. Elsewhere, "th" reads them in Thai (AB2039 with Thai letter names and digits) and "en" in English. "zh" reads codes in English, a number next to Chinese characters in Mandarin, and other digits and symbols in Thai. "auto", the default, takes the language most of the text is written in, counting English only in words of three or more letters, and Thai on a tie. Under "auto", a bare number, AB2039, or 250 ml reads as Thai, and ISO9001 or 100 USD as English. Text with no Thai, Chinese, digits, or counted English word reads as English when a two-letter word has a lowercase letter, such as Hi or I'm OK. Pin "th" or "en" to choose how a short number or code reads. A request costs the same in every language. Fixed for the connection, like model and voice. "auto" resolves on each leg's own text, and a leg that is only a number reads as Thai.
temperaturenumberSets how much the pacing, pauses, breaths, and melody of a reading vary from one request to the next. It runs from 0 to 2, and 0.5 is the default. They vary least at 0 and most at 2. Paxa TTS Flash v2 reads it. Any other model accepts only a value that rounds to 0.5, and any other answers validation. A request costs the same at every temperature. Values round to the nearest 0.1. Fixed for the connection, like model and voice. A refused value answers an in-band validation error, and the connection stays open for a corrected start frame.
textAppends text. The server auto-flushes on a newline, sentence-ending punctuation, or a buffered-length threshold, holding back a tag still open at the end of the buffer for up to that threshold.
type"text"จำเป็นtextstringจำเป็นText appended to the synthesis buffer. A frame longer than the model's max_chars answers an in-band text_too_long error. Every Paxa TTS Flash v2 voice reads tags, as does a Paxa TTS Flash (paxa-tts-flash-v1) voice whose emotion_tags list is not empty. On those voices, tags that no words follow yet wait in the buffer, and each leg opens with the tags the previous leg ended in. A frame that would take the waiting tags and the opening tags past max_chars also answers text_too_long, as does one that would leave opening tags longer than half of max_chars. A frame whose tag the voice cannot read answers an in-band tag_invalid error and leaves the buffer as it was. Billing is cumulative per connection: the total charged equals what one POST /v1/tts call carrying the text of every charged leg would cost.
flushSynthesizes the buffered text now. A flush with nothing to speak in the buffer (empty, or tags alone) answers flushed immediately.
type"flush"จำเป็นcancelStops the leg being spoken and discards the buffered text. Use it when the speaker interrupts. The leg in flight was charged before its first byte and stays charged. The discarded buffer was never charged. A session that sends one sentence per frame pays only for the sentence it interrupted. The server answers cancelled, and the session stays open for more text.
type"cancel"จำเป็นendFlushes any remaining text, then the server sends done and closes with code 1000.
type"end"จำเป็นอีเวนต์ฝั่งเซิร์ฟเวอร์#
เฟรมเสียง: Raw audio bytes in the session's format for the current leg, in delivery order between that leg's charged and flushed events.
startedThe session is configured and ready for text.
type"started"จำเป็นconnectionstringจำเป็นConnection id; quote it in support requests (the x-request-id analog).
modelstringจำเป็นThe model serving this session.
voicestringจำเป็นCanonical voice id the session resolved to.
format"mp3" or "opus" or "wav" or "pcm" or "mulaw" or "alaw"จำเป็นThe audio format every binary frame of the session carries.
sample_rateintegerจำเป็นThe sample rate of the session's audio in Hz, which is the rate the start frame asked for or else the format's own. Check it before playing raw pcm.
timestamps"word" or "sentence" or "utterance"Echoed when the session requested timing.
speednumberEchoed when the session asked for a rate of its own.
language"th" or "en" or "zh"Echoed when the session pinned a language.
temperaturenumberEchoed when the session asked for a temperature of its own.
chargedBilling receipt, sent before the leg's audio. Receipts replace the x-credits-charged header.
type"charged"จำเป็นseqintegerจำเป็นThe synthesis leg this receipt covers, starting at 1.
charsintegerจำเป็นCharacters synthesized in this leg.
creditsnumberจำเป็นCredits charged for this leg, exact to a hundredth. The 0.1-credit request floor applies once per connection, on the first charged leg.
total_creditsnumberจำเป็นTotal credits charged on this connection so far.
timingTiming spans; sent only when the session set timestamps.
type"timing"จำเป็นseqintegerจำเป็นThe leg these spans belong to.
spansarray of objectsจำเป็นTimes are relative to the start of this leg's audio (each leg is an independent audio stream).
ดูฟิลด์ย่อยซ่อนฟิลด์ย่อย
spans[].textstringจำเป็นThe spoken input text this span covers. An emotion tag takes no span.
spans[].startnumberจำเป็นWhere the span begins in the audio, in seconds.
spans[].endnumberจำเป็นWhere the span ends in the audio, in seconds.
flushedThe buffer is drained; safe to end or keep sending.
type"flushed"จำเป็นseqintegerจำเป็นAll audio and timing through leg seq have been sent and the buffer is empty. 0 when no leg has run yet.
cancelledA cancel frame was applied. The stopped leg keeps the charge its receipt reported; the discarded buffer was never charged. The session stays open, and the next text frame starts a new leg.
type"cancelled"จำเป็นseqintegerจำเป็นThe leg that stopped. No further audio or timing arrives for it, and any already received is safe to discard. 0 when no leg was in flight and only the buffer was discarded.
errorSomething failed. Recoverable errors leave the connection open; after a fatal one the server closes with the code listed below.
type"error"จำเป็นcodestringจำเป็นStable machine-readable code from the error catalog. Branch on this field; the errors reference documents every code.
seqintegerThe leg the error belongs to, when it belongs to one.
retry_afterintegerSeconds to wait before re-flushing; sent with rate_limited.
doneEvery leg is delivered; the server closes with code 1000 after this event. A connection that closes without done did not finish delivering.
type"done"จำเป็นtotal_charsintegerจำเป็นCharacters synthesized on this connection.
total_creditsnumberจำเป็นCredits charged on this connection, exact to a hundredth.
โค้ดปิดการเชื่อมต่อ#
| โค้ด | คำอธิบาย |
|---|---|
| 1000 | Normal close after done, or client-initiated. |
| 1001 | The server is restarting. Reconnect and resume. |
| 1009 | A frame exceeded 64 KiB. |
| 4400 | A frame violated the session protocol, or the start frame named an unknown model or voice, or a format or sample rate the model does not serve. A frame that fails validation answers an error event, and the connection stays open. |
| 4401 | The API key stopped being valid mid-session. |
| 4402 | Insufficient credits for the next leg. |
| 4403 | The key's spending cap was reached. |
| 4408 | No frame arrived and no audio was delivered for 300 seconds. |
| 4413 | The client read too slowly and the outbound buffer overflowed. |
| 4429 | Too many concurrent live connections for the account. Close an existing connection and reconnect. |
| 4500 | Internal server error. |
| 4503 | The start frame's model is not served right now. Nothing was charged; retry once GET /health reports it served. |