Fangjun Kuang пре 1 година
родитељ
комит
12d01487a3
1 измењених фајлова са 21 додато и 16 уклоњено
  1. 21 16
      android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn/MainActivity.kt

+ 21 - 16
android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn/MainActivity.kt

@@ -92,12 +92,13 @@ class MainActivity : AppCompatActivity() {
             audioRecord!!.startRecording()
             recordButton.setText(R.string.stop)
             isRecording = true
-            model.reset(true)
             textView.text = ""
             lastText = ""
             idx = 0
 
             recordingThread = thread(true) {
+                model.reset(true)
+
                 processSamples()
             }
             Log.i(TAG, "Started recording")
@@ -126,25 +127,29 @@ class MainActivity : AppCompatActivity() {
                 while (model.isReady()) {
                     model.decode()
                 }
+                val isEndpoint = model.isEndpoint()
+                val text = model.text
+                var textToDisplay = lastText
+
+                if (text.isNotBlank()) {
+                    if (lastText.isBlank()) {
+                        textToDisplay = "${idx}: ${text}"
+                    } else {
+                        textToDisplay = "${lastText}\n${idx}: ${text}"
+                    }
+                }
 
-                runOnUiThread {
-                    val isEndpoint = model.isEndpoint()
-                    val text = model.text
+                if (isEndpoint) {
+                    model.reset()
                     if (text.isNotBlank()) {
-                        if (lastText.isBlank()) {
-                            textView.text = "${idx}: ${text}"
-                        } else {
-                            textView.text = "${lastText}\n${idx}: ${text}"
-                        }
+                        lastText = "${lastText}\n${idx}: ${text}"
+                        textToDisplay = lastText
+                        idx += 1
                     }
+                }
 
-                    if (isEndpoint) {
-                        model.reset()
-                        if (text.isNotBlank()) {
-                            lastText = "${lastText}\n${idx}: ${text}"
-                            idx += 1
-                        }
-                    }
+                runOnUiThread {
+                    textView.text = textToDisplay
                 }
             }
         }