-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构ASR部分代码,添加华为HMS语音识别;修复TTS初始化失败问题;优化长时间退出无法唤醒问题;优化界面;版本号更新至1.5.0
- Loading branch information
1 parent
ca0d666
commit 24704ba
Showing
27 changed files
with
577 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"agcgw_all":{ | ||
"CN":"connect-drcn.dbankcloud.cn", | ||
"CN_back":"connect-drcn.hispace.hicloud.com", | ||
"DE":"connect-dre.dbankcloud.cn", | ||
"DE_back":"connect-dre.hispace.hicloud.com", | ||
"RU":"connect-drru.hispace.dbankcloud.ru", | ||
"RU_back":"connect-drru.hispace.dbankcloud.cn", | ||
"SG":"connect-dra.dbankcloud.cn", | ||
"SG_back":"connect-dra.hispace.hicloud.com" | ||
}, | ||
"websocketgw_all":{ | ||
"CN":"connect-ws-drcn.hispace.dbankcloud.cn", | ||
"CN_back":"connect-ws-drcn.hispace.dbankcloud.com", | ||
"DE":"connect-ws-dre.hispace.dbankcloud.cn", | ||
"DE_back":"connect-ws-dre.hispace.dbankcloud.com", | ||
"RU":"connect-ws-drru.hispace.dbankcloud.ru", | ||
"RU_back":"connect-ws-drru.hispace.dbankcloud.cn", | ||
"SG":"connect-ws-dra.hispace.dbankcloud.cn", | ||
"SG_back":"connect-ws-dra.hispace.dbankcloud.com" | ||
}, | ||
"client":{ | ||
"cp_id":"70086000187586270", | ||
"product_id":"388421841221708581", | ||
"project_id":"388421841221708581", | ||
"app_id":"109326889", | ||
"package_name":"com.skythinker.gptassistant" | ||
}, | ||
"oauth_client":{ | ||
"client_id":"109326889", | ||
"client_type":1 | ||
}, | ||
"app_info":{ | ||
"app_id":"109326889", | ||
"package_name":"com.skythinker.gptassistant" | ||
}, | ||
"configuration_version":"3.0", | ||
"appInfos":[ | ||
{ | ||
"package_name":"com.skythinker.gptassistant", | ||
"client":{ | ||
"app_id":"109326889" | ||
}, | ||
"app_info":{ | ||
"package_name":"com.skythinker.gptassistant", | ||
"app_id":"109326889" | ||
}, | ||
"oauth_client":{ | ||
"client_type":1, | ||
"client_id":"109326889" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/skythinker/gptassistant/AsrClientBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.skythinker.gptassistant; | ||
|
||
public abstract class AsrClientBase { | ||
public interface IAsrCallback { | ||
void onError(String msg); | ||
void onResult(String result); | ||
} | ||
public abstract void startRecongnize(); | ||
public abstract void stopRecongnize(); | ||
public abstract void cancelRecongnize(); | ||
public abstract void setCallback(IAsrCallback callback); | ||
public abstract void setParam(String key, Object value); | ||
public abstract void destroy(); | ||
} |
107 changes: 107 additions & 0 deletions
107
app/src/main/java/com/skythinker/gptassistant/BaiduAsrClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.skythinker.gptassistant; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import com.baidu.speech.EventListener; | ||
import com.baidu.speech.EventManager; | ||
import com.baidu.speech.EventManagerFactory; | ||
import com.baidu.speech.asr.SpeechConstant; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class BaiduAsrClient extends AsrClientBase{ | ||
private EventManager asr = null; | ||
String asrBuffer = ""; | ||
IAsrCallback callback = null; | ||
EventListener listener = null; | ||
|
||
public BaiduAsrClient(Context context) { | ||
asr = EventManagerFactory.create(context, "asr"); | ||
listener = new EventListener() { | ||
@Override | ||
public void onEvent(String name, String params, byte[] data, int offset, int length) { | ||
if(name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) { | ||
Log.d("bd asr partial", params); | ||
try { | ||
JSONObject json = new JSONObject(params); | ||
String resultType = json.getString("result_type"); | ||
if(resultType.equals("final_result")) { | ||
String bestResult = json.getString("best_result"); | ||
asrBuffer += bestResult; | ||
callback.onResult(asrBuffer); | ||
}else if(resultType.equals("partial_result")){ | ||
String bestResult = json.getString("best_result"); | ||
callback.onResult(String.format("%s%s", asrBuffer, bestResult)); | ||
} | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} else if(name.equals(SpeechConstant.CALLBACK_EVENT_ASR_FINISH)) { | ||
try { | ||
JSONObject json = new JSONObject(params); | ||
int errorCode = json.getInt("error"); | ||
if(errorCode != 0) { | ||
String errorMessage = json.getString("desc"); | ||
Log.d("asr error", "error code: " + errorCode + ", error message: " + errorMessage); | ||
callback.onError(errorMessage); | ||
} | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}; | ||
asr.registerListener(listener); | ||
} | ||
|
||
@Override | ||
public void startRecongnize() { | ||
Map<String, Object> params = new LinkedHashMap<>(); | ||
params.put(SpeechConstant.APP_ID, GlobalDataHolder.getAsrAppId()); | ||
params.put(SpeechConstant.APP_KEY, GlobalDataHolder.getAsrApiKey()); | ||
params.put(SpeechConstant.SECRET, GlobalDataHolder.getAsrSecretKey()); | ||
if(GlobalDataHolder.getAsrUseRealTime()){ | ||
params.put(SpeechConstant.BDS_ASR_ENABLE_LONG_SPEECH, true); | ||
params.put(SpeechConstant.VAD, SpeechConstant.VAD_DNN); | ||
} | ||
else{ | ||
params.put(SpeechConstant.BDS_ASR_ENABLE_LONG_SPEECH, false); | ||
params.put(SpeechConstant.VAD, SpeechConstant.VAD_TOUCH); | ||
} | ||
params.put(SpeechConstant.PID, 15374); | ||
asr.send(SpeechConstant.ASR_START, (new JSONObject(params)).toString(), null, 0, 0); | ||
asrBuffer = ""; | ||
} | ||
|
||
@Override | ||
public void stopRecongnize() { | ||
asr.send(SpeechConstant.ASR_STOP, "{}", null, 0, 0); | ||
} | ||
|
||
@Override | ||
public void cancelRecongnize() { | ||
asr.send(SpeechConstant.ASR_CANCEL, null, null, 0, 0); | ||
} | ||
|
||
@Override | ||
public void setCallback(IAsrCallback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void setParam(String key, Object value) { | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { | ||
cancelRecongnize(); | ||
asr.unregisterListener(listener); | ||
} | ||
} |
Oops, something went wrong.