Updated the processAudioLoop to mke sure that the buffer was always flushed after an output stream so we didn't miss any characters. Also made many modifications to the python script running on the Pico to ensure that we get dual inputs and neater outputs now.

This commit is contained in:
2026-02-09 14:48:55 +11:00
parent 75b63f91ea
commit f96189a509
2 changed files with 25 additions and 3 deletions

View File

@@ -21,8 +21,8 @@ android {
applicationId = "net.mmanningau.speechtokeyboard" applicationId = "net.mmanningau.speechtokeyboard"
minSdk = 28 minSdk = 28
targetSdk = 36 targetSdk = 36
versionCode = 14 versionCode = 15
versionName = "1.1.2" versionName = "1.1.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@@ -101,7 +101,7 @@ class TestModelActivity : AppCompatActivity() {
val silenceRule = EndpointRule( val silenceRule = EndpointRule(
mustContainNonSilence = false, mustContainNonSilence = false,
minTrailingSilence = 2.4f, minTrailingSilence = 1.2f,
minUtteranceLength = 0.0f minUtteranceLength = 0.0f
) )
@@ -214,6 +214,7 @@ class TestModelActivity : AppCompatActivity() {
val cleanText = text.lowercase() val cleanText = text.lowercase()
if (isEndpoint) { if (isEndpoint) {
// CASE A: Natural Pause (Sentence Finished)
val punctuatedText = punctuator?.addPunctuation(cleanText) ?: cleanText val punctuatedText = punctuator?.addPunctuation(cleanText) ?: cleanText
runOnUiThread { runOnUiThread {
@@ -223,6 +224,8 @@ class TestModelActivity : AppCompatActivity() {
} }
localRec.reset(localStream) localRec.reset(localStream)
} else { } else {
// CASE B: Partial (Still talking)
// Update screen ONLY, do not send to Pico yet
runOnUiThread { runOnUiThread {
outputText.text = "$committedText $cleanText" outputText.text = "$committedText $cleanText"
} }
@@ -230,6 +233,25 @@ class TestModelActivity : AppCompatActivity() {
} }
} }
} }
// --- NEW: THE FLUSH BLOCK ---
// This runs when you hit "Stop". It grabs the last unspoken words.
val finalTail = localRec.getResult(localStream).text
if (finalTail.isNotEmpty()) {
val cleanTail = finalTail.lowercase()
val punctuatedTail = punctuator?.addPunctuation(cleanTail) ?: cleanTail
runOnUiThread {
committedText += "$punctuatedTail "
outputText.text = committedText
// FORCE SEND the remaining text
sendToPico("$punctuatedTail ")
}
// Reset for next time
localRec.reset(localStream)
}
// -----------------------------
record.stop() record.stop()
record.release() record.release()
} }