> ## Documentation Index
> Fetch the complete documentation index at: https://developer.sanas.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Language Translation

> Add real-time speech-to-speech translation to your application with WebRTC, WebSocket, and REST APIs

### How Language Translation Works

Sanas Language Translation turns speech in one language into natural-sounding speech in another, in real time. You send audio in, and you get translated audio back — along with the text of what was said and what it was translated to.

Access is enabled through the **Sanas Developer Console**. Once Language Translation is turned on for your account there, you'll generate an API key and pick the languages you want to translate between. No separate installation or infrastructure is required on your side.

Under the hood, each session follows a simple round trip:

1. **Your app captures audio** — from a microphone or an audio file — and opens a connection to the Sanas cloud using WebRTC or WebSocket (or the Sanas JavaScript client, which handles the connection for you).
2. **You choose a language route**, such as English → Spanish, and the session starts once the service confirms it's ready.
3. **Sanas processes the speech in the cloud**: it transcribes what was said (speech-to-text), translates the text into the target language, and generates spoken audio in a natural voice (text-to-speech).
4. **Translated audio streams back to your app**, ready to play, along with live transcription and translation text you can display on screen.

The whole loop happens continuously and with low latency, so conversations feel natural rather than stop-and-start. Because everything runs as a managed cloud service, you get updates, new languages, and scaling automatically — you only manage your API key and language settings in the Developer Console.

The API supports browser-friendly WebRTC sessions, raw WebSocket streaming, and REST endpoints for setup tasks such as language discovery and account/device operations.

For a working browser integration, see the [Language Translation Demo](https://github.com/Scott-Hickmann-Sanas/Language-Translation-Demo). It shows how to connect with the Sanas JavaScript client, select source and target languages, stream microphone or file audio, play translated audio, and record translated output.

## Supported Languages:

| Current Supported Languages | Code   |
| --------------------------- | ------ |
| Arabic                      | ar-SA  |
| Czech                       | cs-CZ  |
| Danish (Beta)               | da-DK  |
| Dutch                       | nl-NL  |
| English (US)                | en-US  |
| English (UK)                | en-GB  |
| Finnish (Beta)              | fi-FI  |
| French                      | fr-FR  |
| French (Canadian)           | fr-CA  |
| German                      | de-DE  |
| Greek                       | el-GR  |
| Hindi                       | hi-IN  |
| Hungarian                   | hu-HU  |
| Indonesian                  | id-ID  |
| Italian                     | it-IT  |
| Japanese (Beta)             | ja-JP  |
| Korean                      | ko-KR  |
| Malay                       | ms-MY  |
| Mandarin                    | zh-CN  |
| Polish                      | pl-PL  |
| Portuguese (Brazilian)      | pt-BR  |
| Portuguese (Portugal)       | pt-PT  |
| Romanian                    | ro-RO  |
| Russian                     | ru-RU  |
| Spanish (Spain)             | es-ES  |
| Spanish (Latin America)     | es-419 |
| Swedish                     | sv-SE  |
| Tagalog (Beta)              | tl-PH  |
| Thai                        | th-TH  |
| Turkish                     | tr-TR  |

## Before You Start

You need:

* A Sanas API key or access token.
* The Sanas API base URL: `https://api.sanaslt.com`.
* A source language and target language route, such as `en-US` to `es-ES`.
* A browser or client environment that can capture and play audio.

## Choose an Integration Path

### JavaScript Client

Use the JavaScript client for web applications and prototypes. It wraps the WebRTC and WebSocket transports, manages the connection lifecycle, and exposes callbacks for transcript, translation, and audio events.

```bash theme={null}
npm install @sanas-ai/language-translation
```

Minimal WebRTC example:

```ts theme={null}
import {
  SanasTranslationClient,
  TranslationState,
  WebRTCTransport,
  getMicrophoneTrack,
} from "@sanas-ai/language-translation";

const state = new TranslationState({
  onUtterance: (utterance) => {
    console.log("Transcription:", utterance.transcription.spokenText);
    console.log("Translation:", utterance.translation.spokenText);
  },
});

const client = new SanasTranslationClient(state, {
  apiKey: "your-api-key",
  endpoint: "https://api.sanaslt.com",
});

const audioTrack = await getMicrophoneTrack();
const transport = new WebRTCTransport();
const { audio } = await client.connect({ transport, audioTrack });

const audioElement = document.createElement("audio");
audioElement.srcObject = audio;
audioElement.autoplay = true;

await client.reset({
  languageRoutes: [{ langIn: "en-US", langOut: "es-ES" }],
  features: ["consecutive"],
});
```

The demo repository provides a fuller version of this flow with UI controls and examples at [https://github.com/Scott-Hickmann-Sanas/Language-Translation-Demo](https://github.com/Scott-Hickmann-Sanas/Language-Translation-Demo).

### Direct WebRTC API

Use WebRTC when you want browser-native media tracks, Opus audio, and lower-latency playback. The signaling endpoint is:

```text theme={null}
wss://api.sanaslt.com/v3/webrtc?api_key=<api_key>
```

See [WebRTC API](/Docs/Language-Translation/WebRTC-API) for signaling, ICE, data channel, and media track details.

### Direct WebSocket API

Use the WebSocket API when you want a single persistent connection and can send raw PCM audio frames yourself. The stream endpoint is:

```text theme={null}
wss://api.sanaslt.com/v3/stream?api_key=<api_key>
```

See [WebSocket API](/Docs/Language-Translation/WebSocket-API) for connection details and audio frame requirements.

## Stream Session Basics

Both WebRTC and WebSocket use the same Stream message layer:

1. Open an authenticated transport connection.
2. Send an `init` message with session settings.
3. Send a `configure` message with language routes and features.
4. Wait for the server to return `configured`.
5. Stream input audio.
6. Listen for transcription, translation, lifecycle, and output audio events.
7. Send `flush` when you want to finalize a turn manually.

See [Stream Message Layer](/Docs/Language-Translation/Stream-Message-Layer) for the full schema, examples, events, and error shapes.

## REST API

Use REST endpoints for non-streaming operations, including health checks, error codes, language listing, device registration, and Twilio integration. REST endpoints use the base URL:

```text theme={null}
https://api.sanaslt.com/v2
```

See [REST API](/Docs/Language-Translation/REST-API) for endpoint details.

## Authentication

Streaming APIs accept either an API key or a JWT access token as a query parameter:

```text theme={null}
wss://api.sanaslt.com/v3/stream?api_key=<api_key>
wss://api.sanaslt.com/v3/stream?token=<jwt_token>
```

REST APIs accept either header:

```text theme={null}
x-api-key: <api_key>
Authorization: Bearer <jwt_token>
```

Never expose production API keys in public client code. For browser applications, use the credential flow recommended by your Sanas integration contact.

## Next Steps

* Start from the [Language Translation Demo](https://github.com/Scott-Hickmann-Sanas/Language-Translation-Demo) if you are building a browser app.
* Read [Stream Message Layer](/Docs/Language-Translation/Stream-Message-Layer) before implementing direct WebRTC or WebSocket clients.
* Use [WebRTC API](/Docs/Language-Translation/WebRTC-API) for browser media-track integrations.
* Use [WebSocket API](/Docs/Language-Translation/WebSocket-API) for custom PCM streaming integrations.
* Use [REST API](/Docs/Language-Translation/REST-API) for setup, metadata, and account operations.
