Flutter
Update:
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.
Version Support
- Flutter 2.10.5 and above.
- Dart 2.14.0 and above.
- Prepare the corresponding development and runtime environment according to your target platform:
Platform
Development and runtime environment
Android
Android 5.0 and above
iOS
iOS 10 and above
Requirements
- Audio format : Only PCM format is supported
- Sampling rate: 16KHz
- Encoding: 16-bit depth
- Channels: Monaural
Configuring build settings
- Setting Linker Flags
- Go to the “Build Settings” tab under your project’s “TARGETS”.
- Add the “-ObjC” flag to the “Other Linker Flags” section.
- Make sure to do this in the “ALL” configurations view.
- Ensure that the “O” and “C” in “-ObjC” are capitalized and the preceding hyphen “-” is included.
- Ensuring Support for Objective-C++
- Your project needs to have at least one source file with a “.mm” extension to support Objective-C++.
- If not present, you can rename an existing “.m” file to “.mm”.
- Adding Libraries
- Add the “libresolv.9.tbd” library to your project.
- This is typically done in the “Link Binary With Libraries” section.
Login
void rtvtLogin(String token, String endpoint, int pid, RtvtDelegate delegate,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter
Type
M/O
Description
token
string
M
token generation using key from LiveData Console service configuration
endpoint
string
M
endpoint (check from LiveData Console service configuration)
pid
int
M
project ID
delgate
-
-
imported callback object
success
-
-
login success callback
fail
-
-
login fail callback
Callback object
mixin RtvtDelegate {
void rtvtRecognizeResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtTranslatedResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtTmpRecognizeResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtReloginResult(int code, String ex);
}
Parameter
Description
result
callback result
startTs
ms timestamp of voice starts
endTs
ms timestamp of voice ends
recTs
ms timestamp of voice recognition
code
the prompt code for the reconnection result, where 0 indicates a successful reconnection.
Start translate
void startTranslate(bool asrResult, bool asrTempResult, bool transResult, String srcLanguage, String destLanguage, List[String] srcAltLanguage, String userId,
void Function(int streamId) success,
void Function(int errorCode, String errorEx) fail)
Parameter
Type
M/O
Description
asrResult
bool
M
Set whether the final result of voice recognition is needed. The default is true.
transResult
bool
M
Set whether the final result of translate is needed. The default is true.
asrTempResult
bool
M
Set whether the temporary result of voice recognition is needed. The default is false.
srcLanguage
string
M
source language
destLanguage
string
M
arget language.
The target language can be passed as an empty string if only transcription is needed.
srcAltLanguage
array
O
The range of alternative languages for the source language supports a maximum of three language types.
userId
string
M
user id, input as needed.
success
-
-
callback when obtain the streamId successful
fail
-
-
callback when obtain the streamId fail
Notice:
1.In scenarios where callback of recognition results is needed, asrResult
should be set to true, srcLanguage
is mandatory, and srcAltLanguage
is optional.
2.In scenarios where callback of translation results is needed, transResult
should be set to true, destLanguage
is mandatory, and it cannot be an empty string.
3.If temporary recognition results and temporary translation results are needed, tempResult
should be set to true.
4.If a language is passed into srcAltLanguage
, the RTVT will default to a language recognition process first. The beginning part of the voice (about 3 seconds) will be used for language recognition, and the subsequent recognition/translation results will be returned normally.
5.If the language passed is not within the range of supported languages, a error message indicating “language not supported” will be displayed; if the language passed is not enabled in the project, a message indicating “project does not support” will be displayed.
6.In the event of a automatic reconnection, this method must be called again to obtain a new streamId.
Send voice clip
void sendPcmData(int streamId, Uint8List pcmData, int seq, int ts,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter
Type
M/O
Description
streamId
int
M
stream ID
seq
int
M
audio segment sequence number (preferably in order)
pcmData
Uint8List
M
audio data,default of 640 bytes
ts
int
M
audio frame reference timestamp
success
-
-
success callback
fail
-
-
fail callback
Notice: If no voice data is sent for a certain period of time, the RTVT will perform a timeout process. At this point, it is necessary to call the startTranslate
method again to obtain a new streamId.
Stop translate
void stopTranslate(int streamId, int lastSeq,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter
Type
M/O
Description
streamId
int
M
stream Id need to translate
lastSeq
int
M
the final audio frame
success
-
-
success callback
fail
-
-
fail callback
Close RTVT
void close()
Error code
Error code
Description
800000
unknown error
800001
unverified link
800002
login failed
800003
expired token
800004
invalid verification time
800005
invalid token
800006
streamId does not exist
More information
For SDK download and more information, please go to Github.
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.
Version Support
- Flutter 2.10.5 and above.
- Dart 2.14.0 and above.
- Prepare the corresponding development and runtime environment according to your target platform:
Platform | Development and runtime environment |
---|---|
Android | Android 5.0 and above |
iOS | iOS 10 and above |
Requirements
- Audio format : Only PCM format is supported
- Sampling rate: 16KHz
- Encoding: 16-bit depth
- Channels: Monaural
Configuring build settings
- Setting Linker Flags
- Go to the “Build Settings” tab under your project’s “TARGETS”.
- Add the “-ObjC” flag to the “Other Linker Flags” section.
- Make sure to do this in the “ALL” configurations view.
- Ensure that the “O” and “C” in “-ObjC” are capitalized and the preceding hyphen “-” is included.
- Ensuring Support for Objective-C++
- Your project needs to have at least one source file with a “.mm” extension to support Objective-C++.
- If not present, you can rename an existing “.m” file to “.mm”.
- Adding Libraries
- Add the “libresolv.9.tbd” library to your project.
- This is typically done in the “Link Binary With Libraries” section.
Login
void rtvtLogin(String token, String endpoint, int pid, RtvtDelegate delegate,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter | Type | M/O | Description |
---|---|---|---|
token | string | M | token generation using key from LiveData Console service configuration |
endpoint | string | M | endpoint (check from LiveData Console service configuration) |
pid | int | M | project ID |
delgate | - | - | imported callback object |
success | - | - | login success callback |
fail | - | - | login fail callback |
Callback object
mixin RtvtDelegate {
void rtvtRecognizeResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtTranslatedResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtTmpRecognizeResult(
int streamId, String result, int startTs, int endTs, int recTs);
void rtvtReloginResult(int code, String ex);
}
Parameter | Description |
---|---|
result | callback result |
startTs | ms timestamp of voice starts |
endTs | ms timestamp of voice ends |
recTs | ms timestamp of voice recognition |
code | the prompt code for the reconnection result, where 0 indicates a successful reconnection. |
Start translate
void startTranslate(bool asrResult, bool asrTempResult, bool transResult, String srcLanguage, String destLanguage, List[String] srcAltLanguage, String userId,
void Function(int streamId) success,
void Function(int errorCode, String errorEx) fail)
Parameter | Type | M/O | Description |
---|---|---|---|
asrResult | bool | M | Set whether the final result of voice recognition is needed. The default is true. |
transResult | bool | M | Set whether the final result of translate is needed. The default is true. |
asrTempResult | bool | M | Set whether the temporary result of voice recognition is needed. The default is false. |
srcLanguage | string | M | source language |
destLanguage | string | M | arget language. The target language can be passed as an empty string if only transcription is needed. |
srcAltLanguage | array | O | The range of alternative languages for the source language supports a maximum of three language types. |
userId | string | M | user id, input as needed. |
success | - | - | callback when obtain the streamId successful |
fail | - | - | callback when obtain the streamId fail |
Notice:
1.In scenarios where callback of recognition results is needed, asrResult
should be set to true, srcLanguage
is mandatory, and srcAltLanguage
is optional.
2.In scenarios where callback of translation results is needed, transResult
should be set to true, destLanguage
is mandatory, and it cannot be an empty string.
3.If temporary recognition results and temporary translation results are needed, tempResult
should be set to true.
4.If a language is passed into srcAltLanguage
, the RTVT will default to a language recognition process first. The beginning part of the voice (about 3 seconds) will be used for language recognition, and the subsequent recognition/translation results will be returned normally.
5.If the language passed is not within the range of supported languages, a error message indicating “language not supported” will be displayed; if the language passed is not enabled in the project, a message indicating “project does not support” will be displayed.
6.In the event of a automatic reconnection, this method must be called again to obtain a new streamId.
Send voice clip
void sendPcmData(int streamId, Uint8List pcmData, int seq, int ts,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter | Type | M/O | Description |
---|---|---|---|
streamId | int | M | stream ID |
seq | int | M | audio segment sequence number (preferably in order) |
pcmData | Uint8List | M | audio data,default of 640 bytes |
ts | int | M | audio frame reference timestamp |
success | - | - | success callback |
fail | - | - | fail callback |
Notice: If no voice data is sent for a certain period of time, the RTVT will perform a timeout process. At this point, it is necessary to call the startTranslate
method again to obtain a new streamId.
Stop translate
void stopTranslate(int streamId, int lastSeq,
void Function() success,
void Function(int errorCode, String errorEx) fail)
Parameter | Type | M/O | Description |
---|---|---|---|
streamId | int | M | stream Id need to translate |
lastSeq | int | M | the final audio frame |
success | - | - | success callback |
fail | - | - | fail callback |
Close RTVT
void close()
Error code
Error code | Description |
---|---|
800000 | unknown error |
800001 | unverified link |
800002 | login failed |
800003 | expired token |
800004 | invalid verification time |
800005 | invalid token |
800006 | streamId does not exist |
More information
For SDK download and more information, please go to Github.