Use Language Translation Session
After establishing a WebRTC connection in Connect With WebRTC, you can initialize a conversation for simultaneous language translation with Sanas.
First, start by sending a reset
message on the WebRTC data channel:
{
type: 'reset'
reset: {
id: string // This should be an arbitrary UUID generated by you
lang_in: string // The original language code in ISO 639-1 format
lang_out: string // The translation language code in ISO 639-1 format
glossary?: string[] | null // An optional list of brand names to preserve
conversation_id?: string // Optionally for a two way call, the conversation ID
}
}
Then, wait to receive a ready
message back from the server on the WebRTC data channel with a matching id. The message should look like so:
{
type: 'ready'
ready: {
id: string // The id that you specified in the reset message
}
}
You are now ready to start feeding audio through the WebRTC audio channel! You will then start receiving audio back.
Additionally, you will receive the following messages on the data channel for transcripts and translations:
{
type: 'transcription'
transcription: {
type: 'partial' | 'complete'
transcriptions: Word[]
}
}
{
type: 'translation'
transcription: {
type: 'partial' | 'complete'
transcriptions: Word[]
}
}
With the word object like so:
{
word: string // The text content of the word
start: number // When the word start speaking, in seconds since the start of the session
end: number // When the word finished speaking, in seconds since the start of the session
}
To end a session, simply stop the WebRTC connection.
Last updated