Browse Source

修改讯飞语音识别

weicu
tanlongsheng 10 months ago
parent
commit
e840e25d4c
  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 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")
}
}

Loading…
Cancel
Save