1.申请相关Key
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4b45c7dc5ffb6d10f836de53e7f5fe94.png#pic_center)
2.引入相关资源
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/37f4b79ea517e0a94ae892ddb05417ff.png#pic_center)
3.Gradle文件配置
signingConfigs {
training {
storeFile file("./keystore/xxx.jks")
storePassword ""
keyAlias ""
keyPassword ""
}
}
buildTypes {
debug {
signingConfig signingConfigs.training
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
signingConfig signingConfigs.training
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
implementation files('libs/lib-dds-1.2.23.1-release.aar')
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3c288f61368d69326bc1eb1f986e652b.png#pic_center)
4.AndroidMenifest.xml配置
android:sharedUserId="android.uid.system"
android:persistent="true"
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a0960bfe0c893d0c0a30761523f3dced.png#pic_center)
5.初始化DDS
package com.example.ddsworktest2;
import android.os.Bundle;
import com.aispeech.ailog.AILog;
import com.aispeech.dui.dds.DDS;
import com.aispeech.dui.dds.DDSAuthListener;
import com.aispeech.dui.dds.DDSConfig;
import com.aispeech.dui.dds.DDSInitListener;
import com.aispeech.dui.dds.exceptions.DDSNotInitCompleteException;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
public static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DDS.getInstance().setDebugMode(3);
DDS.getInstance().init(
getApplicationContext(),
new DDSConfig()
.addConfig(DDSConfig.K_PRODUCT_ID, "")
.addConfig(DDSConfig.K_USER_ID, "")
.addConfig(DDSConfig.K_ALIAS_KEY, "")
.addConfig(DDSConfig.K_API_KEY, "")
.addConfig(DDSConfig.K_PRODUCT_KEY, "")
.addConfig(DDSConfig.K_PRODUCT_SECRET, "")
.addConfig(DDSConfig.K_DUICORE_ZIP, "820394c2753440956204ab6b29ff40f8.zip")
.addConfig(DDSConfig.K_USE_UPDATE_DUICORE, "false")
.addConfig(DDSConfig.K_MIC_TYPE,"5")
.addConfig(DDSConfig.K_CUSTOM_ZIP, "product.zip"),
new DDSInitListener() {
@Override
public void onInitComplete(boolean isFull) {
AILog.d(TAG, "onInitComplete: " + isFull);
try {
boolean authSuccess = DDS.getInstance().isAuthSuccess();
String[] wakeupWords = DDS.getInstance()
.getAgent()
.getWakeupEngine()
.getWakeupWords();
for (String s:wakeupWords) {
AILog.d(TAG, "唤醒词: " + s);
}
AILog.d(TAG, "authSuccess: " + authSuccess);
if (!authSuccess) {
DDS.getInstance().doAuth();
}
if (DDS.getInstance()
.getInitStatus() == DDS.INIT_COMPLETE_FULL && DDS.getInstance()
.isAuthSuccess()) {
DDS.getInstance().getAgent().getWakeupEngine().enableWakeup();
}
} catch (DDSNotInitCompleteException e) {
e.printStackTrace();
}
}
@Override
public void onError(int what, String msg) {
AILog.d(TAG, "onError: " + what + ", error: " + msg);
}
}, new DDSAuthListener() {
@Override
public void onAuthSuccess() {
AILog.d(TAG, "onAuthSuccess");
}
@Override
public void onAuthFailed(String errId, String error) {
AILog.d(TAG, "onAuthFailed: " + errId + ", error:" + error);
}
});
}
}