Browse Source

修改讯飞语音识别

newdev_shunjiawei
tanlongsheng 10 months ago
parent
commit
2809d6a18f
  1. 8
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/XunFeiAsrHelper.kt

8
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/XunFeiAsrHelper.kt

@ -25,6 +25,7 @@ class XunFeiAsrHelper(private val context: Context) {
private var currentSessionId = "" private var currentSessionId = ""
private var sessionId = "" private var sessionId = ""
private var lastIntermediateResult = ""
fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback) { fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback) {
try { try {
@ -35,6 +36,7 @@ class XunFeiAsrHelper(private val context: Context) {
} }
currentSessionId = UUID.randomUUID().toString() currentSessionId = UUID.randomUUID().toString()
lastIntermediateResult = ""
val url = getWebSocketUrl() val url = getWebSocketUrl()
val request = Request.Builder().url(url).build() val request = Request.Builder().url(url).build()
@ -56,6 +58,10 @@ class XunFeiAsrHelper(private val context: Context) {
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
Log.d(tag, "WebSocket Closed: $code / $reason") Log.d(tag, "WebSocket Closed: $code / $reason")
if (currentSessionId.isNotEmpty() && lastIntermediateResult.isNotEmpty()) {
callback.onResult(currentSessionId, lastIntermediateResult, "zh-CN")
currentSessionId = ""
}
callback.onSessionStopped(currentSessionId) callback.onSessionStopped(currentSessionId)
} }
@ -141,11 +147,13 @@ class XunFeiAsrHelper(private val context: Context) {
if (st.optInt("type") == 0) { if (st.optInt("type") == 0) {
callback.onResult(currentSessionId, resultTextTemp, "zh-CN") callback.onResult(currentSessionId, resultTextTemp, "zh-CN")
currentSessionId = "" currentSessionId = ""
lastIntermediateResult = ""
} else { } else {
if (currentSessionId.isEmpty()) { if (currentSessionId.isEmpty()) {
currentSessionId = UUID.randomUUID().toString() currentSessionId = UUID.randomUUID().toString()
callback.onSessionStarted(currentSessionId) callback.onSessionStarted(currentSessionId)
} }
lastIntermediateResult = resultTextTemp
callback.onRecognizing(currentSessionId, resultTextTemp, "zh-CN") callback.onRecognizing(currentSessionId, resultTextTemp, "zh-CN")
} }
} }

Loading…
Cancel
Save