Voice input tells you if it can't record due to microphone permissions

This commit is contained in:
James Babcock committed 2026-09-12 00:47:27 -07:00
1 parent 476bb281a1
commit dfde776016
4 files changed
+75 -9

No files matched your search

+51 -3
View File
@@ -11,7 +11,19 @@ import { toUint8Array } from "../util/array-util";
declare const com: any;
export type VoiceControlState = {
/** One-line state of the capture: progress, "Listening...", or an error. */
status: string;
/**
* Whether audio is actually being captured and transcribed right now. False
* while the mic is starting, while the phone is showing the permission
* prompt, and after an error, so a dialog must not claim to be listening.
*/
listening: boolean;
/**
* Longer guidance to show in place of the (still empty) transcript, e.g.
* what the user has to do on the phone. Empty when there is nothing to say.
*/
detail: string;
};
export type VoiceProviderKind = "onboard" | "elevenlabs" | "whisper" | "soniox";
@@ -88,6 +100,8 @@ export class FaceclawVoiceControlBridge {
private controller: any | null = null;
private listenerProxy: any | null = null;
private status = "Voice control stopped.";
private listening = false;
private detail = "";
private started = false;
// The mic is a single shared stream; these are the reasons it is running.
// The first holder starts capture (choosing the provider); the mic stops
@@ -118,7 +132,7 @@ export class FaceclawVoiceControlBridge {
onStatus(listener: (state: VoiceControlState) => void): () => void {
this.statusListeners.add(listener);
listener({ status: this.status });
listener(this.state());
return () => this.statusListeners.delete(listener);
}
@@ -142,6 +156,28 @@ export class FaceclawVoiceControlBridge {
return () => this.speechPauseListeners.delete(listener);
}
/**
* The capture is blocked on the phone's system microphone-permission
* prompt. Reported by the controller before it asks Android, so the dialog
* on the glasses can send the user to the phone instead of claiming to
* listen; the next status (from the capture start, or reportPermissionDenied)
* replaces it.
*/
reportPermissionPrompt(): void {
this.setStatus(
"Waiting for microphone permission...",
"Allow microphone access in the prompt on your phone.",
);
}
/** The user declined the microphone permission (or the prompt could not be shown). */
reportPermissionDenied(): void {
this.setStatus(
"Microphone access denied.",
"Enable the microphone for Faceclaw in the phone's app settings, then try again.",
);
}
/** Begin push-to-talk capture (momentary; released with stopPushToTalk). */
startPushToTalk(options: PushToTalkOptions): void {
this.acquireCapture("ptt", options);
@@ -262,6 +298,9 @@ export class FaceclawVoiceControlBridge {
}
this.speechPause.reset();
// Replaces whatever the last capture left behind ("Listening...", an
// error, the permission prompt) until the controller reports progress.
this.setStatus("Starting microphone...");
// A previous push-to-talk commit may still be awaiting its final result.
this.cloudClient?.stop();
const cloudClient = this.createCloudClient(options);
@@ -492,12 +531,21 @@ export class FaceclawVoiceControlBridge {
}
}
private setStatus(status: string): void {
private setStatus(status: string, detail = ""): void {
this.status = status;
this.detail = detail;
// Every "audio is flowing" report — from the Java controller and from the
// cloud providers — is phrased "Listening..." / "Listening (X)...".
this.listening = status.startsWith("Listening");
const state = this.state();
for (const listener of this.statusListeners) {
listener({ status });
listener(state);
}
}
private state(): VoiceControlState {
return { status: this.status, listening: this.listening, detail: this.detail };
}
}
function toJavaFloats(values: Float32Array): any {