Web

Overview

This document will guide developer using the real-time voice translation SDK (RTVT) from LiveData, to implement translation services in real-time voice scenarios.

Integration

Service Activation

To integration the LiveData RTVT SDK, you need to register an personal/enterprise account from LiveData official website (https://www.ilivedata.com/) , create a real-time voice translation service project and update the corresponding project parameters in SDK.

Requirements

  • Audio format : Only PCM format is supported
  • Sampling rate: 16KHz
  • Encoding: 16-bit depth
  • Channels: Monaural

Integrate dependencies

Import the following dependency libraries:

<script src="libs/msgpack.min.js"></script>
<script src="libs/md5.min.js"></script>
<script src="libs/int64.min.js"></script>
<script src="libs/crypto-js.min.js"></script>
<script src="libs/fpnn.min.js"></script>
<script src="dist/rtvt.sdk.min.js"></script>

Initialization

let rtvtClient = new RTVTClient({
    endpoint: endpoint,
    pid: pid,
    uid: uid,
});
Parameter Type M/O Description
endpoint string M endpoint (check from LiveData Console service configuration)
pid long M project ID
uid string O user id, input as needed.

Login

login(token, ts, callback);
Parameter Type M/O Description
token string M Refer to the following text for the method of token generation
ts int M token reference timestamp

Start translate

createStream(srcLang, destLang, asrResult, tempResult, transResult, callback);
Parameter Type M/O Description
srcLang string M source language
destLang string M target language
asrResult boolean M Set whether the final result of voice recognition is needed. The default is false.
tempResult boolean M Set whether the temporary result of voice recognition is needed. The default is false.
transResult boolean M Set whether the final result of translate is needed. The default is true.
  • When there are recognition results, if asrResult is set to true, callback will be triggered:
rtvtClient.on("recognizedResult", data);
  • When there are translate results, if transResult is set to true, callback will be triggered:
rtvtClient.on("translatedResult", data);
  • When there are recognized results, if asrResult is set to true, and tempResult is set to true, callback will be triggered:
rtvtClient.on("recognizedTempResult", data);
  • When there are translate results, if transResult is set to true, and tempResult is set to true, callback will be triggered:
rtvtClient.on("translatedTempResult", data);

Send voice clip

rtvtClient.sendVoice(stream, seq, pcm);
Parameter Type M/O Description
stream long M stream ID
seq long M audio segment sequence number (preferably in order)
pcm byte M audio data,default of 640 bytes

Stop Translate

stopAllStreams();

Close RTVT

destory();

Token generate

Please refer to the following code example for the method of token generation:

var pid = pid;
var key = key;
var ts = parseInt(new Date().getTime() / 1000);
var coreString = pid + ":" + ts;
var token = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(coreString, atob(key)));

More information

For SDK download and more information, please go to Github