diff --git a/tts/tts-pad/libs/DUI-lite-SDK-for-Android-2.18.1.jar b/tts/tts-pad/libs/DUI-lite-SDK-for-Android-2.18.1.jar deleted file mode 100644 index ff88eb4f4c..0000000000 Binary files a/tts/tts-pad/libs/DUI-lite-SDK-for-Android-2.18.1.jar and /dev/null differ diff --git a/tts/tts-pad/libs/DUI-lite-SDK-for-Android-CAR_v1.4.5-58-g33e903a.jar b/tts/tts-pad/libs/DUI-lite-SDK-for-Android-CAR_v1.4.5-58-g33e903a.jar new file mode 100644 index 0000000000..18c0c6cc37 Binary files /dev/null and b/tts/tts-pad/libs/DUI-lite-SDK-for-Android-CAR_v1.4.5-58-g33e903a.jar differ diff --git a/tts/tts-pad/src/main/assets/v2.1.31_aitts_sent_dict_local.db b/tts/tts-pad/src/main/assets/aitts_sent_dict_local.db similarity index 69% rename from tts/tts-pad/src/main/assets/v2.1.31_aitts_sent_dict_local.db rename to tts/tts-pad/src/main/assets/aitts_sent_dict_local.db index 991cee42a9..3bb8f10139 100644 Binary files a/tts/tts-pad/src/main/assets/v2.1.31_aitts_sent_dict_local.db and b/tts/tts-pad/src/main/assets/aitts_sent_dict_local.db differ diff --git a/tts/tts-pad/src/main/assets/guodgm_common_back_ce_local.v2.1.0.bin b/tts/tts-pad/src/main/assets/guodgm_common_back_ce_local.v2.1.0.bin new file mode 100644 index 0000000000..81ac2d6092 Binary files /dev/null and b/tts/tts-pad/src/main/assets/guodgm_common_back_ce_local.v2.1.0.bin differ diff --git a/tts/tts-pad/src/main/assets/v2.1.31_local_front.bin b/tts/tts-pad/src/main/assets/local_front.bin similarity index 98% rename from tts/tts-pad/src/main/assets/v2.1.31_local_front.bin rename to tts/tts-pad/src/main/assets/local_front.bin index e3ed833aaa..c0f19f94e5 100644 Binary files a/tts/tts-pad/src/main/assets/v2.1.31_local_front.bin and b/tts/tts-pad/src/main/assets/local_front.bin differ diff --git a/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java b/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java index 25db02dca6..49518e86f0 100644 --- a/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java +++ b/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java @@ -1,21 +1,26 @@ package com.mogo.tts.pad; +import android.app.ActivityManager; import android.content.Context; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.os.Build; import android.os.Environment; import android.provider.Settings; import android.text.TextUtils; -import com.aispeech.AIEchoConfig; import com.aispeech.AIError; import com.aispeech.DUILiteConfig; import com.aispeech.DUILiteSDK; import com.aispeech.common.AIConstant; import com.aispeech.export.config.AILocalTTSConfig; -import com.aispeech.export.engines2.AILocalTTSEngine; +import com.aispeech.export.config.AuthConfig; +import com.aispeech.export.config.EchoConfig; +import com.aispeech.export.engines.AILocalTTSEngine; import com.aispeech.export.intent.AILocalTTSIntent; import com.aispeech.export.listeners.AILocalTTSListener; +import com.aispeech.export.listeners.AITTSListener; +import com.aispeech.lite.AuthType; import com.alibaba.android.arouter.facade.annotation.Route; import com.mogo.cloud.commons.BuildConfig; import com.mogo.cloud.passport.MoGoAiCloudClientConfig; @@ -23,7 +28,6 @@ import com.mogo.tts.base.IMogoTTS; import com.mogo.tts.base.IMogoTTSCallback; import com.mogo.tts.base.MogoTTSConstants; import com.mogo.tts.base.PreemptType; -import com.mogo.utils.AppUtils; import com.mogo.utils.logger.Logger; import com.zhidao.auto.platform.voice.VoiceClient; import com.zhidao.voicesdk.MogoVoiceManager; @@ -92,11 +96,12 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList //echo module res private static final String ECHO_RES = "echo/sspe_aec_ch2_mic1_ref1_asr_v2.0.0.95.bin"; //local tts module res - private static final String TTS_DICT_RES = "v2.1.31_aitts_sent_dict_local.db"; - private static final String TTS_FRONT_RES = "v2.1.31_local_front.bin"; + private static final String TTS_DICT_RES = "aitts_sent_dict_local.db"; + private static final String TTS_FRONT_RES = "local_front.bin"; + public static final String TTS_BACK_RES_GUODGM = "tts/guodgm_common_back_ce_local.v2.1.0.bin"; private AILocalTTSEngine mEngine; private AILocalTTSIntent mAILocalTTSIntent; - private String[] mBackResBinArray = new String[]{TTS_BACK_RES_ZHILING}; + private String[] mBackResBinArray = new String[]{TTS_BACK_RES_ZHILING,TTS_BACK_RES_GUODGM}; // 单独的语音播放 private boolean mHasAuth; @@ -108,62 +113,53 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList private void initTtsConfig() { Logger.d(TAG, "initTtsConfig"); - // 产品认证需设置 apiKey, productId, productKey, productSecret -// DUILiteConfig config = new DUILiteConfig( -// "d65ec9d65082d65ec9d65082614c36cc", -// "279605401", -// "cdb83d210ad55d7e9e388754eb890e7c", -// "5bd044ac68dc193df2e0fc4be3a120dd"); -// config.setAuthTimeout(5000); //设置授权连接超时时长,默认5000ms -// config.setExtraParameter("DEVICE_NAME", "fea815f374af8"); -// config.setExtraParameter("DEVICE_ID", "fea815f374af8"); + //在线授权配置 + AuthConfig.Builder onlineBuilder = new AuthConfig.Builder() + .setType(AuthType.ONLINE) + .setCustomDeviceName(MoGoAiCloudClientConfig.getInstance().getSn()); - DUILiteConfig config = new DUILiteConfig( - "113cc31f6385113cc31f6385618c86f5", - "278586132", - "1fe5930844b488a8d32d9ef7717be7dc", - "f601ecc407986b548ac8ab2a9144162e"); - config.setExtraParameter("DEVICE_NAME", MoGoAiCloudClientConfig.getInstance().getSn()); - config.setExtraParameter("DEVICE_ID", MoGoAiCloudClientConfig.getInstance().getSn()); - config.setAuthTimeout(5000); //设置授权连接超时时长,默认5000ms - config.setDeviceProfileDirPath("/sdcard/speech"); // 自定义设置授权文件的保存路径,需要确保该路径事先存在 -// config.setThreadAffinity(3); //绑定第3个核,降低CPU占用 -// config.setOfflineProfileName("auth.txt");//设置assetes目录下的离线授权文件 - //设置SDK录音模式 - // 单麦 单麦Echo 双麦 线性4麦 环形4麦 环形6麦,可选的 - config.setAudioRecorderType(audioRecorderType); - if (config.getAudioRecorderType() == DUILiteConfig.TYPE_COMMON_ECHO) { - AIEchoConfig aiEchoConfig = new AIEchoConfig(); - aiEchoConfig.setAecResource(ECHO_RES); // 设置echo的AEC资源文件 - aiEchoConfig.setChannels(2); //音频总的通道数 - aiEchoConfig.setMicNumber(1); //真实mic数 - // 默认为1,即左通道为rec录音音频,右通道为play参考音频(播放音频) - // 若设置为2,通道会互换,即左通道为play参考音频(播放音频),右通道为rec录音音频 - aiEchoConfig.setRecChannel(1); - aiEchoConfig.setSavedDirPath("/sdcard/aispeech/aecPcmFile/");//设置保存的aec原始输入和aec之后的音频文件路径 - config.setEchoConfig(aiEchoConfig); - } - if (BuildConfig.DEBUG) { - config.openLog(); - // 设置log日志的级别 - DUILiteSDK.setDebugMode(3); - } - Logger.d(TAG, "DUILite SDK is isAuthorized ? " + DUILiteSDK.isAuthorized(mContext)); - DUILiteSDK.init(mContext, - config, - new DUILiteSDK.InitListener() { - @Override - public void success() { - Logger.d(TAG, "授权成功!"); - mHasAuth = true; - initTtsEngine(); - } + //echo 配置 + EchoConfig echoConfig = new EchoConfig.Builder() + .setAecResource(ECHO_RES)// 2mic AEC资源 + .setChannels(2)//设置音频通道数 + .setMicNumber(1)//设置mic数 + .setSavedDirPath("/sdcard/aispeech/aecPcmFile/")//设置echo前后音频保存路径 + .create(); - @Override - public void error(final String errorCode, final String errorInfo) { - Logger.d(TAG, "授权失败\n\nErrorCode:" + errorCode + "\n\nErrorInfo:" + errorInfo); - } - }); + if (BuildConfig.DEBUG){ + DUILiteSDK.openLog();//开启日志,需要在sdk init 之前调用 + } + + DUILiteSDK.init(mContext, new DUILiteConfig.Builder() + .setApiKey("113cc31f6385113cc31f6385618c86f5") + .setProductId("278586132") + .setProductKey("1fe5930844b488a8d32d9ef7717be7dc") + .setProductSecret("f601ecc407986b548ac8ab2a9144162e") + .setAuthConfig(onlineBuilder.create())//授权配置 +// .setRecorderConfig(recorderConfig)//设置录音配置 +// .setUploadConfig(uploadConfig)//设置日志上传配置 +// .setTtsCacheDir("/sdcard/speech/cache") //设置tts cache文件存放目录 + .setEchoConfig(echoConfig) + .create(), new DUILiteSDK.InitListener() { + @Override + public void success() { + Logger.d(TAG, "授权成功"); + mHasAuth = true; + initTtsEngine(); + } + + @Override + public void error(String errorCode, final String errorInfo) { + Logger.e(TAG, "error code : " + errorCode + " , error info :" + errorInfo); +// throw new IllegalStateException("授权失败,请检查授权配置"); + } + }); + + boolean isAuthorized = DUILiteSDK.isAuthorized(mContext);//查询授权状态,DUILiteSDK.init之后随时可以调 + Logger.d(TAG, "DUILite SDK is isAuthorized ? " + isAuthorized); + + String core_version = DUILiteSDK.getCoreVersion();//获取内核版本号 + Logger.d(TAG, "core version is: " + core_version); } private void initTtsEngine() { @@ -171,39 +167,45 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList if (mEngine != null) { mEngine.destroy(); } - AILocalTTSConfig config = new AILocalTTSConfig(); - // 设置assets目录下合成字典名 - config.setDictResource(TTS_DICT_RES);//普通话字典 - // 设置合成字典的外部路径,包含文件名(需要手动拷贝到指定目录) - // config.setDictResource("/sdcard/speech/tts/aitts_sent_dict_idx_middle_2.0.4_20180806.db"); +// AILocalTTSConfig config = new AILocalTTSConfig(); +// // 设置assets目录下合成字典名 +// config.setDictResource(TTS_DICT_RES);//普通话字典 +// // 设置合成字典的外部路径,包含文件名(需要手动拷贝到指定目录) +// // config.setDictResource("/sdcard/speech/tts/aitts_sent_dict_idx_middle_2.0.4_20180806.db"); +// +// // 非必需,用户自定义词典,用于修复离线合成问题,如多音字发音、停顿和数字字母符号读法错误等 +// // 正常情況用不着,这个只有有发音问题需要紧急修复可以改这个资源。user_source.bin该资源由合成组提供的工具包生成。 +// // config.setUserDictResource("user_source.bin"); +// // 设置assets目录下前端合成资源名 +// config.setFrontBinResource(TTS_FRONT_RES);//普通话前端资源 +// //config.setFrontBinResource(SampleConstants.TTS_FRONT_RES_YUEYU);//粤语前端资源 +// //config.setFrontBinResource(SampleConstants.TTS_FRONT_RES_SICHUAN);//四川话前端资源 +// // 设置合成前端资源的外部路径,包含文件名(需要手动拷贝到指定目录) +// // config.setFrontBinResource("/sdcard/speech/tts/v2.1.23_local_front.bin"); +// // default is true +// config.setUseCache(false); +// //设置后端合成音色资源,如果只需设置一个,则array只需要传一个成员值就可以 +// config.addSpeakerResource(mBackResBinArray); +// // 设置合成音色的外部路径,包含文件名(需要手动拷贝到指定目录) +// // config.addSpeakerResource("/sdcard/speech/tts/zhilingf_common_back_ce_local.v2.1.0.bin"); - // 非必需,用户自定义词典,用于修复离线合成问题,如多音字发音、停顿和数字字母符号读法错误等 - // 正常情況用不着,这个只有有发音问题需要紧急修复可以改这个资源。user_source.bin该资源由合成组提供的工具包生成。 - // config.setUserDictResource("user_source.bin"); - // 设置assets目录下前端合成资源名 - config.setFrontBinResource(TTS_FRONT_RES);//普通话前端资源 - //config.setFrontBinResource(SampleConstants.TTS_FRONT_RES_YUEYU);//粤语前端资源 - //config.setFrontBinResource(SampleConstants.TTS_FRONT_RES_SICHUAN);//四川话前端资源 - // 设置合成前端资源的外部路径,包含文件名(需要手动拷贝到指定目录) - // config.setFrontBinResource("/sdcard/speech/tts/v2.1.23_local_front.bin"); - // default is true - config.setUseCache(false); - //设置后端合成音色资源,如果只需设置一个,则array只需要传一个成员值就可以 - config.addSpeakerResource(mBackResBinArray); - // 设置合成音色的外部路径,包含文件名(需要手动拷贝到指定目录) - // config.addSpeakerResource("/sdcard/speech/tts/zhilingf_common_back_ce_local.v2.1.0.bin"); + mEngine = AILocalTTSEngine.getInstance();//创建实例 - mEngine = AILocalTTSEngine.createInstance();//创建实例 + AILocalTTSConfig config = new AILocalTTSConfig.Builder() + .setFrontResBin(TTS_FRONT_RES)//设置前端合成资源路径.assets路径或sd卡路径均可 + .setDictDb(TTS_DICT_RES)//设置合成字典资源路径.assets路径或sd卡路径均可 + .setBackResBinArray(mBackResBinArray)//设置后端合成音色资源,如果只需设置一个,则array只需要传一个成员值就可以,init前设置setBackResBin接口无效 + .build(); mEngine.init(config, new AILocalTTSListenerImpl());//初始化合成引擎 mAILocalTTSIntent = new AILocalTTSIntent(); // 设置合成音语速,范围为0.5~2.0 - mAILocalTTSIntent.setSpeed(0.85f); + mAILocalTTSIntent.setSpeechRate(0.85f); mAILocalTTSIntent.setUseSSML(false); // 设置是否使用ssml合成语法,默认为false - mAILocalTTSIntent.setVolume(100); // 设置合成音频的音量,范围为1~500 + mAILocalTTSIntent.setSpeechVolume(100); // 设置合成音频的音量,范围为1~500 // 保存合成音频到指定路径,格式为wav - mAILocalTTSIntent.setSaveAudioFilePath(Environment.getExternalStorageDirectory() + "/tts/" + mAILocalTTSIntent.setSaveAudioFileName(Environment.getExternalStorageDirectory() + "/tts/" + System.currentTimeMillis() + ".wav"); } @@ -339,9 +341,9 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList Logger.d( TAG, "speakTTSVoice"); if (mEngine != null && mHasAuth) { // 合成并播放 - mEngine.speak(mAILocalTTSIntent, text, "1024"); + mEngine.speak(text,"1024",mAILocalTTSIntent); // 合成音频,不播放,同时输出实时pcm音频,音频回调在onSynthesizeDataArrived接口 - mEngine.synthesize(mAILocalTTSIntent, text, "1024"); +// mEngine.synthesize(mAILocalTTSIntent, text, "1024"); } } @@ -520,11 +522,11 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList } private boolean isVoiceServiceReady( Context context ) { - if ( AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.zhidao.speech" ) )) { + if ( isProcessRunning( context, getPackageUid( context, "com.zhidao.speech" ) )) { Logger.d( TAG, "pad txz is voiceServiceReady" ); return true; - } else if ( AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.txznet.txz" ) ) - && AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.txznet.adapter" ) ) ) { + } else if ( isProcessRunning( context, getPackageUid( context, "com.txznet.txz" ) ) + && isProcessRunning( context, getPackageUid( context, "com.txznet.adapter" ) ) ) { Logger.d( TAG, "txz is voiceServiceReady" ); return true; } @@ -632,7 +634,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList context.sendBroadcast( intent ); } - private static class AILocalTTSListenerImpl implements AILocalTTSListener { + private static class AILocalTTSListenerImpl implements AITTSListener { @Override public void onInit(int status) { @@ -645,8 +647,23 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList } @Override - public void onError(String utteranceId, AIError error) { - Logger.d(TAG, "检测到错误:" + error.toString()); + public void onError(String s, AIError aiError) { + Logger.d(TAG, "检测到错误:" + aiError.toString()); + } + + @Override + public void onReady(String s) { + Logger.d(TAG, "开始播放"); + } + + @Override + public void onCompletion(String s) { + Logger.d(TAG, "播放完成"); + } + + @Override + public void onProgress(int currentTime, int totalTime, boolean isRefTextTTSFinished) { + Logger.d(TAG, "当前:" + currentTime + "ms, 总计:" + totalTime + "ms, 可信度:" + isRefTextTTSFinished); } @Override @@ -665,20 +682,33 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList public void onSynthesizeFinish(String utteranceId) { Logger.d(TAG, "合成结束"); } + } - @Override - public void onSpeechStart(String utteranceId) { - Logger.d(TAG, "开始播放"); + public static boolean isProcessRunning( Context context, int uid ) { + if ( context == null ) { + return false; } - - @Override - public void onSpeechProgress(int currentTime, int totalTime, boolean isRefTextTTSFinished) { - Logger.d(TAG, "当前:" + currentTime + "ms, 总计:" + totalTime + "ms, 可信度:" + isRefTextTTSFinished); + ActivityManager am = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE ); + List< ActivityManager.RunningServiceInfo > runningServiceInfos = am.getRunningServices( 200 ); + if ( runningServiceInfos.size() > 0 ) { + for ( ActivityManager.RunningServiceInfo appProcess : runningServiceInfos ) { + if ( uid == appProcess.uid ) { + return true; + } + } } - - @Override - public void onSpeechFinish(String utteranceId) { - Logger.d(TAG, "播放完成"); + return false; + } + //获取已安装应用的 uid,-1 表示未安装此应用或程序异常 + public static int getPackageUid( Context context, String packageName ) { + try { + ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo( packageName, 0 ); + if ( applicationInfo != null ) { + return applicationInfo.uid; + } + } catch ( Exception e ) { + return -1; } + return -1; } } diff --git a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libcntts.so b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libcntts.so index 36db975411..e71996618a 100644 Binary files a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libcntts.so and b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libcntts.so differ diff --git a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libduiutils.so b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libduiutils.so old mode 100644 new mode 100755 index 9fcd8446f8..1a8f61131f Binary files a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libduiutils.so and b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libduiutils.so differ diff --git a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libliteca.so b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libliteca.so index 25f6ba8a15..f7f26eeb76 100644 Binary files a/tts/tts-pad/src/main/jniLibs/arm64-v8a/libliteca.so and b/tts/tts-pad/src/main/jniLibs/arm64-v8a/libliteca.so differ