forked from Blendman974/faceclaw
Port Transcribe to new UI; remove legacy dashboard
This commit is contained in:
1 parent
56d0f8c351
commit
d0c30f9ca9
21 files changed
+392
-1291
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { Utils } from "@nativescript/core";
|
||||
import { ImageSource, Utils } from "@nativescript/core";
|
||||
import * as frameTimings from "./frame-timings";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
const PREVIEW_BRIGHTEN_GAMMA = 0.7;
|
||||
|
||||
export type CommunicatorPhase =
|
||||
| "disconnected"
|
||||
| "connecting"
|
||||
@@ -338,6 +340,19 @@ export class FaceclawCommunicatorBridge {
|
||||
});
|
||||
}
|
||||
|
||||
/** Phone-UI preview of the current composited screen, or null if none yet. */
|
||||
getCompositePreview(): ImageSource | null {
|
||||
if (!global.isAndroid) return null;
|
||||
const bitmap = this.communicator.getCompositePreviewBitmap(PREVIEW_BRIGHTEN_GAMMA);
|
||||
return bitmap ? new ImageSource(bitmap) : null;
|
||||
}
|
||||
|
||||
/** Save the current composite as a raw 4bpp screenshot; returns the path (empty if none). */
|
||||
saveRawCompositeScreenshot(): string {
|
||||
if (!global.isAndroid) return "";
|
||||
return String(this.communicator.saveRawCompositeScreenshot());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or reconfigure a compositor surface. Geometry changes take effect
|
||||
* when the next frame is submitted.
|
||||
|
||||
@@ -73,6 +73,30 @@ export function listDirectory(path: string): DirectoryEntry[] | null {
|
||||
}
|
||||
}
|
||||
|
||||
/** Write UTF-8 text to a file in the public Downloads directory; returns its path or null. */
|
||||
export function writeTextToDownloads(filename: string, text: string): string | null {
|
||||
try {
|
||||
const downloads = android.os.Environment.getExternalStoragePublicDirectory(
|
||||
android.os.Environment.DIRECTORY_DOWNLOADS,
|
||||
);
|
||||
downloads.mkdirs();
|
||||
const file = new java.io.File(downloads, filename);
|
||||
const bytes = new java.lang.String(text).getBytes("UTF-8");
|
||||
// FileOutputStream rather than Files.write to avoid NativeScript varargs /
|
||||
// overload resolution pitfalls.
|
||||
const stream = new java.io.FileOutputStream(file);
|
||||
try {
|
||||
stream.write(bytes);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
return String(file.getAbsolutePath());
|
||||
} catch (error) {
|
||||
console.warn(`writeTextToDownloads failed for ${filename}: ${error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read a UTF-8 text file (size-capped); null when unreadable or too large. */
|
||||
export function readTextFile(path: string): string | null {
|
||||
try {
|
||||
|
||||
@@ -27,6 +27,9 @@ export type PushToTalkOptions = {
|
||||
saveRecording: boolean;
|
||||
};
|
||||
|
||||
/** Who currently wants the mic running. */
|
||||
type CaptureHolder = "ptt" | "continuous";
|
||||
|
||||
export class FaceclawVoiceControlBridge {
|
||||
private readonly statusListeners = new Set<(state: VoiceControlState) => void>();
|
||||
private readonly wakeWordListeners = new Set<(keyword: string) => void>();
|
||||
@@ -35,6 +38,11 @@ export class FaceclawVoiceControlBridge {
|
||||
private listenerProxy: any | null = null;
|
||||
private status = "Voice control stopped.";
|
||||
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
|
||||
// when the last one releases. Transcript events broadcast to every
|
||||
// listener, so push-to-talk and the Transcribe window both receive text.
|
||||
private readonly captureHolders = new Set<CaptureHolder>();
|
||||
// Non-null while a cloud provider owns the transcript; Java only decodes PCM.
|
||||
private cloudClient: ElevenLabsSttClient | null = null;
|
||||
|
||||
@@ -54,10 +62,34 @@ export class FaceclawVoiceControlBridge {
|
||||
return () => this.transcriptListeners.delete(listener);
|
||||
}
|
||||
|
||||
/** Begin push-to-talk capture with the selected provider. */
|
||||
/** Begin push-to-talk capture (momentary; released with stopPushToTalk). */
|
||||
startPushToTalk(options: PushToTalkOptions): void {
|
||||
this.acquireCapture("ptt", options);
|
||||
}
|
||||
|
||||
/** End push-to-talk: for cloud, commit for a final result if it was the last holder. */
|
||||
stopPushToTalk(): void {
|
||||
this.releaseCapture("ptt", true);
|
||||
}
|
||||
|
||||
/** Begin continuous capture (Transcribe): the mic stays on until released. */
|
||||
startContinuousCapture(options: PushToTalkOptions): void {
|
||||
this.acquireCapture("continuous", options);
|
||||
}
|
||||
|
||||
stopContinuousCapture(): void {
|
||||
this.releaseCapture("continuous", false);
|
||||
}
|
||||
|
||||
private acquireCapture(holder: CaptureHolder, options: PushToTalkOptions): void {
|
||||
if (!global.isAndroid) return;
|
||||
if (this.started) this.stop();
|
||||
const wasIdle = this.captureHolders.size === 0;
|
||||
this.captureHolders.add(holder);
|
||||
if (!wasIdle) {
|
||||
// Mic already running; the new holder just shares the existing stream
|
||||
// (transcripts are already broadcast to its listeners).
|
||||
return;
|
||||
}
|
||||
this.ensureController();
|
||||
this.controller?.setCommunicator(options.communicator);
|
||||
this.controller?.setSaveRecordings(options.saveRecording);
|
||||
@@ -83,21 +115,34 @@ export class FaceclawVoiceControlBridge {
|
||||
this.controller?.start("onboard");
|
||||
}
|
||||
|
||||
/** End push-to-talk: stop the mic and, for cloud, commit for a final result. */
|
||||
stopPushToTalk(): void {
|
||||
private releaseCapture(holder: CaptureHolder, commit: boolean): void {
|
||||
if (!this.captureHolders.delete(holder)) {
|
||||
// Never held; still finish a dangling cloud commit if one is pending.
|
||||
if (commit) this.cloudClient?.finish();
|
||||
return;
|
||||
}
|
||||
if (this.captureHolders.size > 0) {
|
||||
// Another holder still wants the mic; keep it running.
|
||||
return;
|
||||
}
|
||||
if (!this.started) {
|
||||
this.cloudClient?.finish();
|
||||
return;
|
||||
}
|
||||
// Order matters for cloud: stopping the Java controller flushes any final
|
||||
// decode/PCM; then commit so ElevenLabs finalizes the transcript. The
|
||||
// socket is closed once the committed transcript arrives, or on stop().
|
||||
// decode/PCM; then commit so ElevenLabs finalizes the transcript.
|
||||
this.controller?.stop();
|
||||
this.started = false;
|
||||
this.cloudClient?.finish();
|
||||
if (commit) {
|
||||
this.cloudClient?.finish();
|
||||
} else {
|
||||
this.cloudClient?.stop();
|
||||
this.cloudClient = null;
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
this.captureHolders.clear();
|
||||
if (global.isAndroid) {
|
||||
this.controller?.stop();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user