Browse Source

修改讯飞语音识别

weicu
tanlongsheng 10 months ago
parent
commit
149bb07fe2
  1. 17
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/XunFeiAsrHelper.kt

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

@ -107,11 +107,14 @@ class XunFeiAsrHelper(private val context: Context) {
val dataStr = jsonData.optString("data") val dataStr = jsonData.optString("data")
val data = JSONObject(dataStr) val data = JSONObject(dataStr)
val ls = data.optBoolean("ls")
val cn = data.optJSONObject("cn") ?: return val cn = data.optJSONObject("cn") ?: return
val st = cn.optJSONObject("st") ?: return val st = cn.optJSONObject("st") ?: return
val rt = st.optJSONArray("rt") ?: return val rt = st.optJSONArray("rt") ?: return
var resultTextTemp = "" var resultTextTemp = ""
var punctuationCount = 0
var wordCount = 0
for (i in 0 until rt.length()) { for (i in 0 until rt.length()) {
val j = rt.getJSONObject(i) val j = rt.getJSONObject(i)
@ -122,13 +125,27 @@ class XunFeiAsrHelper(private val context: Context) {
for (l in 0 until cw.length()) { for (l in 0 until cw.length()) {
val lObj = cw.getJSONObject(l) val lObj = cw.getJSONObject(l)
resultTextTemp += lObj.optString("w") resultTextTemp += lObj.optString("w")
if (lObj.optString("wp") == "p") {
punctuationCount++
} else {
wordCount++
}
} }
} }
} }
if (ls && wordCount == 0 && punctuationCount == 1) {
return
}
if (st.optInt("type") == 0) { if (st.optInt("type") == 0) {
callback.onResult(currentSessionId, resultTextTemp, "zh-CN") callback.onResult(currentSessionId, resultTextTemp, "zh-CN")
currentSessionId = ""
} else { } else {
if (currentSessionId.isEmpty()) {
currentSessionId = UUID.randomUUID().toString()
callback.onSessionStarted(currentSessionId)
}
callback.onRecognizing(currentSessionId, resultTextTemp, "zh-CN") callback.onRecognizing(currentSessionId, resultTextTemp, "zh-CN")
} }
} }

Loading…
Cancel
Save