Skip to content

Commit

Permalink
Fix crash for Android (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Sep 13, 2023
1 parent 033e936 commit 12d0148
Showing 1 changed file with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 12d0148

Please sign in to comment.