This feature is on Beta state.

We’re looking for feedbacks to improve this feature, share yours here.

The Translation model generates translations of your transcriptions to one or more targeted languages. If subtitles and/or sentences are enabled, the translations will also include translated results for them. You can translate your transcription to multiples languages in a single API call.

The list of the languages covered by the Translation feature are listed in the API Reference (see translation_config).

2 translation models are available:

  • base : Fast, cover most use cases
  • enhanced : Slower, but higher quality and with context awareness

In the following examples, we’re using base model.

async function makeFetchRequest(url: string, options: any) {
  const response = await fetch(url, options);
  return response.json();
}

async function pollForResult(resultUrl: string, headers: any) {
  while (true) {
    console.log("Polling for results...");
    const pollResponse = await makeFetchRequest(resultUrl, { headers });

    if (pollResponse.status === "done") {
      console.log("- Transcription done: \n");
      const translation = pollResponse.result.translation;
      console.log(translation);
      break;
    } else {
      console.log("Transcription status : ", pollResponse.status);
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  }
}

async function startTranscription() {
  const gladiaKey = "YOUR_GLADIA_API_TOKEN";
  const requestData = {
    audio_url:
      "YOUR_AUDIO_URL",
    translation: true,
    translation_config: {
      target_languages: [ "fr", "es"],
      model: "base" // "enhanced" is slower but of better quality
    }
  };
  const gladiaUrl = "https://api.gladia.io/v2/transcription/";
  const headers = {
    "x-gladia-key": gladiaKey,
    "Content-Type": "application/json",
  };

  console.log("- Sending initial request to Gladia API...");
  const initialResponse = await makeFetchRequest(gladiaUrl, {
    method: "POST",
    headers,
    body: JSON.stringify(requestData),
  });

  console.log("Initial response with Transcription ID :", initialResponse);

  if (initialResponse.result_url) {
    await pollForResult(initialResponse.result_url, headers);
  }
}

startTranscription();

With this code, your output will look like this:

{
  success: true,
  is_empty: false,
  results: [
    {
      words: [
        {
          word: "Diviser",
          start: 0.20043,
          end: 0.7008000000000001,
          confidence: 1
        },
        {
          word: "l'infini",
          start: 0.9009500000000001,
          end: 1.5614400000000002,
          confidence: 1
        },
        ...
      ],
      languages: [Array],
      full_transcript: "Diviser l'infini dans un temps où moins est plus...",
      utterances: [Array], // Also translated
      error: null
    },
    {
      words: [
        {
          word: "Dividir",
          start: 0.20043,
          end: 0.7008000000000001,
          confidence: 1
        },
        {
          word: "la infinidad",
          start: 0.9009500000000001,
          end: 1.5614400000000002,
          confidence: 1
        },
        ...
      ],
      languages: [Array],
      full_transcript: "Dividir la infinidad en un tiempo en que menos es más, donde demasiado nunca es suficiente...",
      utterances: [Array], // Also translated
      error: null
    }
  ],
  exec_time: 0.6475496292114258,
  error: null
}

If you enabled the subtitles generation, those will also benefits from the translation model.