Speech translation
Translate a finished audio file, or a live stream over a WebSocket, into text in another language.
POST /v1/audio/translations takes a finished audio file and returns its
content as text in another language. It follows the OpenAI translations shape.
target_language sets the language of the returned text. A WebSocket at the
same path translates a live stream turn by turn.
Models lists the models that translate. The examples use
symphony and abbreviate usage.
Translate a file
Upload the audio as multipart/form-data. Without target_language, the text
comes back in en.
curl https://api.sprag.ai/v1/audio/translations \
-H "Authorization: Bearer $SPRAG_API_KEY" \
-F [email protected] \
-F model=symphony{
"text": "Hello, I would like to reserve a table for four people on Friday evening at around eight o'clock.",
"usage": { "input": { "audio": { "duration": "6.08" } } }
}Choose the output language
To get text in another language, send its tag as target_language. To send it from the OpenAI Python client, pass it in
extra_body.
curl https://api.sprag.ai/v1/audio/translations \
-H "Authorization: Bearer $SPRAG_API_KEY" \
-F [email protected] \
-F model=symphony \
-F target_language=de{
"text": "Guten Tag, ich hätte gerne einen Tisch für vier Personen am Freitagabend gegen zwanzig Uhr.",
"usage": { "input": { "audio": { "duration": "6.08" } } }
}Name the spoken language
If you know the spoken language, send its tag as source_languages.
curl https://api.sprag.ai/v1/audio/translations \
-H "Authorization: Bearer $SPRAG_API_KEY" \
-F [email protected] \
-F model=symphony \
-F source_languages=fr \
-F target_language=es{
"text": "Hola, me gustaría reservar una mesa para cuatro personas el viernes por la noche, alrededor de las ocho.",
"usage": { "input": { "audio": { "duration": "6.08" } } }
}If the request carries one tag, the audio is translated from that language. If
it carries several, the spoken language is detected from among them. Send the
field once per tag. Without source_languages, the spoken language is detected
from the audio.
Request fields
| Field | Required | Type | Notes |
|---|---|---|---|
file | Yes | file | The audio to translate. Common containers such as MP3, WAV, FLAC, M4A, OGG, AAC, AIFF, and WebM are accepted. |
model | Yes | string | A model that translates, such as symphony. |
target_language | No | string | ISO-639 tag of the language to return, such as de. en when omitted. |
source_languages | No | string, repeatable | ISO-639 tag of a language the audio may be spoken in, such as fr. |
response_format | No | string | json, the only accepted value. |
Target languages
target_language accepts the tags below. Two- and three-letter ISO-639 tags
are both accepted, so fr and fra name the same language.
| Tag | Language | Tag | Language |
|---|---|---|---|
ar | Arabic | ms | Malay |
de | German | nl | Dutch |
en | English | pt | Portuguese |
es | Spanish | ru | Russian |
fr | French | tr | Turkish |
hi | Hindi | ur | Urdu |
id | Indonesian | vi | Vietnamese |
it | Italian | yue | Cantonese |
ja | Japanese | zh | Chinese |
ko | Korean |
If target_language names a language outside this list, the request returns
HTTP 400, and the error message lists the accepted tags.
Response fields
| Field | Type | Notes |
|---|---|---|
text | string | The translated text. |
usage | object | Measured per-modality usage and cost. |
Translate a live stream
A translation session takes a live audio stream over a WebSocket and returns
each turn's text in target_language. It follows the
realtime transcription protocol: authentication,
audio format, turn detection, events, and limits are the same, and each turn's
text arrives once the turn closes.
Connect to the translations route:
wss://api.sprag.ai/v1/audio/translationsWithin ten seconds of connecting, send a session.update that names the model
under session.audio.input.transcription.model. Set target_language in the
same block:
{
"type": "session.update",
"session": {
"audio": {
"input": {
"format": { "type": "audio/pcm", "rate": 16000 },
"transcription": { "model": "symphony", "target_language": "de" }
}
}
}
}Each turn's text arrives in conversation.item.input_audio_transcription.delta
and conversation.item.input_audio_transcription.completed events, keyed by
item_id:
{
"type": "conversation.item.input_audio_transcription.completed",
"item_id": "item_cd99c2b70002",
"content_index": 0,
"transcript": "Guten Tag, ich hätte gerne einen Tisch für vier Personen am Freitagabend gegen zwanzig Uhr.",
"usage": { "type": "duration", "seconds": 6.08 }
}| Field | Required | Type | Notes |
|---|---|---|---|
model | Yes | string | A model that translates, such as symphony. |
target_language | No | string | ISO-639 tag of the language to return, from Target languages. en when omitted. |
A later session.update can change target_language.
If target_language names a language outside
Target languages, the server sends an error event with
the code unsupported_language. If target_language is not an ISO-639 tag, the
error event carries the code invalid_session_update. In both cases none of
the fields in that session.update take effect, so send the update again with
an accepted tag. If the declared model does not translate, the server closes the
socket with close code 1008.
Errors
| Status | Meaning |
|---|---|
400 | Sent when target_language is not an accepted tag. Also sent when response_format is not json. Also sent with the code model_not_supported when the model does not translate. Also sent with the code unsupported_media when the audio cannot be decoded. |
401 | Missing, invalid, or expired credentials. |
402 | Out of credit. Also sent with the code payment_overdue when a plan invoice is unpaid. Also sent while billing for a new account is being set up; retry the request after a moment. |
403 | Not a member of the requested organization. |
404 | Unknown model id. |
413 | Request too large. |
429 | Rate limit exceeded. Wait Retry-After seconds. |
500 | Unhandled server error. |
503 | Temporarily unavailable. Retry after Retry-After when it is set. |
Full schemas are in the translations reference. For transcripts in the spoken language, see REST. For connection, turn detection, limits, and close codes, see realtime transcription.