Wait for final results from Whisper before completing

<details>
<summary>Prompts Used</summary>
User: This checkout corresponds to https://github.com/jimrandomh/faceclaw/pull/27. Review this branch.

GPT-6 Astra:
> Found one issue:
>
> - **[P2] Wait for Whisper’s final result before completing dictation** — [FaceclawVoiceController.java:729](/Users/jbabcock/repositories/g2/faceclaw/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java:729). Skipping partial decodes leaves short utterances without text until release, but the dialog still finalizes after its existing timeout. If decoding exceeds roughly 2.7 seconds (native stop’s 1.5-second wait plus the dialog’s 1.2-second timeout), auto-send can abandon a short command or send an incomplete longer one. Continue can append the late editing instruction literally instead of refining the message. I reproduced these outcomes with delayed transcript events. These flows should await recognition completion.
>
> Validation: TypeScript and a clean Android build passed. All 21 test failures also occur on `main`. Actual Whisper latency was not tested on hardware.

<hr>

User: Thanks, let's fix that issue.

GPT-6 Astra:
> Fixed. Dictation now waits for native recognition to finish before fallback timers run. Auto-send, Continue, and AI Chat preserve delayed Whisper results; cancellation ignores late transcripts.
>
> TypeScript and Android builds pass. All 11 new regression tests pass. The full suite still has the same 21 pre-existing failures.
</details>
This commit is contained in:
James Babcock committed 2026-09-17 22:12:33 -07:00
1 parent 91890a25ac
commit 25c398d60f
11 files changed
+385 -28

No files matched your search

@@ -266,20 +266,26 @@ public class FaceclawVoiceController {
}
public void start(String requestedMode) {
start(requestedMode, 0);
}
public void start(String requestedMode, int captureId) {
synchronized (lock) {
if (started) {
emitStatus("Voice control is already listening.");
emitStopped(captureId);
return;
}
if (!usePhoneMic && (communicator == null || !communicator.isSessionReady())) {
emitStatus("Voice control needs an active G2 connection.");
emitStopped(captureId);
return;
}
mode = parseMode(requestedMode);
activePhoneMic = usePhoneMic;
started = true;
audioStarted = false;
workerThread = new Thread(this::runLoop, "FaceclawVoiceController");
workerThread = new Thread(() -> runLoop(captureId), "FaceclawVoiceController");
workerThread.start();
}
}
@@ -350,7 +356,7 @@ public class FaceclawVoiceController {
return VoiceInputMode.ONBOARD;
}
private void runLoop() {
private void runLoop(int captureId) {
try {
deleteLegacyKwsFiles();
VoiceInputMode currentMode = mode;
@@ -432,6 +438,7 @@ public class FaceclawVoiceController {
audioStarted = false;
workerThread = null;
}
emitStopped(captureId);
}
}
@@ -1014,6 +1021,13 @@ public class FaceclawVoiceController {
mainHandler.post(currentListener::onSpeechEnd);
}
private void emitStopped(int captureId) {
FaceclawVoiceControllerListener currentListener = listener;
if (currentListener != null) {
mainHandler.post(() -> currentListener.onStopped(captureId));
}
}
/**
* Decides when a hands-free utterance is over, so "Hey Even" capture can
* stop without a button release.
@@ -10,6 +10,9 @@ public interface FaceclawVoiceControllerListener {
*/
void onTranscript(String text, boolean isFinal);
/** Capture has finished, after the final transcript or a startup/recognition error. */
void onStopped(int captureId);
/**
* Decoded microphone audio: 16 kHz mono signed 16-bit little-endian PCM.
* Emitted in every mode so raw-PCM consumers (levels, recording, captions)