|
@@ -39,7 +39,7 @@ public class RecordServices extends Service {
|
|
|
private String mUploadBody;
|
|
|
private RecordCallBack mRecordCallBack;
|
|
|
boolean isRecording = false;
|
|
|
-
|
|
|
+ boolean mRecordCreate = false;
|
|
|
|
|
|
@Nullable
|
|
|
@Override
|
|
@@ -66,48 +66,43 @@ public class RecordServices extends Service {
|
|
|
}
|
|
|
|
|
|
|
|
|
- void initChiVox(Context context, String name, String refText) {
|
|
|
- runOnWorkerThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- JSONObject cfg = new JSONObject();
|
|
|
- try {
|
|
|
- String provisionPath = AIEngineHelper.extractResourceOnce(Consts.getmApplicAtion(), "aiengine.provision", false);
|
|
|
- cfg.put("appKey", ChivoxBean.appKey); // 设置AppKey
|
|
|
- cfg.put("secretKey", ChivoxBean.secretKey); // 设置SecretKey
|
|
|
- cfg.put("provision", provisionPath);
|
|
|
-
|
|
|
- //获取sdk版本
|
|
|
- String version = SdkInfo.singleton().version;//获取二次封装SDK版本
|
|
|
- String commonversion = SdkInfo.singleton().commonSdkVersion;//获取通用SDK版本
|
|
|
- { // cloud
|
|
|
- JSONObject cloud = new JSONObject();
|
|
|
- cloud.put("enable", 1);
|
|
|
- cfg.put("cloud", cloud);
|
|
|
- }
|
|
|
-
|
|
|
- // 创建引擎,本调用不会阻塞UI线程,待创建成功后,会通过Engine.CreateCallback回调
|
|
|
- Engine.create(Consts.getmApplicAtion(), cfg, new Engine.CreateCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Engine engine) {
|
|
|
- // 创建成功, 请保存engine对象用于后续评测
|
|
|
- mAiengine = engine;
|
|
|
- Logger.e("初始化录音成功");
|
|
|
- startRecord(context, name, refText);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFail(RetValue err) {
|
|
|
- // 创建失败, 请查看e.errId和e.error分析原因。
|
|
|
- Logger.e(err.errId + ", " + err.error);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- } catch (Exception ex) {
|
|
|
- ex.printStackTrace();
|
|
|
+ public void initChiVox() {
|
|
|
+ JSONObject cfg = new JSONObject();
|
|
|
+ try {
|
|
|
+ String provisionPath = AIEngineHelper.extractResourceOnce(Consts.getmApplicAtion(), "aiengine.provision", false);
|
|
|
+ cfg.put("appKey", ChivoxBean.appKey); // 设置AppKey
|
|
|
+ cfg.put("secretKey", ChivoxBean.secretKey); // 设置SecretKey
|
|
|
+ cfg.put("provision", provisionPath);
|
|
|
+
|
|
|
+ //获取sdk版本
|
|
|
+ String version = SdkInfo.singleton().version;//获取二次封装SDK版本
|
|
|
+ String commonversion = SdkInfo.singleton().commonSdkVersion;//获取通用SDK版本
|
|
|
+ JSONObject cloud = new JSONObject();
|
|
|
+ cloud.put("enable", 1);
|
|
|
+ cfg.put("cloud", cloud);
|
|
|
+
|
|
|
+ // 创建引擎,本调用不会阻塞UI线程,待创建成功后,会通过Engine.CreateCallback回调
|
|
|
+ Engine.create(Consts.getmApplicAtion(), cfg, new Engine.CreateCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Engine engine) {
|
|
|
+ // 创建成功, 请保存engine对象用于后续评测
|
|
|
+ mAiengine = engine;
|
|
|
+ Logger.e("mAiengine is null:" + (mAiengine == null));
|
|
|
+ Logger.e("初始化录音成功");
|
|
|
+ mRecordCreate = true;
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(RetValue err) {
|
|
|
+ // 创建失败, 请查看e.errId和e.error分析原因。
|
|
|
+ Logger.e(err.errId + ", " + err.error);
|
|
|
+ mRecordCreate = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -115,10 +110,7 @@ public class RecordServices extends Service {
|
|
|
* 开始录音(如果没有初始化,就初始化,初始化了直接往下走)
|
|
|
* */
|
|
|
public void startRecord(Context context, String name, String refText) {
|
|
|
- if (mAiengine == null) {
|
|
|
- initChiVox(context, name, refText);
|
|
|
- return;
|
|
|
- }
|
|
|
+ Logger.e("mAiengine:" + (mAiengine == null));
|
|
|
JSONObject param = new JSONObject();
|
|
|
try {
|
|
|
param.put("coreProvideType", "cloud");
|
|
@@ -211,6 +203,7 @@ public class RecordServices extends Service {
|
|
|
isRecording = false;
|
|
|
mRecordCallBack.onRecordStop();
|
|
|
}
|
|
|
+ Logger.e("stopRecord==ret.errId:" + ret.errId);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -272,8 +265,10 @@ public class RecordServices extends Service {
|
|
|
|
|
|
|
|
|
public void desrotyRecord() {
|
|
|
+ Logger.e("desrotyRecord");
|
|
|
if (mAiengine != null) {
|
|
|
mAiengine.destroy();
|
|
|
+ mAiengine = null;
|
|
|
}
|
|
|
}
|
|
|
|