เชื่อมต่อครั้งเดียว แล้วเปิด context ให้แต่ละสายด้วยเฟรม start ที่ระบุ context_id ซึ่งคุณกำหนดเอง จากนั้นสตรีมเสียงของสายนั้นเป็นเฟรมไบนารี โดยทุกเฟรมขึ้นต้นด้วยเฮดเดอร์ระบุ context แต่ละ context รับเฟรมชุดเดียวกับ WS /v1/stt/live และส่งอีเวนต์ชุดเดียวกัน โดยทุกอีเวนต์ระบุ context ของตัวเอง แต่ละ context จบด้วยอีเวนต์ closed เว้นแต่ WebSocket จะปิดก่อน โดย context อื่นยังทำงานต่อ context ที่เปิดอยู่ถือหนึ่งช่องคำขอพร้อมกันฝั่งถอดเสียงของแพ็กเกจ ตั้งแต่เฟรม start จนถึง closed คู่มือ Multiplexing อธิบายเฮดเดอร์ของเฟรม การรีสตาร์ตของเซิร์ฟเวอร์ และลิมิต
เฮดเดอร์#
authorizationBearer pxa_...จำเป็นAuthorization: Bearer pxa_... (recommended).
x-api-keypxa_...Alternative to the Authorization header. Ignored when Authorization is present.
การเชื่อมต่อ#
wss://api.paxalabs.com/v1/stt/multi Binary frames carry audio in. JSON text frames carry control in, and turn, transcript, and billing events out, each naming its context. Where a message below says connection, read context.
ข้อความฝั่งไคลเอนต์#
startConfigures the session. Must be the first frame; exactly one per connection.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"start"จำเป็นmodelstringจำเป็นRealtime transcription model id, for example paxa-stt-lite-realtime-v1-preview. GET /v1/models lists the served catalog; a recording model answers unknown_model here.
audioobjectจำเป็นWhat the binary frames carry, fixed for the connection. The bytes are read exactly as declared. A wrong declaration transcribes noise.
ดูฟิลด์ย่อยซ่อนฟิลด์ย่อย
audio.encoding"pcm_s16le" or "mulaw"จำเป็น"pcm_s16le" is signed 16-bit little-endian PCM, "mulaw" is G.711 mu-law as telephony delivers it. Mono.
audio.sample_rate16000 or 48000 or 8000จำเป็นSamples per second of the binary frames: 16000 or 48000 for pcm_s16le, 8000 for mulaw. Any other pairing answers validation.
languagestringThe language the speech is expected to be in, as a BCP 47 tag such as "th", "en", or "zh". The hint filters nothing. Speech in any other language is still transcribed as spoken, and Thai that switches into English mid-sentence needs no setting. Omitted, the model detects the language itself. Set the tag when detection has picked the wrong language.
timestamps"word"Adds a words array to every final transcript, one span per word with its start and end in seconds on the connection's clock. Thai words are segmented for you. Costs nothing extra.
style"verbatim" or "clean"How faithfully the transcript follows the speech. "verbatim", the default, writes exactly what was said: fillers, false starts, and self-corrections included. "clean" drops fillers and merges broken phrases into one, for a transcript that is easier to read. It is a readability choice. A clean transcript departs further from what was said, and our own measurement found it less exact. Any other value answers 400 validation.
convention"spoken" or "written"How the transcript writes what was said. "spoken", the default, writes numbers as they were said (สามสิบเปอร์เซ็นต์) and a word said twice as two words, which is what a verbatim transcript, a subtitle, or a language model reading the text needs. "written" keeps display conventions: digits and units (30%), the repetition mark ๆ, for dictated text that will be read on a page. The word timestamps are the same under both. Only Thai is respelled: a transcript in another language, English and Mandarin among them, reads the same under both.
vocabularyarray of stringsTerms the speech is likely to contain that the model should recognize as written: product names, people, places, jargon, in Thai or any other language. Up to 50 terms of 50 characters each, and a longer list or term answers 400 validation. The terms bias recognition and are never inserted; a term that was not said does not appear. Costs nothing extra and combines with every other option.
playbackTells the turn detector when your agent is speaking. Its own voice reaching the microphone then cannot open a turn. While speaking is true, opening a turn takes more sustained speech from the user; a real interruption still opens one and arrives as speech_started. Send it on every change. A session that never sends it treats the room as quiet.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"playback"จำเป็นspeakingbooleanจำเป็นtrue while your agent's audio is playing into the same room as the microphone, false once it stops.
endCloses the turn in progress, if any, and delivers its transcript, then the server sends done and closes with code 1000. Audio after end is ignored.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"end"จำเป็นอีเวนต์ฝั่งเซิร์ฟเวอร์#
เฟรมเสียง: Each frame opens with one byte counting the context id, 1 to 64, then the id in ASCII. The rest is audio in the encoding and sample rate that context's start frame declared, in any chunking and at any cadence, up to 64 KiB a frame with its header. Audio may follow the start frame at once. Audio that names a context which is not open is dropped.
startedThe session is configured and listening.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"started"จำเป็นconnectionstringจำเป็นConnection id; quote it in support requests (the x-request-id analog).
modelstringจำเป็นThe model serving this session.
speech_startedThe user started speaking. This is the interruption signal. Stop your agent's audio and cancel the reply it was generating. It arrives once enough speech has been heard to be sure. The time it reports is therefore earlier than the moment it arrives.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"speech_started"จำเป็นturnintegerจำเป็นThe turn this event belongs to, counting from 1 per connection. A higher number is a later turn: an agent that already replied to turn 3 discards turn 3 and answers turn 4.
timenumberจำเป็นWhere the user started speaking. In seconds of audio received since the connection's first binary frame, exact to a thousandth.
transcriptA transcript of one turn. The final transcript is the turn: send its text to your language model. An interim gives an earlier look at the same turn and never needs handling on its own.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"transcript"จำเป็นturnintegerจำเป็นThe turn this event belongs to, counting from 1 per connection. A higher number is a later turn: an agent that already replied to turn 3 discards turn 3 and answers turn 4.
is_finalbooleanจำเป็นtrue for the turn's finished transcript, sent exactly once per turn. false for an interim transcript of the turn so far, sent at a natural pause and replaced by the final.
textstringจำเป็นThe verbatim transcript of the turn, or of the turn so far. Empty on a final when the turn held no speech the model could read.
startnumberจำเป็นWhere the transcribed audio starts. In seconds of audio received since the connection's first binary frame, exact to a thousandth.
endnumberจำเป็นWhere the transcribed audio ends. In seconds of audio received since the connection's first binary frame, exact to a thousandth.
wordsarray of objectsWord spans on the connection's clock, present on a final when the session set timestamps.
ดูฟิลด์ย่อยซ่อนฟิลด์ย่อย
words[].textstringจำเป็นThe spoken input text this span covers. An emotion tag takes no span.
words[].startnumberจำเป็นWhere the span begins in the audio, in seconds.
words[].endnumberจำเป็นWhere the span ends in the audio, in seconds.
speech_endedThe user stopped speaking and the turn is closed. Its final transcript follows. Use it to show that the agent is thinking.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"speech_ended"จำเป็นturnintegerจำเป็นThe turn this event belongs to, counting from 1 per connection. A higher number is a later turn: an agent that already replied to turn 3 discards turn 3 and answers turn 4.
timenumberจำเป็นWhere the turn ended. In seconds of audio received since the connection's first binary frame, exact to a thousandth.
chargedBilling receipt. The connection is charged for the audio it receives, silence included. A period closes at the end of each turn, after a minute of audio with no turn, and at the end of the session. Receipts replace the x-credits-charged header.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"charged"จำเป็นseqintegerจำเป็นThe billing period this receipt covers, starting at 1.
secondsnumberจำเป็นAudio received in this period, in seconds, exact to a thousandth.
creditsnumberจำเป็นCredits charged for this period, exact to a hundredth. The 0.1-credit request floor applies once per connection, on the first receipt.
total_creditsnumberจำเป็นCredits charged on this connection so far, the audio of failed turns excluded, exact to a hundredth.
errorSomething failed. A recoverable error leaves the context open. After a fatal one the context sends closed with the code listed below, and the socket itself closes on 4401 and 4403.
context_idstringThe context the error belongs to. Absent when the frame named no context. That is a frame that was not a JSON object, one whose context_id was missing or malformed, or a binary frame the socket does not take or whose header was malformed. Nothing closes on such an error.
type"error"จำเป็นcodestringจำเป็นStable machine-readable code from the error catalog. Branch on this field; the errors reference documents every code.
turnintegerThe turn the error belongs to, when it belongs to one. That turn delivers no transcript; the session keeps listening.
not_billednumberCredits this turn's audio is held back from the bill, exact to a hundredth. It comes off what the periods after this turn owe. A turn that fails with little audio behind it returns less than this. Sent with a turn.
retry_afterintegerSeconds to wait before sending start again. Sent with rate_limited.
doneEvery turn is delivered; the server closes with code 1000 after this event. A connection that closes without done did not finish delivering.
context_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
type"done"จำเป็นtotal_secondsnumberจำเป็นAudio received on this connection, in seconds, exact to a thousandth.
turnsintegerจำเป็นTurns the connection delivered or failed.
total_creditsnumberจำเป็นCredits charged on this connection, the audio of failed turns excluded, exact to a hundredth. Zero when no turn was delivered, which returns the connection's charge in full.
closedThe context is closed, and no audio follows. A context ends with one closed event unless the socket closes first. The id is free for a new start once it arrives.
type"closed"จำเป็นcontext_idstringจำเป็นThe context this message belongs to. You choose it: 1 to 64 characters of letters, digits, and . _ : -, such as your own call id.
codeintegerจำเป็นThe context's close code, one of those listed below.
reasonstringจำเป็นThe same in words, for logs.
drainingThe server is restarting. Open another socket now and start every new context there. Contexts already open keep running. Move each call at its next turn boundary. A start sent here from now on answers provider_unavailable and closed. The socket closes with 1001 once its last context has closed.
type"draining"จำเป็นgraceintegerจำเป็นSeconds until the server closes the contexts still open on this socket.
โค้ดปิดการเชื่อมต่อ#
| โค้ด | คำอธิบาย |
|---|---|
| 1000 | A context reports it after done. The socket closes with it only when you close it. |
| 1001 | The server is restarting. A context reports it when it was still open after the grace the draining event named. The socket closes with it once its last context has closed. It can also close the socket while contexts are open, and those end with no closed event. Open another socket and start again there. |
| 1009 | The socket closes: a frame exceeded 64 KiB. |
| 4400 | A context reports it: a frame violated the session protocol, or the start frame failed validation. It also reports it when the start frame named an unknown model or a sample rate its encoding does not take. Any other frame that fails validation answers an error event, and the context stays open. |
| 4401 | The API key stopped being valid. Every open context reports it, then the socket closes with it. |
| 4402 | A context reports it: the account cannot cover the request floor at start, or the next billing period. |
| 4403 | The key's spending cap was reached. Every open context reports it, then the socket closes with it. |
| 4408 | A context reports it when no frame arrived for it and no event was sent for 300 seconds. The socket closes with it after 300 seconds with no open context and no frame. |
| 4413 | A context reports it when its frames arrived faster than they could be handled, and a speech context also when its client read a leg too slowly for the leg's time budget, which keeps that leg's charge. The socket closes with it when the client read too slowly and the outbound buffer overflowed. |
| 4429 | A context reports it: the account holds the plan's full count of concurrent transcription sessions, or the start passed the plan's requests per minute. End another context or connection, or wait the error's retry_after seconds, then start again. |
| 4500 | A context reports it: internal server error. |
| 4502 | A context reports it: transcription failed for the whole context. What its delivered periods charged stays charged; a context that delivered no turn is refunded in full. Start it again. |
| 4503 | A context reports it: transcription was unavailable at start. Nothing was charged; retry. |