Android SDK
Note:
When integrating multiple SDKs at the same time, "so" file conflicts may occur. Please use decompression software (such as 7-zip) to decompress the aar package and delete conflicting "so" files. Supports Android 5.0 and above versions.
Only activation via internet connection is supported
1 Integration Steps
Note: If you are interested in trying the on-device recognition feature, please get in touch with our business contact in advance to receive an APPID. Also, please specify the language type you want to try. Contact: voice.contact@dolphin-ai.jp.
1.1 Add Model Files
After decompressing the model files, place them in the assets/model/asr/ folder. For example, assets/model/asr/zh-cmn-Hans-CN/.
1.2 Add aar Dependency
Place asr-sdk.aar in the project's libs directory and modify the build.gradle of the app module to add the aar file and okhttp as dependencies.
implementation fileTree(dir: "libs", include: ["*.jar","*.aar"])
implementation 'com.squareup.okhttp3:okhttp:4.10.0'//ここでokhttpを追加します。古いプロジェクトの場合は3.14.2バージョンを使用することができます
implementation 'com.google.code.gson:gson:2.10.1'If you are using a 32-bit SDK, you need to add the following code:
defaultConfig {
//Add the following code
externalNativeBuild {
ndk {
abiFilters "armeabi-v7a"
}
}
}1.3 Add App-Related Permissions
Modify the AndroidManifest.xml file
<!--Recording permission-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!--Network permission-->
<uses-permission android:name="android.permission.INTERNET" />1.4 Invocation Steps/Sample Code
1.4.1 Obtain Recording Permission
registerForActivityResult(new ActivityResultContracts.RequestPermission(), success -> {
tip(success);
}).launch(Manifest.permission.RECORD_AUDIO);1.4.2 Create a Speech Recognition Class
private Transcriber transcriber;
private Recognizer recognizer;
private BaseAsr getAsr() {
if (type == Asr.Type.RECOGNIZER) {
return recognizer;
}
return transcriber;
}
//Initialize the SDK in onCreate
transcriber = Transcriber.getInstance(activity);
recognizer = Recognizer.getInstance(activity);1.4.3 Initialize the Microphone
getAsr().initRecorder();//Initializes the microphone when creating the recognition class 1.4.4 Set Up Callbacks
(1) Callback Parameter Description
| Name | Type | Description | Return Parameters |
|---|---|---|---|
| onStart | Function | Callback method when the engine connection starts | String type of the current task ID |
| onResult | Function | Callback method for engine result content | String type of result data |
| onIntermediateResult | Function | Callback method for engine intermediate results | String type of intermediate result data |
| onWarning | Function | Callback method for engine result warnings | Task ID and Errors type of status code |
| onError | Function | Callback method for engine result errors | Task ID and Errors type of status code |
| onGetAudio | Function | Callback method for engine recognition audio data | byte[] type of audio data |
| onStop | Function | Callback method when the engine ends | None |
(2) Parameter Example
getAsr().setListener(new Asr.Listener() {
@Override
public void onStart(String taskId) {
}
@Override
public void onError(String taskId, Errors.Err err) {
}
@Override
public void onResult(String msg) {
}
@Override
public void onIntermediateResult(String msg) {
}
@Override
public void onWarning(String taskId, Errors.Err err) {
}
@Override
public void onGetAudio(byte[] data) {
}
@Override
public void onStop() {
}
}); 1.4.5 Activate Permissions (Online, Offline)
(1) Configuration Parameters
| Name | Type | Description | Default Value |
|---|---|---|---|
| onSuccess | Function | Callback method for successful initialization | None |
| onFail | Function | Callback method for failed initialization | None |
(2) Parameter Example
@NonNull
private Asr.InitListener getInitListener() {
return new Asr.InitListener() {
@Override
public void onSuccess() {
tip("onSuccess");
}
@Override
public void onFail(Errors.Err err) {
}
};
}Offline & Online Approval
getAsr().initOffline_OnlineAuth(appId, getCurrLang(), getInitListener());1.4.6 Set Parameters
1.4.7 Parameter Settings
Interface Parameter Description
| Parameter | Type | Required | Description | Default Value |
|---|---|---|---|---|
| lang_type | String | Yes | Language option | Required |
| format | String | No | Audio encoding format | pcm |
| sample_rate | Integer | No | Audio sampling rate | 16000 |
| enable_intermediate_result | Boolean | No | Whether to return intermediate recognition results | false |
| enable_punctuation_prediction | Boolean | No | Whether to add punctuation in post-processing | false |
| enable_inverse_text_normalization | Boolean | No | Whether to perform ITN in post-processing | false |
| max_sentence_silence | Integer | No | Speech sentence breaking detection threshold. Silence longer than this threshold is considered as a sentence break. The valid parameter range is 200~1200. Unit: Milliseconds | 450 |
| enable_words | Boolean | No | Whether to enable returning word information | false |
| enable_modal_particle_filter | Boolean | No | Whether to enable modal particle filtering | false |
| hotwords_id | String | No | Hotwords ID | None |
| hotwords_weight | Float | No | Hotwords weight, the range is [0.1, 1.0] | 0.4 |
JsonObject params = new JsonObject();
params.addProperty("lang_type", langType);
params.addProperty("format", "pcm");
params.addProperty("sample_rate", 16000);
params.addProperty("enable_intermediate_result", true);
params.addProperty("enable_punctuation_prediction", true);
params.addProperty("enable_inverse_text_normalization", true);
params.addProperty("max_sentence_silence", 800);
params.addProperty("enable_words", true);1.4.8 Start/Stop Recognition
| Name | Type | Description | Default Value |
|---|---|---|---|
| autoRecording | boolean | Microphone initialized as true | true |
| onlineAsr | boolean | True for Cloud API, false for On-Device | true |
| params | JsonObject | Parameter json | None |
Start Recognition
getAsr().start(autoRecording, onlineAsr, params);Force Sentence Ending
getAsr().sentenceEnd();Customize Speaker Number
getAsr().speakerStart("speaker_name")Stop Recognition
getAsr().stop();Release On-Device Model
@Override
protected void onDestroy() {
super.onDestroy();
getAsr().finish("zh-cmn-Hans-CN");
getAsr().finishAll();
}Cancel the generation of logs
Set the parameters in model/asr/ja-JP/config:
log-level = 6
log-rotate-days=02 Status Code Table
| Error Code | Error Message | Description | Solution |
|---|---|---|---|
| 110100 | Unauthorized | Unauthorized | Change the parameter to an authorized capability or contact the business department to add AI capabilities |
| 110101 | Invalid Activation Code | Activation key is incorrect | Enter the correct activation key |
| 110103 | Authorization Expired | Authorization has expired | Contact business department to extend the authorization period |
| 230400 | Invalid Calling Sequence | The calling sequence is incorrect | Call in the correct sequence |
| 230200 | Recognition Failed | Recognition failed | Please contact the business department |
3 SDK Download & Resource Kit
3.1 SDK Download
The download link for the Android Speech Recognition Mobile SDK package is as follows: Android SDK & Demo
3.2 On-Device Model Download
| Language Category | Language Code | Download Link | Remarks |
|---|---|---|---|
| Japanese - General | ja-JP | Japanese - General | Only Japanese |
| Japanese - Hotel | ja-JP | Japanese - Hotel | Supports mixed speech of Japanese and English |
| English | en-US | English | |
| Chinese | zh-cmn-Hans-CN | Chinese | Supports mixed speech of Chinese and English |