[8.0.0]
[fea] [科大讯飞 离线唤醒 资源导入+初始化]
This commit is contained in:
@@ -7,6 +7,7 @@ import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.mgintelligent.speech.MGSpeech
|
||||
import com.mogo.mgintelligent.speech.iflytek.WakeManager
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.biz.provider.CommonServiceImpl
|
||||
import com.mogo.och.bridge.autopilot.autopilot.OchAutopilotAnalytics
|
||||
@@ -32,6 +33,7 @@ class TaxiUnmannedPassengerProvider : CommonServiceImpl() {
|
||||
d(SceneConstant.M_TAXI_P + tag, "init")
|
||||
statusBarView = StatusBarView(context)
|
||||
MGSpeech.init(context)
|
||||
WakeManager.initWakeAi(context)
|
||||
}
|
||||
|
||||
override fun getStatusBarView(context: Context): View {
|
||||
|
||||
@@ -57,4 +57,9 @@ dependencies {
|
||||
|
||||
implementation(files("libs/bdasr_V3_20210628_cfe8c44.jar"))
|
||||
implementation(files("libs/com.baidu.tts_2.6.3.c2aaa9f_20220922113422.jar"))
|
||||
|
||||
implementation files('libs/AIKit.aar')
|
||||
|
||||
implementation project(':foudations:mogo-commons')
|
||||
implementation project(':core:mogo-core-utils')
|
||||
}
|
||||
|
||||
BIN
libraries/mogo-speech/libs/AIKit.aar
Normal file
BIN
libraries/mogo-speech/libs/AIKit.aar
Normal file
Binary file not shown.
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_FILLER_1
Normal file
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_FILLER_1
Normal file
Binary file not shown.
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_GRAM_1
Normal file
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_GRAM_1
Normal file
Binary file not shown.
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_KEYWORD_1
Normal file
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_KEYWORD_1
Normal file
Binary file not shown.
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_MLP_1
Normal file
BIN
libraries/mogo-speech/src/main/assets/ivw/IVW_MLP_1
Normal file
Binary file not shown.
1
libraries/mogo-speech/src/main/assets/ivw/version_2
Normal file
1
libraries/mogo-speech/src/main/assets/ivw/version_2
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.mogo.mgintelligent.speech.iflytek
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.iflytek.aikit.core.AiHelper
|
||||
import com.iflytek.aikit.core.BaseLibrary
|
||||
import com.iflytek.aikit.core.CoreListener
|
||||
import com.iflytek.aikit.core.ErrType
|
||||
import com.iflytek.aikit.core.LogLvl
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.FileUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ResourceUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import java.io.File
|
||||
|
||||
object WakeManager {
|
||||
|
||||
private val TAG = "WakeManager"
|
||||
|
||||
private val coreListener = CoreListener { type, code ->
|
||||
Log.i(TAG, "core listener code:$code")
|
||||
|
||||
when (type) {
|
||||
ErrType.AUTH -> {
|
||||
if (code == 0) {
|
||||
Log.i(TAG, "SDK授权成功")
|
||||
} else {
|
||||
Log.i(TAG, "SDK授权失败,授权码为:$code")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ErrType.HTTP -> Log.i(TAG, "SDK状态:HTTP认证结果$code")
|
||||
|
||||
else -> Log.i(TAG, "SDK状态:其他错误$code")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun initWakeAi(context: Context) {
|
||||
|
||||
try {
|
||||
val workDir = getWorkDir()
|
||||
copyFile(workDir)
|
||||
val file = File(workDir)
|
||||
if(!file.exists()){
|
||||
file.mkdirs()
|
||||
}
|
||||
AiHelper.getInst().setLogInfo(LogLvl.VERBOSE, 1, "${workDir}aeeLog.txt")
|
||||
|
||||
//设定初始化参数
|
||||
val params = BaseLibrary.Params.builder()
|
||||
.appId("0c498b42") //您的应用ID,可从控制台查看
|
||||
.apiKey("8579f566eb7f3c4f4a07148ad9e2408c") //您的APIKEY,可从控制台查看
|
||||
.apiSecret("NTRmMmI5MWI4NzIzZTIxN2Q5N2FjMWVl") //您的APISECRET,可从控制台查看
|
||||
.workDir(workDir) //SDK的工作目录,需要确保有读写权限。一般用于存放离线能力资源,日志存放目录等使用。
|
||||
.build()
|
||||
|
||||
AiHelper.getInst().registerListener(coreListener) // 注册SDK 初始化状态监听
|
||||
AiHelper.getInst().initEntry(context, params)
|
||||
}catch (e:Exception){
|
||||
CallerLogger.d(TAG,"初始化失败:${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyFile(workDir: String) {
|
||||
ThreadUtils.getIoPool().submit{
|
||||
val dir = "ivw"
|
||||
val targetDir = workDir + File.separator + dir
|
||||
if(checkCopied(dir,targetDir)) {
|
||||
FileUtils.deleteAllInDir(targetDir)
|
||||
ResourceUtils.copyFileFromAssets(dir, targetDir)
|
||||
CallerLogger.d(TAG,"copy 完成")
|
||||
}else{
|
||||
CallerLogger.d(TAG,"文件已经存在 不需要copy")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkCopied(dir: String, targetDir: String): Boolean {
|
||||
val assets = Utils.getApp().assets.list(dir)?.toMutableList()
|
||||
val tartgetFile = File(targetDir)
|
||||
if(tartgetFile.isDirectory){
|
||||
tartgetFile.listFiles { dir, name ->
|
||||
(assets?.contains(name)?:true).apply {
|
||||
assets?.remove(name)
|
||||
}
|
||||
}
|
||||
return assets?.isNotEmpty()?:false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun getWorkDir():String{
|
||||
AbsMogoApplication.getApp()?.let {
|
||||
return it.filesDir.path + File.separator + "iflytek" + File.separator
|
||||
}
|
||||
throw IllegalArgumentException("找不到 Application")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user