|
|
|
@ -25,6 +25,7 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
|
|
|
|
private var currentSessionId = "" |
|
|
|
private var sessionId = "" |
|
|
|
private var lastIntermediateResult = "" |
|
|
|
|
|
|
|
fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback) { |
|
|
|
try { |
|
|
|
@ -35,6 +36,7 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
} |
|
|
|
|
|
|
|
currentSessionId = UUID.randomUUID().toString() |
|
|
|
lastIntermediateResult = "" |
|
|
|
|
|
|
|
val url = getWebSocketUrl() |
|
|
|
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) { |
|
|
|
Log.d(tag, "WebSocket Closed: $code / $reason") |
|
|
|
if (currentSessionId.isNotEmpty() && lastIntermediateResult.isNotEmpty()) { |
|
|
|
callback.onResult(currentSessionId, lastIntermediateResult, "zh-CN") |
|
|
|
currentSessionId = "" |
|
|
|
} |
|
|
|
callback.onSessionStopped(currentSessionId) |
|
|
|
} |
|
|
|
|
|
|
|
@ -141,11 +147,13 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
if (st.optInt("type") == 0) { |
|
|
|
callback.onResult(currentSessionId, resultTextTemp, "zh-CN") |
|
|
|
currentSessionId = "" |
|
|
|
lastIntermediateResult = "" |
|
|
|
} else { |
|
|
|
if (currentSessionId.isEmpty()) { |
|
|
|
currentSessionId = UUID.randomUUID().toString() |
|
|
|
callback.onSessionStarted(currentSessionId) |
|
|
|
} |
|
|
|
lastIntermediateResult = resultTextTemp |
|
|
|
callback.onRecognizing(currentSessionId, resultTextTemp, "zh-CN") |
|
|
|
} |
|
|
|
} |
|
|
|
|