Translates audio content to a specified language.

Endpoint

POST https://api.sambanova.ai/v1/audio/translations

Request parameters

The following tables outline the parameters required to make an audio translation request, parameter type, description, and default values.

Whisper Large v3

ParameterTypeDescriptionDefault
modelStringThe ID of the model to use.Required
promptMessagePrompt provided to influence transcription style or vocabulary. Example: “Please transcribe carefully, including pauses and hesitations.”Optional
temperatureStringSampling temperature between 0 and 1. Higher values increase randomness; lower values produce more focused output.0
fileFileAudio file in FLAC, MP3, MP4, MPEG, MPGA, M4A, Ogg, WAV, or WebM format. File size limit is 25MB.Required
response formatStringOutput format: JSON or text.json

Qwen2-Audio-7B-Instruct

ParameterTypeDescriptionDefault
modelStringThe ID of the model to use.Required
response_formatStringThe output format is either json or text.json
temperatureNumberSampling temperature between 0 and 1. Higher values (e.g., 0.8) increase randomness, while lower values (e.g., 0.2) make output more focused.0
max_tokensNumberThe maximum number of tokens to generate.1000
fileFileAudio file in FLAC, MP3, MP4, MPEG, MPGA, M4A, Ogg, WAV, or WebM format. Each single file must not exceed 30 seconds in duration.Required
languageStringThe target language for transcription or translation.Optional
streamBooleanEnables streaming responses.false
stream_optionsObjectAdditional streaming configuration (e.g., {“include_usage”: true}).Optional

Request format

This section provides examples of how to send a request using different methods.

CURL

curl --location 'https://api.sambanova.ai/v1/audio/translations' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'model="Qwen2-Audio-7B-Instruct"' \
--form 'language="spanish"' \
--form 'response_format="json"' \
--form 'temperature="0.01"' \
--form 'file=@"/path/to/audio/file.mp3"' \
--form 'stream="true"'

Python

import requests

def translate_audio(audio_file_path, api_key, target_language="spanish"):
      headers = {"Authorization": f"Bearer {api_key}"}

      files = {'file': open(audio_file_path, 'rb')}
      
      data = {
          'model': 'Qwen2-Audio-7B-Instruct',
          'language': target_language,
          'response_format': 'json',
          'temperature': 0.01,
          'stream': True  # Optional
      }
      response = requests.post(
          "https://api.sambanova.ai/v1/audio/translations",
          headers=headers,
          files=files,
          data=data
      )
      return response.json()

Response format

The API returns a translation of the input audio in the selected format.

JSON

{
    "text": "Es un efecto de sonido de una campana sonando, específicamente una campana de iglesia."
}

Text

Es un efecto de sonido de una campana sonando, específicamente una campana de iglesia.