[6.4.0]工单上报修复语音输入Bug

This commit is contained in:
xuxinchao
2024-04-23 17:09:35 +08:00
parent 1313d7bf99
commit cfd9e0bbb6

View File

@@ -50,8 +50,6 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.json.JSONException
import org.json.JSONObject
import kotlin.math.absoluteValue
/**
@@ -79,7 +77,6 @@ class WorkOrderWindow constructor(activity: Activity) : View.OnTouchListener,
// 语音听写对象
private var mIat: SpeechRecognizer? = null
private var reasonDetail: String = "" //语音转写
// 用HashMap存储听写结果
private val mIatResults: HashMap<String, String> = LinkedHashMap()
@@ -326,30 +323,16 @@ class WorkOrderWindow constructor(activity: Activity) : View.OnTouchListener,
@SuppressLint("SetTextI18n")
private fun printResult(results: RecognizerResult) {
val text: String = JsonParser.parseIatResult(results.resultString)
var sn: String? = null
// 读取json结果中的sn字段
try {
val resultJson = JSONObject(results.resultString)
sn = resultJson.optString("sn")
} catch (e: JSONException) {
e.printStackTrace()
}
mIatResults[sn!!] = text
val resultBuffer = java.lang.StringBuilder()
for (key in mIatResults.keys) {
resultBuffer.append(mIatResults[key])
}
Log.i(TAG, "语音内容=$resultBuffer")
reasonDetail = resultBuffer.toString()
if(reasonDetail.isNotEmpty()){
Log.i(TAG, "语音内容=$text")
if(text.isNotEmpty()){
if(etDescribeInput.text.toString().isEmpty()){
etDescribeInput.setText(reasonDetail)
etDescribeInput.setSelection(reasonDetail.length)
etDescribeInput.setText(text)
etDescribeInput.setSelection(text.length)
}else{
val startStr = etDescribeInput.text.toString().substring(0,etDescribeInput.selectionStart)
val endStr = etDescribeInput.text.toString().substring(etDescribeInput.selectionEnd,etDescribeInput.text.toString().length)
etDescribeInput.setText(startStr+reasonDetail+endStr)
etDescribeInput.setSelection(startStr.length+reasonDetail.length)
etDescribeInput.setText(startStr+text+endStr)
etDescribeInput.setSelection(startStr.length+text.length)
}
}