fixed a bug

This commit is contained in:
2026-08-26 10:46:09 +08:00
parent 1b6090e44c
commit a6297e2f9f
4 changed files with 102 additions and 2 deletions

View File

@@ -100,6 +100,7 @@ class MainActivity : Activity() {
private var mediaRecorder: MediaRecorder? = null
private var recordingFile: File? = null
private val dubSegments = mutableMapOf<Int, File>()
private val latestScores = mutableMapOf<Int, ImitationAssessmentResult>()
private var mergedDubFile: File? = null
private var dubbingStatusText: TextView? = null
private var dubbingPlayback = false
@@ -1207,6 +1208,25 @@ class MainActivity : Activity() {
"{\"sentence_index\":$it}"
}
text("segments", payload)
val scores = dubSegments.keys.sorted().map { index ->
latestScores[index]
}.filterNotNull().joinToString(",", "[", "]") { score ->
buildString {
append("{\"sentence_index\":")
append(score.sentenceIndex)
if (score.overallScore != null) {
append(",\"overall_score\":")
append(score.overallScore)
}
score.recognizedText?.let { text ->
append(",\"recognized_text\":\"")
append(text.replace("\\", "\\\\").replace("\"", "\\\""))
append("\"")
}
append("}")
}
}
text("scores", scores)
dubSegments.toSortedMap().forEach { (index, file) ->
output.writeBytes("--$boundary\r\n")
output.writeBytes(
@@ -1260,6 +1280,9 @@ class MainActivity : Activity() {
if (::testStatusText.isInitialized) {
applyAssessmentResult(result)
}
sentence.index.let { index ->
latestScores[index] = result
}
}
override fun onError(error: Throwable) {