Connect With WebRTC
WebRTC is a powerful set of standard interfaces for building real-time applications. The Sanas Language Translation API supports connecting through a WebRTC peer connection. Follow this guide to learn how to configure a WebRTC connection to the Sanas Language Translation API.
Overview (All Cases)
In scenarios where you would like to connect to a Realtime model from an insecure client over the network, we recommend using the WebRTC connection method. WebRTC is better equipped to handle variable connection states, and provides a number of convenient APIs for capturing user audio inputs and streaming it in a reliable manner.
However, we are currently working on supporting connecting through SIP as well to be more easily integrated with telephony systems.
The process for initializing a WebRTC connection is as follows (assuming a web browser client):
The client generates an SDP offer
The client sends an authenticated HTTP POST request to the
/session
endpoint to receive an SDP answer for establish a WebRTC connectionThe client establishes the WebRTC connection using this received answer and creates both an audio channel and a data
All messages to the Sanas Language Translation API can now be sent through the data channel. Live transcripts and translations can be received from that data channel. Audio data of the original speech can be sent through the audio channel from the client to the server. And likewise the translated speech audio will be received through the audio channel from the server to the client.
Overview (Bidirectional Translation)
In cases where you have two users A and B communicating in language A and B with each other, you likely will want to create two translation sessions. One session will be in charge of translating the audio from A in language A to audio in language B, and one session will be in charge of translating the audio from B in language B to audio in language A.
To ensure that context is shared accross these two sessions, you will want to generate a shared conversation_id
for both of these sessions. This ID can be an arbitrary string that you are in charge of generating. More information for how to pass this conversation ID to the language translation session will be explained in Use Language Translation Session.

Connection Details
Connecting via WebRTC requires the following connection information:
URL
https://d1i2jhhbmh30pt.cloudfront.net/session
Method
POST
Body
type
Must be set to offer
sdp
The sdp string generated on the client's end
input_sample_rate
(optional)
Must be 8000, 16000, 22050, 24000, 44100, or 48000 Hz. Defaults to 24000
output_sample_rate
(optional)
Must be 8000, 16000, 22050, 24000, 44100, or 48000 Hz. Defaults to 24000
Headers
Content-Type
Must be application/json
X-API-Key
Your Sanas API key
See Default for more details about this endpoint.
Last updated