Skip to content

Speech translation

Translate a finished audio file into text in another language with the OpenAI-compatible translations endpoint.

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. 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 English.

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 a language other than English, 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

FieldRequiredTypeNotes
fileYesfileThe audio to translate. Common containers such as MP3, WAV, FLAC, M4A, OGG, AAC, AIFF, and WebM are accepted.
modelYesstringA model that translates, such as symphony.
target_languageNostringISO-639 tag of the language to return, such as de. English when omitted.
source_languagesNostring, repeatableISO-639 tag of a language the audio may be spoken in, such as fr.
response_formatNostringjson, 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.

TagLanguageTagLanguage
arArabicmsMalay
deGermannlDutch
enEnglishptPortuguese
esSpanishruRussian
frFrenchtrTurkish
hiHindiurUrdu
idIndonesianviVietnamese
itItalianyueCantonese
jaJapanesezhChinese
koKorean

If target_language names a language outside this list, the request returns HTTP 400, and the error message lists the accepted tags.

Response fields

FieldTypeNotes
textstringThe translated text.
usageobjectMeasured per-modality usage and cost.

Errors

StatusMeaning
400Sent 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.
401Missing, invalid, or expired credentials.
402No payment method on the account.
403Not a member of the requested organization.
404Unknown model id.
413Request too large.
429Rate limit exceeded. Wait Retry-After seconds.
500Unhandled server error.
503Temporarily unavailable. Retry after Retry-After when it is set.

Full schemas are in the translations reference. For transcripts in the spoken language, see REST.