From f96189a509102269b13dda8a47d84733e656f1c6 Mon Sep 17 00:00:00 2001 From: mmanningau Date: Mon, 9 Feb 2026 14:48:55 +1100 Subject: [PATCH] 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. --- app/build.gradle.kts | 4 ++-- .../speechtokeyboard/TestModelActivity.kt | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 148cf66..10be7b3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,8 +21,8 @@ android { applicationId = "net.mmanningau.speechtokeyboard" minSdk = 28 targetSdk = 36 - versionCode = 14 - versionName = "1.1.2" + versionCode = 15 + versionName = "1.1.3" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt index 15b7e6c..e6d4602 100644 --- a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt +++ b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt @@ -101,7 +101,7 @@ class TestModelActivity : AppCompatActivity() { val silenceRule = EndpointRule( mustContainNonSilence = false, - minTrailingSilence = 2.4f, + minTrailingSilence = 1.2f, minUtteranceLength = 0.0f ) @@ -214,6 +214,7 @@ class TestModelActivity : AppCompatActivity() { val cleanText = text.lowercase() if (isEndpoint) { + // CASE A: Natural Pause (Sentence Finished) val punctuatedText = punctuator?.addPunctuation(cleanText) ?: cleanText runOnUiThread { @@ -223,6 +224,8 @@ class TestModelActivity : AppCompatActivity() { } localRec.reset(localStream) } else { + // CASE B: Partial (Still talking) + // Update screen ONLY, do not send to Pico yet runOnUiThread { 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.release() }