Logo

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" 
        }
    }
}

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

NameTypeDescriptionReturn Parameters
onStartFunctionCallback method when the engine connection startsString type of the current task ID
onResultFunctionCallback method for engine result contentString type of result data
onIntermediateResultFunctionCallback method for engine intermediate resultsString type of intermediate result data
onWarningFunctionCallback method for engine result warningsTask ID and Errors type of status code
onErrorFunctionCallback method for engine result errorsTask ID and Errors type of status code
onGetAudioFunctionCallback method for engine recognition audio databyte[] type of audio data
onStopFunctionCallback method when the engine endsNone

(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

NameTypeDescriptionDefault Value
onSuccessFunctionCallback method for successful initializationNone
onFailFunctionCallback method for failed initializationNone

(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

ParameterTypeRequiredDescriptionDefault Value
lang_typeStringYesLanguage optionRequired
formatStringNoAudio encoding formatpcm
sample_rateIntegerNoAudio sampling rate16000
enable_intermediate_resultBooleanNoWhether to return intermediate recognition resultsfalse
enable_punctuation_predictionBooleanNoWhether to add punctuation in post-processingfalse
enable_inverse_text_normalizationBooleanNoWhether to perform ITN in post-processingfalse
max_sentence_silenceIntegerNoSpeech 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_wordsBooleanNoWhether to enable returning word informationfalse
enable_modal_particle_filterBooleanNoWhether to enable modal particle filteringfalse
hotwords_idStringNoHotwords IDNone
hotwords_weightFloatNoHotwords 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

NameTypeDescriptionDefault Value
autoRecordingbooleanMicrophone initialized as truetrue
onlineAsrbooleanTrue for Cloud API, false for On-Devicetrue
paramsJsonObjectParameter jsonNone

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=0

2 Status Code Table

Error CodeError MessageDescriptionSolution
110100UnauthorizedUnauthorizedChange the parameter to an authorized capability or contact the business department to add AI capabilities
110101Invalid Activation CodeActivation key is incorrectEnter the correct activation key
110103Authorization ExpiredAuthorization has expiredContact business department to extend the authorization period
230400Invalid Calling SequenceThe calling sequence is incorrectCall in the correct sequence
230200Recognition FailedRecognition failedPlease 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 CategoryLanguage CodeDownload LinkRemarks
Japanese - Generalja-JPJapanese - GeneralOnly Japanese
Japanese - Hotelja-JPJapanese - HotelSupports mixed speech of Japanese and English
Englishen-USEnglish
Chinesezh-cmn-Hans-CNChineseSupports mixed speech of Chinese and English