|
|
@ -30,7 +30,10 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
private var currentLanguage = "zh-CN" |
|
|
private var currentLanguage = "zh-CN" |
|
|
private var isAutoDetectLanguage = false |
|
|
private var isAutoDetectLanguage = false |
|
|
|
|
|
|
|
|
fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback, language: String, isAutoDetect: Boolean) { |
|
|
// 是否第去除一个文字的标点符号 |
|
|
|
|
|
private var removeFirstPunctuation = true |
|
|
|
|
|
|
|
|
|
|
|
fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback, language: String, isAutoDetect: Boolean, isRemoveFirstPunctuation: Boolean) { |
|
|
try { |
|
|
try { |
|
|
webSocket?.cancel() |
|
|
webSocket?.cancel() |
|
|
webSocket = null |
|
|
webSocket = null |
|
|
@ -43,6 +46,7 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
|
|
|
|
|
currentLanguage = language |
|
|
currentLanguage = language |
|
|
isAutoDetectLanguage = isAutoDetect |
|
|
isAutoDetectLanguage = isAutoDetect |
|
|
|
|
|
removeFirstPunctuation = isRemoveFirstPunctuation |
|
|
|
|
|
|
|
|
val url = getWebSocketUrl() |
|
|
val url = getWebSocketUrl() |
|
|
val request = Request.Builder().url(url).build() |
|
|
val request = Request.Builder().url(url).build() |
|
|
@ -142,32 +146,35 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
for (k in 0 until ws.length()) { |
|
|
for (k in 0 until ws.length()) { |
|
|
val kObj = ws.getJSONObject(k) |
|
|
val kObj = ws.getJSONObject(k) |
|
|
val cw = kObj.optJSONArray("cw") ?: continue |
|
|
val cw = kObj.optJSONArray("cw") ?: continue |
|
|
// 如果resultTextTemp中第一个文字是标点符号,则去除第一个文字的标点符号 |
|
|
if(removeFirstPunctuation) { |
|
|
for (l in 0 until cw.length()) { |
|
|
// 如果resultTextTemp中第一个文字是标点符号,则去除第一个文字的标点符号 |
|
|
val lObj = cw.getJSONObject(l) |
|
|
for (l in 0 until cw.length()) { |
|
|
val w = lObj.optString("w") |
|
|
val lObj = cw.getJSONObject(l) |
|
|
val wp = lObj.optString("wp") |
|
|
val w = lObj.optString("w") |
|
|
|
|
|
val wp = lObj.optString("wp") |
|
|
if (wp == "p") { |
|
|
|
|
|
punctuationCount++ |
|
|
if (wp == "p") { |
|
|
if (resultTextTemp.isEmpty()) { |
|
|
punctuationCount++ |
|
|
continue |
|
|
if (resultTextTemp.isEmpty()) { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
wordCount++ |
|
|
|
|
|
} |
|
|
|
|
|
resultTextTemp += w |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 不去除resultTextTemp第一个文字的标点符号 |
|
|
|
|
|
for (l in 0 until cw.length()) { |
|
|
|
|
|
val lObj = cw.getJSONObject(l) |
|
|
|
|
|
resultTextTemp += lObj.optString("w") |
|
|
|
|
|
if (lObj.optString("wp") == "p") { |
|
|
|
|
|
punctuationCount++ |
|
|
|
|
|
} else { |
|
|
|
|
|
wordCount++ |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
wordCount++ |
|
|
|
|
|
} |
|
|
} |
|
|
resultTextTemp += w |
|
|
|
|
|
} |
|
|
} |
|
|
// 不去除resultTextTemp第一个文字的标点符号 |
|
|
|
|
|
// for (l in 0 until cw.length()) { |
|
|
|
|
|
// val lObj = cw.getJSONObject(l) |
|
|
|
|
|
// resultTextTemp += lObj.optString("w") |
|
|
|
|
|
// if (lObj.optString("wp") == "p") { |
|
|
|
|
|
// punctuationCount++ |
|
|
|
|
|
// } else { |
|
|
|
|
|
// wordCount++ |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|