Translate Audio

Translator

The Translator class is the core component of the lara-sdk, designed for translating audio. It must be initialized with authentication credentials.

from lara_sdk import Translator, Credentials

LARA_ACCESS_KEY_ID = "your-access-key-id"
LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

# Initialization of the Translator class
credentials = Credentials(access_key_id=LARA_ACCESS_KEY_ID, access_key_secret=LARA_ACCESS_KEY_SECRET)
lara = Translator(credentials)
import {Credentials, Translator} from "@translated/lara";

const LARA_ACCESS_KEY_ID: string = "your-access-key-id";
const LARA_ACCESS_KEY_SECRET: string = "your-access-key-secret";

// Initialization of the Translator class
const credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
const lara: Translator = new Translator(credentials);
import com.translated.lara.Credentials;
import com.translated.lara.translator.Translator;

private static final String LARA_ACCESS_KEY_ID = "your-access-key-id";
private static final String LARA_ACCESS_KEY_SECRET = "your-access-key-secret";

// Initialization of the Translator class
Credentials credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET);
Translator lara = new Translator(credentials);
use Lara\Translator;
use Lara\LaraCredentials;

define("LARA_ACCESS_KEY_ID", "your-access-key-id");
define("LARA_ACCESS_KEY_SECRET", "your-access-key-secret");

// Initialization of the Translator class
$credentials = new LaraCredentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET);
$lara = new Translator($credentials);
// Sdk available soon
import com.translated.lara.Credentials
import com.translated.lara.translator.Translator

private const val LARA_ACCESS_KEY_ID = "your-access-key-id"
private const val LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

// Initialization of the Translator class
val credentials = Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
val lara = Translator(credentials)
using Lara;
using Lara.Models;

string LARA_ACCESS_KEY_ID = "your-access-key-id";
string LARA_ACCESS_KEY_SECRET = "your-access-key-secret";

// Initialization of the Translator class
var credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET);
var lara = new Translator(credentials);
import Lara

let LARA_ACCESS_KEY_ID = "your-access-key-id"
let LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

// Initialization of the Translator class
let credentials = Credentials(accessKeyId: LARA_ACCESS_KEY_ID, accessKeySecret: LARA_ACCESS_KEY_SECRET)
let lara = Translator(credentials: credentials)

Translate audio file

All audio translation functionalities can be accessed via the same Translator (lara in the example) object of the above example, through the AudioTranslator class.

Audio translation is an asynchronous process consisting of three phases.

  1. Upload the audio file
  2. Wait for Lara to finish the process, polling the status at regular intervals until it changes to translated
  3. Download the file

For your convenience the SDK includes a translate method that takes care of the entire process.

Once uploaded with the upload method, Lara will return a Audio object; the id of this object can be used both to check the status with the status method, both to download the translated file with the download method once its status became translated.

Audio object

FieldTypeDescription
idStringUnique ID of the document. Format: doc_xyz123
statusStringThe current status of the translation.
sourceStringThe source language of the document.
targetStringThe target language of the translation.
voiceGenderStringGender of the voice in the translation, available values: male, female
filenameStringFilename of the source file.
createdAtDateTimeWhen the document is created.
updatedAtDateTimeWhen the document is last updated (equal to created_at with no updates).
optionsAudioOptionsOptions related to the document translation.
translatedSecondsIntegerThe number of translated seconds.
totalSecondsIntegerThe number of seconds in the document.
errorReasonStringThe reason of the error, if any.

Translate method

The SDK contains a translate method that simplifies the process of translating audio file by uploading the file, checking the status at regular intervals, and returning the result of the download function.

Request

sample_audio_file = "sample_audio.mp3"

translated_audio = lara.audio.translate(
				file_path=sample_audio_file,
				filename=os.path.basename(sample_audio_file),
				source="en-US",
				voice_gender = "female",
				target="it-IT",
				adapt_to=["mem_1234..."],
				glossaries=["gls_1234..."]
        )
const options: AudioTranslateOptions = {
  adaptTo: ['mem_1_id', 'mem_2_id'],
  glossaries: ['gls_1_id', 'gls_2_id'],
	voiceGender : 'male',
  style: 'fluid'
};

// Translate an audio file
const translation = await lara.audio.translate(file, 'test.wav', 'en', 'it', options);
File audioFile = new File("voice.mp3");

AudioUploadOptions options = new AudioUploadOptions();
options.setAdaptTo("mem_1234...");
options.setGlossaries("gls_1234...");
options.setVoiceGender = "female";

InputStream translated = lara.audio.translate(audioFile, "en-US", "it-IT", options);
$translateOptions = new AudioTranslateOptions([
  "adaptTo" => ["mem_1_id", "mem_2_id"],
  "glossaries" => ["gls_1_id", "gls_2_id"],
  "voiceGender" => "male",
  "style" => "fluid"
]);

// Translate an audio file
$translation = $lara->audio->translate($file_path, "en", "it", $translateOptions);
// Sdk available soon
val audioFile = File("voice.mp3")
val options = AudioUploadOptions().apply {
    adaptTo = "mem_1234..."
  	glossaries = "gls_1234..."
		voiceGender = "female"

}
val translated: InputStream = lara.audio.translate(audioFile, "en-US", "it-IT", options)
var options = new AudioTranslateOptions {
    AdaptTo = new[] { "mem_1_id", "mem_2_id" },
    Glossaries = new[] { "gls_1_id", "gls_2_id" },
    Style = TranslationStyle.Fluid
};

// Translate an audio file
var translation = await lara.Audio.Translate("path/to/file", "en", "it", options);
let sampleFilePath = "sample_audio.mp3"  // Create this file with your content

let sourceLang = "en-US"
let targetLang = "de-DE"
let gender = "female"

print("Translating audio: \(FileManager.default.displayName(atPath: sampleFilePath)) from \(sourceLang) to \(targetLang)")

        let audioData = try Data(contentsOf: URL(fileURLWithPath: sampleFilePath))
        let translatedData = try await lara.audio.translate(
	          data: audioData,
						voiceGender = gender,
            filename: FileManager.default.displayName(atPath: sampleFilePath),
            source: sourceLang,
            target: targetLang
        )

  // Save translated audio - replace with your desired output path
  let outputPath = "sample_audio_translated.mp3"
  try translatedData.write(to: URL(fileURLWithPath: outputPath))

Here follows the basic fields for the translate method:

Field

Type     

Required     

Default     

Description

file / filePath

File / String

Yes


The input file/the path to input file to translate.

filename

String

Yes*


Only the Typescript/Javascript SDK requires the filename as parameter.

source

String

No

Autodetected

The source language code (e.g., "en-EN" for English). If not specified, the system will attempt to detect it automatically.

target

String

Yes


The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into.

options

AudioTranslateOptions

No


See the table below for details.

Some options are available to customize the behavior of the translate method:

Field

Type

Required

Default

Description

adaptTo

String[]

No

Default is all Memories on your account

A list of translation memory IDs for adapting the translation.

glossaries

String[]

No


A list of glossary IDs.

noTrace

Boolean

No

False

If set to True, source content and its translation will not be saved on our system. (AKA Incognito mode)

style

String

No

faithful

The style to apply to the translation. Available values: faithful fluid creative

The following sections provide a detailed breakdown of the phases and methods utilized by the translate method.

Upload an audio file

The upload method will take care of uploading the source file to Lara and starting the translation process.

Request

sample_audio_file = "sample_audio.mp3"

audio = lara.audio.upload(
            file_path=sample_audio_file,
            filename=os.path.basename(sample_audio_file),
            source="en-US",
            target="it-IT",
            adapt_to=["mem_1234..."]
  					glossaries=["gls_1234..."]
)
const options: AudioUploadOptions = {
  adaptTo: ['mem_1_id', 'mem_2_id'],
  glossaries: ['gls_1_id', 'gls_2_id'],
  style: 'fluid',
};

// Upload an audio file and start the translation process
const audio: Audio = await lara.audio.upload(file, 'test.wav', 'en', 'it', options);
File audioFile = new File("voice.mp3");

AudioUploadOptions options = new AudioUploadOptions();
options.setAdaptTo("mem_1234...");
options.setGlossaries("gls_1234...");

Audio audio = lara.audio.upload(audioFile, "en-US", "it-IT", options);
$translateOptions = new AudioUploadOptions([
  "adaptTo" => ["mem_1_id", "mem_2_id"],
  "glossaries" => ["gls_1_id", "gls_2_id"],
  "style" => "fluid"
]);

// Upload a audio and start the translation process
$audio = $lara->audio->upload($file_path, "en", "it", $translateOptions);
// Sdk available soon
val audioFile = File("voice.mp3")
val options = AudioUploadOptions().apply {
    adaptTo = "mem_1234..."
    glossaries = "gls_1234..."
}
val audio: Audio = lara.audio.upload(audioFile, "en-US", "it-IT", options)
var options = new AudioUploadOptions {
    AdaptTo = new[] { "mem_1_id", "mem_2_id" },
    Glossaries = new[] { "gls_1_id", "gls_2_id" },
    Style = TranslationStyle.Fluid
  };

var audio = await lara.Audio.Upload("path/to/file", "en", "it", options);
 let sampleFilePath = "sample_audio.mp3"  // Create this file with your content

 let sourceLang = "en-US"
 let targetLang = "de-DE"

 let audioData = try Data(contentsOf: URL(fileURLWithPath: sampleFilePath))
 let audio = try await lara.audio.upload(
          data: audioData,
          filename: FileManager.default.displayName(atPath: sampleFilePath),
          source: sourceLang,
          target: targetLang,
          options: AudioUploadOptions(
              adaptTo: ["mem_1A2b3C4d5E6f7G8h9I0jKl"],  // Replace with actual memory IDs
              glossaries: ["gls_1A2b3C4d5E6f7G8h9I0jKl"]  // Replace with actual glossary IDs
            )
 )
// Check status with polling
var updatedAudio = try await lara.audio.status(id: audio.id)
while updatedAudio.status != .translated {
updatedAudio = try await lara.audio.status(id: audio.id)
	if updatedAudio.status == .error {
  	throw NSError(domain: "AudioTranslationError",
    	code: 500,
      userInfo: [NSLocalizedDescriptionKey: updatedAudio.errorReason ?? "Translation failed"])
      }
       try await Task.sleep(nanoseconds: 2_000_000_000) // 2 seconds
    }

        // Download translated audio
        let translatedData = try await lara.audio.download(id: audio.id)

        // Save translated audio - replace with your desired output path
        let outputPath = "step_audio_translated.mp3"
try translatedData.write(to: URL(fileURLWithPath: outputPath))

Here follows the basic fields for the upload method:

Field

Type     

Required     

Default     

Description

file

File

Yes


The input file to translate.

filename

String

Yes*


The Typescript/Javascript and Python SDKs require the filename as a parameter.

source

String

No

Autodetected

The source language code (e.g., "en-EN" for English). If not specified, the system will attempt to detect it automatically.

target

String

Yes


The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into.

options

AudioUploadOptions

No


See the table below for details.

There are some options available to customize the behavior of the upload method:

Field

Type

Required

Default

Description

adaptTo

String[]

No

Default is all Memories on your account

A list of translation memory IDs for adapting the translation.

glossaries

String[]

No


A list of glossary IDs.

noTrace

Boolean

No

False

If set to True, source content and its translation will not be saved on our system.

style

String

No

faithful

The style to apply to the translation. Available values: faithful fluid creative

The result of the upload method is a Audio object that is needed to check the translation status and download the translated audio file.

Response

# audio
audio = Audio(
    status="initialized",
    id="doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename="voice.mp3",
    updatedAt="2025-05-29T18:00:24.779000+00:00",
    createdAt="2025-05-29T18:00:24.779000+00:00",
    source="en",
    target="it"
)
// audio
{
  status: 'initialized',
  id: 'doc_3TJ2ObqnrYTC2k5vSfLlqz',
  filename: 'test.wav',
  updatedAt: 2025-05-15T09:28:14.626Z,
  createdAt: 2025-05-15T09:28:14.626Z,
  source: 'en',
  target: 'it'
}
// audio
Audio(
    status="initialized",
    id="doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename="voice.mp3",
    updatedAt=2025-05-15T09:28:14.626Z,
    createdAt=2025-05-15T09:28:14.626Z,
    source="en",
    target="it"
)
// audio
$audio = [
    "status" => "initialized",
    "id" => "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    "filename" => "test.wav",
    "updated_at" => "2025-05-29T18:00:24.779000+00:00",
    "created_at" => "2025-05-29T18:00:24.779000+00:00",
    "source" => "en",
    "target" => "it"
];
// Sdk available soon
val audio = Audio(
    status = "initialized",
    id = "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename = "voice.mp3",
    updatedAt = ZonedDateTime.parse("2025-05-15T09:28:14.626Z"),
    createdAt = ZonedDateTime.parse("2025-05-15T09:28:14.626Z"),
    source = "en",
    target = "it"
)
// audio
var audio = new Audio(
    id: "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    status: AudioStatus.Initialized,
    filename: "test.wav",
    target: "it",
    createdAt: "2025-05-15T09:28:14.626Z",
    updatedAt: "2025-05-15T09:28:14.626Z",
    source: "en"
);
// document
let document = Document(
    id: "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    status: .initialized,
    source: "en",
    target: "it",
    filename: "test.mp3",
    createdAt: "2025-05-15T09:28:14.626Z",
    updatedAt: "2025-05-15T09:28:14.626Z"
)

Check status

After the upload is finished, it is possible to check the status of the translation at regular intervals. This can be done with the status method:

Request

// Check the status of the audio translation
audio = lara.audio.status(audio.id)
// check the status of the audio file
audio = await lara.audio.status(audio.id);
// Check the status of the audio translation
audio = lara.audio.status(audio.getId());
// check the status of the audio file
$audio = $lara->audio->status($audio->getId());
// Sdk available soon
// Check the status of the audio translation
audio = lara.audio.status(audio.id)
// Check the status of the audio file
var audio = await lara.Audio.Status(audio.Id);
// Check the status of the audio file
$updatedAudio = $lara->audio->status($audio->getId());
echo "Current status: " . $updatedAudio->getStatus() . "\n";

The method takes as unique parameter the id of the Audio object obtained with the upload method.

Field

Type

Required

Default

Description

id

String

Yes


The audio file id obtained with the upload method.

Response

# audio
audio = Audio(
    status="initialized",
    id="doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename="vioce.mp3",
    updatedAt="2025-05-29T18:00:24.779000+00:00",
    createdAt="2025-05-29T18:00:24.779000+00:00",
    source="en",
    target="it"
)
// document
{
  status: 'translated',
  id: 'doc_3TJ2ObqnrYTC2k5vSfLlqz',
  filename: 'test.mp3',
  updatedAt: 2025-05-15T09:28:22.347Z,
  createdAt: 2025-05-15T09:28:14.626Z,
  source: 'en',
  target: 'it'
}
// audio
Audio(
    status="initialized",
    id="doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename="voice.mp3",
    updatedAt=2025-05-15T09:28:14.626Z,
    createdAt=2025-05-15T09:28:14.626Z,
    source="en",
    target="it"
)
// audio
$audio = [
    "status" => "translated",
    "id" => "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    "filename" => "test.mp3",
    "updated_at" => "2025-05-29T18:00:32.519000+00:00",
    "created_at" => "2025-05-15T09:28:14.626",
    "source" => "en",
    "target" => "it"
];
// Sdk available soon
// Sdk available soon
val audio = Audio(
    status = "initialized",
    id = "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    filename = "voice.mp3",
    updatedAt = ZonedDateTime.parse("2025-05-15T09:28:14.626Z"),
    createdAt = ZonedDateTime.parse("2025-05-15T09:28:14.626Z"),
    source = "en",
    target = "it"
)
// audio
var audio = new audio(
    id: "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    status: DocumentStatus.Translated,
    filename: "test.mp3",
    target: "it",
    createdAt: "2025-05-15T09:28:14.626Z",
    updatedAt: "2025-05-15T09:28:22.347Z",
    source: "en"
);
// document
let audio = audio(
    id: "doc_3TJ2ObqnrYTC2k5vSfLlqz",
    status: .initialized,
    source: "en",
    target: "it",
    filename: "test.mp3",
    createdAt: "2025-05-15T09:28:14.626Z",
    updatedAt: "2025-05-15T09:28:14.626Z"
)

Download the translation

After updating the audio file status with the status method and setting it to translated, you can download the translated audio file with the download method.

Request

// Download the translation
translated_audio = lara.audio.download(audio.id)
// Download the translation
const translation = await lara.audio.download(audio.id);
// Download the translation
InputStream downloaded = lara.audio.download(audio.getId())
// Download the translation
$translation = $lara->audio->download($audio->getId());
// Sdk available soon
// Download the translation
val downloaded: InputStream = lara.audio.download(audio.id)
// Download the translation
var translation = await lara.Audio.Download(audio.Id);
// Download the translation
let translation = try await lara.audio.download(id: document.id)

Here follows the basic fields for the download method:

Field

Type     

Required     

Default     

Description

id

String

Yes


The id of the document obtained with the upload method.

Supported Languages

  • Afrikaans - af-ZA
  • Albanian - sq-AL
  • Amharic - am-ET
  • Arabic - ar-SA Armenian - hy-AM
  • Azerbaijani - az-AZ
  • Basque - eu-ES
  • Bengali - bn-BD Bulgarian - bg-BG
  • Burmese - my-MM
  • Catalan - ca-ES
  • Chinese (Simplified) - zh-CN
  • Chinese (Traditional, Hong Kong) - zh-HK
  • Croatian - hr-HR
  • Czech - cs-CZ
  • Danish - da-DK
  • Dutch - nl-NL
  • English (Australia) - en-AU
  • English (Canada) - en-CA
  • English (Ireland) - en-IE
  • English (United Kingdom) - en-GB
  • English (United States) - en-US
  • Estonian - et-EE
  • Filipino - fil-PH
  • Finnish - fi-FI
  • French - fr-FR
  • Galician - gl-ES
  • Georgian - ka-GE
  • German - de-DE
  • Hebrew - he-IL
  • Hindi - hi-IN
  • Hungarian - hu-HU
  • Icelandic - is-IS
  • Indonesian - id-ID
  • Irish - ga-IE
  • Italian - it-IT
  • Japanese - ja-JP
  • Javanese - jv-ID
  • Kazakh - kk-KZ
  • Korean - ko-KR
  • Lao - lo-LA
  • Latvian - lv-LV
  • Lithuanian - lt-LT
  • Macedonian - mk-MK
  • Malay - ms-MY
  • Malayalam - ml-IN
  • Maltese - mt-MT
  • Marathi - mr-IN
  • Mongolian - mn-MN
  • Norwegian Bokmål - nb-NO
  • Pashto - ps-PK Persian - fa-IR
  • Polish - pl-PL
  • Portuguese (Brazil) - pt-BR
  • Portuguese (Portugal) - pt-PT
  • Romanian - ro-RO
  • Russian - ru-RU
  • Serbian (Cyrillic script) - sr-Cyrl-RS Slovak - sk-SK
  • Slovenian - sl-SI
  • Somali - so-SO
  • Spanish - es-ES
  • Spanish (Argentina) - es-AR
  • Spanish (Latin America) - es-419 Spanish (Mexico) - es-MX
  • Swahili - sw-KE
  • Swedish - sv-SE
  • Tagalog - tl-PH Tamil - ta-IN
  • Thai - th-TH
  • Turkish - tr-TR
  • Ukrainian - uk-UA
  • Urdu - ur-PK Uzbek - uzn-UZ
  • Vietnamese - vi-VN
  • Welsh - cy-GB
  • Billing

    More details are available in the pricing page