Skip to main content

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

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.
Minimal WebRTC example:
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.

Direct WebRTC API

Use WebRTC when you want browser-native media tracks, Opus audio, and lower-latency playback. The signaling endpoint is:
See 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:
See 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 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:
See REST API for endpoint details.

Authentication

Streaming APIs accept either an API key or a JWT access token as a query parameter:
REST APIs accept either header:
Never expose production API keys in public client code. For browser applications, use the credential flow recommended by your Sanas integration contact.

Next Steps