Compare commits

..
Author SHA1 Message Date
Blendman974 a80d6697b5 Allow choosing an OpenAI transcription model available to the project
Secret scan / gitleaks (pull_request) Canceled after 0s
Tests / test (pull_request) Canceled after 0s
Tests / test-kotlin (pull_request) Canceled after 0s
Tests / stats-server (pull_request) Canceled after 0s
Tests / evenhub-extensions (pull_request) Canceled after 0s
2026-11-08 00:35:51 +01:00
Blendman974 0b9e4cb367 feat: select languages for cloud and local Whisper transcription
Secret scan / gitleaks (pull_request) Canceled after 0s
Tests / test (pull_request) Canceled after 0s
Tests / test-kotlin (pull_request) Canceled after 0s
Tests / stats-server (pull_request) Canceled after 0s
Tests / evenhub-extensions (pull_request) Canceled after 0s
2026-11-06 04:22:48 +01:00
34 changed files with 504 additions and 620 deletions

No files matched your search

@@ -25,18 +25,21 @@ internal object AndroidSpeechEngines {
private const val FEATURE_DIM = 80
/** Sherpa-onnx configuration for the on-device model files in [modelDir]. */
fun recognizerConfig(modelDir: File, kind: VoiceModelKind): OfflineRecognizerConfig {
fun recognizerConfig(
modelDir: File, kind: VoiceModelKind,
whisper: WhisperModelFiles = WhisperModelFiles.forLanguage(null),
): OfflineRecognizerConfig {
val modelConfig = OfflineModelConfig.builder()
.setNumThreads(1)
if (kind == VoiceModelKind.WHISPER) {
modelConfig
.setWhisper(OfflineWhisperModelConfig.builder()
.setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath)
.setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath)
.setLanguage("en")
.setEncoder(File(modelDir, whisper.encoder).absolutePath)
.setDecoder(File(modelDir, whisper.decoder).absolutePath)
.setLanguage(whisper.language)
.setTask("transcribe")
.build())
.setTokens(File(modelDir, "base.en-tokens.txt").absolutePath)
.setTokens(File(modelDir, whisper.tokens).absolutePath)
} else {
modelConfig
.setMoonshine(OfflineMoonshineModelConfig.builder()
@@ -1,47 +0,0 @@
package com.faceclaw.app
import android.content.Context
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.AtomicFile
import java.io.File
import java.security.KeyStore
import javax.crypto.Cipher
import javax.crypto.KeyGenerator
import javax.crypto.SecretKey
import javax.crypto.spec.GCMParameterSpec
/** This credential cannot be restored onto a device lacking its Keystore key. */
object FaceclawHealthExportSecret {
private const val ALIAS = "faceclaw.health.export"
private fun file(context: Context) = AtomicFile(File(context.noBackupFilesDir, "health-export-key"))
private fun key(): SecretKey {
val store = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
(store.getKey(ALIAS, null) as? SecretKey)?.let { return it }
return KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore").apply {
init(KeyGenParameterSpec.Builder(ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE).build())
}.generateKey()
}
@JvmStatic @Synchronized fun read(context: Context): String {
val held = file(context)
if (!held.baseFile.exists()) return ""
return try {
val bytes = held.readFully()
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.DECRYPT_MODE, key(), GCMParameterSpec(128, bytes.copyOfRange(0, 12)))
String(cipher.doFinal(bytes.copyOfRange(12, bytes.size)), Charsets.UTF_8)
} catch (_: Exception) { "" } // Require re-entry after key loss; never log the credential.
}
@JvmStatic @Synchronized fun write(context: Context, value: String) {
val held = file(context)
if (value.isEmpty()) { held.delete(); return }
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, key())
val bytes = cipher.iv + cipher.doFinal(value.toByteArray(Charsets.UTF_8))
val stream = held.startWrite()
try { stream.write(bytes); held.finishWrite(stream) }
catch (error: Exception) { held.failWrite(stream); throw error }
}
}
@@ -32,17 +32,6 @@ class FaceclawVoiceController(context: Context) {
"decoder_model_merged.ort",
"tokens.txt"
)
// Second on-device model: sherpa-onnx's offline Whisper backend (base.en,
// int8-quantized -- see the model-choice note in asr-model.ts). Directory
// shared with the TS-side download flow, same convention as ASR_MODEL_DIR.
// Whisper re-encodes the whole buffer on every call, so the shared session
// skips live partials for it; see VoiceCaptureSession.processRecognizer.
private const val ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8"
private val ASR_WHISPER_MODEL_FILES = arrayOf(
"base.en-encoder.int8.onnx",
"base.en-decoder.int8.onnx",
"base.en-tokens.txt"
)
// 50 ms chunks match the G2 packet cadence the rest of the pipeline
// (endpointing, transcript pacing) is tuned for.
private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20
@@ -84,6 +73,7 @@ class FaceclawVoiceController(context: Context) {
private val mainHandler = Handler(Looper.getMainLooper())
@Volatile
private var communicator: FaceclawBleCommunicator? = null
private var whisperModel = WhisperModelFiles.forLanguage(null)
private val host = object : VoiceCaptureHost {
override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } }
@@ -122,7 +112,7 @@ class FaceclawVoiceController(context: Context) {
override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber {
val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing")
return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind))
return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind, whisperModel))
}
override fun speakerEmbedder(modelPath: String): SpeakerEmbedder {
@@ -168,6 +158,11 @@ class FaceclawVoiceController(context: Context) {
session.setOnboardModelKind(kind)
}
/** Language for the next on-device Whisper capture; empty enables auto-detection. */
fun setOnboardLanguage(language: String?) {
whisperModel = WhisperModelFiles.forLanguage(language)
}
/**
* When true, watch the decoded PCM and fire {@code onSpeechEnd} once the
* speaker stops. Used by hands-free ("Hey Even") capture, which has no
@@ -263,8 +258,8 @@ class FaceclawVoiceController(context: Context) {
*/
private fun findAsrModelDir(kind: VoiceModelKind): File? {
val whisper = kind == VoiceModelKind.WHISPER
val dirName = if (whisper) ASR_WHISPER_MODEL_DIR else ASR_MODEL_DIR
val fileNames = if (whisper) ASR_WHISPER_MODEL_FILES else ASR_MODEL_FILES
val dirName = if (whisper) whisperModel.dirName else ASR_MODEL_DIR
val fileNames = if (whisper) whisperModel.files else ASR_MODEL_FILES.toList()
val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName)
for (fileName in fileNames) {
val file = File(modelDir, fileName)
-2
View File
@@ -1,4 +1,3 @@
import { startHealthExport } from "./health/health-export"
import { Application } from '@nativescript/core'
import { registerShareIntentHandler } from './native/share-intents'
import { installNativeUserAgent } from './util/http'
@@ -19,7 +18,6 @@ Application.on(Application.launchEvent, () => {
// they are closed would be lost if the process restarted first, so this keeps
// them reaching disk regardless. No-op when there is nothing new.
startLiveHealthSync()
startHealthExport()
// Collect from the ring on a wall-clock cadence (:01 and :31). Without this
// nothing drives a pull on a timer at all - only onRingReady() on reconnect -
+5 -4
View File
@@ -78,7 +78,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, openAiTranscriptionModelSetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, getVoiceTranscriptionLanguage, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import {
getInstalledEvenHubAppById,
@@ -483,6 +483,7 @@ class DashboardController {
this.applyVerticalPositionIfChanged();
this.applyAppLayoutsIfChanged();
this.syncAssistantBridgeIfChanged();
this.retargetContinuousCapture();
this.syncLockScreenSettingIfChanged();
// A Preview color or scaling change should show on the mirror at once,
// not at the next composited frame (cheap: floor-limited, dedup'd on
@@ -2197,16 +2198,16 @@ class DashboardController {
private voiceCaptureOptions(communicator: FaceclawCommunicatorBridge | null) {
// A window that needs its own provider and language sets them for every
// capture while it is open, so push-to-talk still shares its stream.
// Otherwise only Whisper server is told a language (its own setting).
// Otherwise use the shared transcription-language preference.
const choice = this.transcriptionChoice();
const provider = choice?.provider ?? voiceProviderSetting.get();
return {
communicator: communicator?.getNativeCommunicator() ?? null,
usePhoneMic: communicator === null,
provider,
language: choice ? choice.language : provider === "whisper-server" ? whisperServerLanguageSetting.get() : "",
language: choice ? choice.language : getVoiceTranscriptionLanguage(provider),
elevenLabsApiKey: elevenLabsApiKeySetting.get(),
openAiApiKey: openAiApiKeySetting.get(),
openAiApiKey: openAiApiKeySetting.get(), openAiTranscriptionModel: openAiTranscriptionModelSetting.get(),
sonioxApiKey: sonioxApiKeySetting.get(),
whisperServerUrl: whisperServerUrlSetting.get(),
whisperServerModel: whisperServerModelSetting.get(),
+5 -5
View File
@@ -52,7 +52,7 @@ import { mirrorToPanelFraction, phonePreviewCrop } from './phone-preview-crop'
import { onAnySettingChanged,
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
openAiApiKeySetting, openAiTranscriptionModelSetting, sonioxApiKeySetting, whisperServerApiKeySetting, getVoiceTranscriptionLanguage,
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting } from '../ui/dashboard-settings'
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
import type { PhoneGesture } from '../phone-ui/phone-gestures'
@@ -416,6 +416,7 @@ export class IosPreviewController {
const phone = readPhoneBatteryState()
this.logBluetooth(`Phone battery ${phone.battery ?? "unknown"}% charging=${phone.charging}`)
this.offSettings = onAnySettingChanged(() => {
this.syncContinuousCapture()
this.syncLockSetting()
this.pushBrightness()
this.relayout()
@@ -1198,14 +1199,13 @@ export class IosPreviewController {
/**
* The transcription provider setting and the keys the cloud ones need. A
* window that needs its own provider and language (Translate) sets them for
* every capture while it is open; otherwise only Whisper server is told a
* language (its own setting).
* every capture while it is open; otherwise use the shared language preference.
*/
private voiceProvider(): VoiceProviderSelection {
const choice = [...this.continuousClients.values()].find(options => options.transcription)?.transcription
const provider = choice?.provider ?? voiceProviderSetting.get()
return { provider, language: choice ? choice.language : provider === 'whisper-server' ? whisperServerLanguageSetting.get() : '',
elevenLabsApiKey: elevenLabsApiKeySetting.get(), openAiApiKey: openAiApiKeySetting.get(), sonioxApiKey: sonioxApiKeySetting.get(),
return { provider, language: choice ? choice.language : getVoiceTranscriptionLanguage(provider),
elevenLabsApiKey: elevenLabsApiKeySetting.get(), openAiApiKey: openAiApiKeySetting.get(), openAiTranscriptionModel: openAiTranscriptionModelSetting.get(), sonioxApiKey: sonioxApiKeySetting.get(),
whisperServerUrl: whisperServerUrlSetting.get(), whisperServerModel: whisperServerModelSetting.get(),
whisperServerApiKey: whisperServerApiKeySetting.get() }
}
-72
View File
@@ -1,72 +0,0 @@
import { healthStore } from "./health-store-files";
import { isFixtureData } from "./health-seed";
import { healthExportEnabledSetting, healthExportUrlSetting, healthExportKeySetting } from "../ui/dashboard-settings";
import { getStringSetting, setStringSetting } from "../native/settings-store";
import { fetchTextWithUserAgent } from "../util/http";
let running = false;
let started = false;
let status = "Not synchronized";
export function healthExportStatus(): string { return status; }
/** One bounded batch, with durable acknowledgement and no overlapping requests. */
export async function syncHealthExport(): Promise<void> {
if (running) return;
running = true;
try {
if (!healthExportEnabledSetting.get()) { status = "Export disabled"; return; }
if (isFixtureData()) { status = "Sample data is never exported"; return; }
const url = healthExportUrlSetting.get();
const key = healthExportKeySetting.get();
if (!url || healthExportUrlSetting.validationError() || !key) {
status = "Configure an HTTPS endpoint and API key";
return;
}
const generation = getStringSetting("health.export.generation", "0");
let held: { url?: string; generation?: string; offsets?: Record<string, number> } = {};
try { held = JSON.parse(getStringSetting("health.export.cursor", "{}")) ?? {}; } catch { /* First sync. */ }
const offsets = held.url === url && held.generation === generation ? held.offsets ?? {} : {};
let limit = 200;
let batch = healthStore().exportBatch(offsets, limit);
let body = JSON.stringify({ version: 1, samples: batch.samples, sleep: batch.sleep });
// Normalized records contain only ASCII keys, numbers and metric names.
// Large sleep histories must fit the server body limit as well as its record limit.
while (body.length > 240_000 && limit > 1) {
limit = Math.max(1, Math.floor(limit / 2));
batch = healthStore().exportBatch(offsets, limit);
body = JSON.stringify({ version: 1, samples: batch.samples, sleep: batch.sleep });
}
if (body.length > 240_000) { status = "A health record exceeds the export size limit"; return; }
if (!batch.scanned) { status = "Up to date"; return; }
if (batch.samples.length || batch.sleep.length) {
status = "Sending health data";
const response = await fetchTextWithUserAgent(url, {
method: "POST", headers: { "Authorization": `Bearer ${key}`, "Content-Type": "application/json" },
body,
timeoutMs: 30_000, dontFollowRedirects: true,
});
if (response.status !== 200) {
status = response.status === 401 || response.status === 403
? "API key refused; check configuration" : `Server refused batch (HTTP ${response.status}); will retry`;
return;
}
const ack = await response.json<{ accepted?: boolean }>();
if (ack.accepted !== true) { status = "Invalid server acknowledgement; will retry"; return; }
}
// An edit during the request must not acknowledge data on a different destination.
if (url !== healthExportUrlSetting.get() || generation !== getStringSetting("health.export.generation", "0")) return;
setStringSetting("health.export.cursor", JSON.stringify({ url, generation, offsets: batch.cursor }));
status = "Batch synchronized; remaining history follows automatically";
} catch {
// Errors may include request headers or data: never log or display them.
status = "Synchronization failed; will retry automatically";
} finally { running = false; }
}
/** Android app process only; no extra BLE pulls, wake locks, or background service. */
export function startHealthExport(): void {
if (started) return;
started = true;
setTimeout(() => { void syncHealthExport(); }, 10_000);
setInterval(() => { void syncHealthExport(); }, 60_000);
}
-19
View File
@@ -48,7 +48,6 @@
import {
HOUR_MS,
HEART_RATE_MEASUREMENT_SPAN_MS,
TEN_MINUTES_MS,
type HealthSample,
type SleepSession,
@@ -66,8 +65,6 @@ export type WireHourlyRecord = {
* zero bytes instead.
*/
anchorMs: number | null;
/** Latest reading, only from live pages; raw journal replay does not guess its clock. */
latest?: { timestampSeconds: number; value: number; receivedAtMs: number; clockOffsetMs: number };
groups: readonly { hourIndex: number; avg: number; max: number; min: number }[];
};
@@ -149,22 +146,6 @@ export function convertRecords(records: readonly WireRecord[]): ConversionResult
* guesses. Dropping loses a page; guessing corrupts the history silently.
*/
function convertHourly(record: WireHourlyRecord, result: ConversionResult): void {
if (record.metric === "heartRate" && record.latest) {
const { timestampSeconds, value, receivedAtMs, clockOffsetMs } = record.latest;
const startMs = timestampSeconds * 1000 - clockOffsetMs;
// Invert the existing handshake clock shift, never replace measurement time
// with reception time or snap it onto an invented ten-minute bucket.
// Older pages can mix clock domains: only accept a recent live reading.
if (Number.isSafeInteger(timestampSeconds) && Number.isSafeInteger(receivedAtMs)
&& Number.isFinite(clockOffsetMs) && Number.isInteger(value) && value > 0 && value <= 300
&& startMs >= 946684800000 && startMs <= receivedAtMs + 120_000
&& receivedAtMs - startMs <= 20 * 60_000) {
result.samples.push({ metric: "heartRate", startMs, spanMs: HEART_RATE_MEASUREMENT_SPAN_MS,
min: value, max: value, avg: value, total: value });
} else {
result.skipped.push({ what: "latest heart rate", why: "invalid, stale or unresolved measurement timestamp/value" });
}
}
if (record.anchorMs === null) {
result.skipped.push({
what: `${record.metric} page, ${record.groups.length} groups`,
+14 -17
View File
@@ -240,7 +240,7 @@ function accumulateStepBuckets(
return merged;
}
function toWire(record: any, includeLatest: boolean): WireRecord | null {
function toWire(record: any): WireRecord | null {
const cmdHi = Number(record.cmdHi);
const metric = HOURLY_METRIC[cmdHi];
@@ -256,12 +256,7 @@ function toWire(record: any, includeLatest: boolean): WireRecord | null {
min: Number(group.min),
});
}
const receivedAtMs = Number(record.receivedAtMs);
const latest = includeLatest && metric === "heartRate" && Number(record.tagRaw) > 0 ? {
timestampSeconds: Number(record.tagRaw), value: Number(record.current), receivedAtMs,
clockOffsetMs: ringClockOffsetMs(receivedAtMs),
} : undefined;
return { kind: "hourly", metric, anchorMs: anchorToMs(Number(record.anchorUnixSeconds), true), groups, latest };
return { kind: "hourly", metric, anchorMs: anchorToMs(Number(record.anchorUnixSeconds), true), groups };
}
if (cmdHi === CMD_STEPS) {
@@ -396,12 +391,12 @@ type StoreResult = Omit<LiveSyncResult, "seen">;
* fails, so the caller keeps whatever it would otherwise mark as consumed.
* Shared by the live batch and the journal replay.
*/
function storeRecords(records: JavaRecordList, includeLatest = true): StoreResult {
function storeRecords(records: JavaRecordList): StoreResult {
const wire: WireRecord[] = [];
const size = records.size();
for (let i = 0; i < size; i++) {
try {
const converted = toWire(records.get(i), includeLatest);
const converted = toWire(records.get(i));
if (converted) wire.push(converted);
} catch (error) {
console.warn("health live: skipped an undecodable record", error);
@@ -485,7 +480,7 @@ function replayFrameJournalOnce(): void {
const records: JavaRecordList = ringProtocol.decodeFrameJournal(File.fromPath(journalPath).readTextSync(), after);
const size = records.size();
if (size > 0) {
const result = storeRecords(records, false);
const result = storeRecords(records);
let through = after;
for (let i = 0; i < size; i++) through = Math.max(through, Number(records.get(i).receivedAtMs));
const next: ReplayCursor = { version: JOURNAL_DECODER_VERSION, throughReceivedAtMs: through };
@@ -548,7 +543,7 @@ export function syncLiveRecords(): LiveSyncResult {
/**
* Ask the ring for a fresh pull now, rather than waiting out the automatic
* ten-minute cycle. Returns immediately; the pull itself takes ~15s on the
* 30-minute cycle. Returns immediately; the pull itself takes ~15s on the
* communicator's worker thread and lands through the next `syncLiveRecords()`.
*
* Throttled communicator-side to one a minute — see
@@ -589,17 +584,19 @@ export function startLiveHealthSync(): void {
}
/**
* Pull the ring every ten minutes, one minute after each bucket boundary.
* Pull the ring on a wall-clock-aligned cadence: :01 and :31, every hour.
*
* This collects the latest heart-rate observation at roughly the cadence
* the stock app documents, as well as the existing historical buckets.
* It does not force the sensor to take a new measurement.
* Chris, 2026-09-12: *"I think we should be polling the ring on the 30 minute
* cycle (that was my intent, not a floor honestly)."* The 30-minute value in
* `RING_HEALTH_MIN_PULL_INTERVAL_MS` was always meant as a collection rhythm
* and got built as a throttle, so a connected, stable ring pulled never —
* nothing in the system drives a pull on a timer at all.
*
* Two reasons this is aligned to the wall clock rather than a plain interval:
*
* 1. **The ring's own step buckets close on 10-minute boundaries.** Pulling on
* the boundary collects a just-closed bucket instead of a half-formed one.
* 2. **An elapsed timer drifts.** A pull at :07 sets the next at :17, then :27,
* 2. **An elapsed timer drifts.** A pull at :07 sets the next at :37, then :07,
* wandering away from the boundary it is supposed to track. Re-arming
* against the clock each time cannot drift.
*
@@ -609,7 +606,7 @@ export function startLiveHealthSync(): void {
* This only *requests* a pull. The communicator still applies its own anti-spam
* floor, so an extra call here can never hammer the ring.
*/
const ALIGNED_PULL_MINUTES = [1, 11, 21, 31, 41, 51];
const ALIGNED_PULL_MINUTES = [1, 31];
let alignedPullTimer: ReturnType<typeof setTimeout> | null = null;
function msUntilNextAlignedPull(now: Date): number {
+4 -47
View File
@@ -59,7 +59,6 @@
import {
type HealthSample,
isHeartRateMeasurement,
type Rollup,
type SampleMetric,
type SleepSession,
@@ -229,51 +228,12 @@ export class HealthStore {
// -------------------------------------------------------------------------
// Reading
/** Append-journal cursor, committed by the exporter only after server acknowledgement.
* Revisions appended to an old month are exported too; a time watermark would lose them.
*/
exportBatch(cursor: Record<string, number>, limit = 200): {
cursor: Record<string, number>; samples: HealthSample[]; sleep: SleepSession[]; scanned: number;
} {
const next = { ...cursor };
const samples: HealthSample[] = [];
const sleep: SleepSession[] = [];
let scanned = 0;
for (const name of this.backend.list().filter(candidate => /^samples-\d{4}-\d{2}\.jsonl$/.test(candidate) || candidate === SLEEP_FILE).sort()) {
const text = this.backend.read(name);
if (text === null) throw new Error("Health export could not read history");
let offset = next[name] ?? 0;
if (!Number.isSafeInteger(offset) || offset < 0 || offset > text.length) offset = 0;
while (scanned < limit) {
const end = text.indexOf("\n", offset);
if (end < 0) break; // Never consume a partially written final record.
const line = text.slice(offset, end);
offset = end + 1;
scanned++;
if (name === SLEEP_FILE) {
try {
const session = JSON.parse(line) as SleepSession;
if (session?.timeResolved === true) sleep.push(session);
} catch { /* Ignore incomplete/corrupt journal lines as the local reader does. */ }
} else {
const sample = fromLine(line);
if (sample) samples.push(sample);
}
}
next[name] = offset;
if (scanned >= limit) break;
}
return { cursor: next, samples, sleep, scanned };
}
/** Bucket samples in [startMs, endMs). Point observations are opt-in so
* existing charts and daily averages never combine two overlapping series. */
samplesInRange(startMs: number, endMs: number, includeMeasurements = false): HealthSample[] {
/** Every stored sample overlapping [startMs, endMs). Exact - reads shards. */
samplesInRange(startMs: number, endMs: number): HealthSample[] {
const out: HealthSample[] = [];
for (const name of this.shardNamesInRange(startMs, endMs)) {
for (const sample of this.loadShard(name).values()) {
if (sample.startMs >= startMs && sample.startMs < endMs
&& (includeMeasurements || !isHeartRateMeasurement(sample))) out.push(sample);
if (sample.startMs >= startMs && sample.startMs < endMs) out.push(sample);
}
}
out.sort((a, b) => a.startMs - b.startMs);
@@ -337,7 +297,6 @@ export class HealthStore {
for (const name of this.backend.list()) {
if (!name.startsWith(SAMPLE_PREFIX) || !name.endsWith(SAMPLE_SUFFIX)) continue;
for (const sample of this.loadShard(name).values()) {
if (isHeartRateMeasurement(sample)) continue;
const key = dayKey(sample.startMs);
let byMetric = perDay.get(key);
if (!byMetric) {
@@ -364,9 +323,7 @@ export class HealthStore {
private updateRollupsFor(samples: readonly HealthSample[]): void {
const file = this.loadRollups();
const touched = new Set<string>();
for (const sample of samples) {
if (!isHeartRateMeasurement(sample)) touched.add(dayKey(sample.startMs));
}
for (const sample of samples) touched.add(dayKey(sample.startMs));
for (const key of touched) {
const parts = key.split("-").map(Number);
const dayStart = new Date(parts[0]!, parts[1]! - 1, parts[2]!).getTime();
-6
View File
@@ -36,12 +36,6 @@ export function isCumulative(metric: SampleMetric): boolean {
export const HOUR_MS = 3_600_000;
export const TEN_MINUTES_MS = 600_000;
/** Point observation, not a ten-minute average. Distinct from hourly buckets. */
export const HEART_RATE_MEASUREMENT_SPAN_MS = 1;
export function isHeartRateMeasurement(sample: HealthSample): boolean {
return sample.metric === "heartRate" && sample.spanMs === HEART_RATE_MEASUREMENT_SPAN_MS;
}
export const DAY_MS = 86_400_000;
/**
+32 -2
View File
@@ -9,7 +9,7 @@ declare const java: any;
* than bundled in the APK; FaceclawVoiceController reads the files from the
* directory each model's `dirName` names.
*
* Two models, same shape:
* Downloadable models, same shape:
* - "moonshine": the original on-device option (three files). The model is
* no longer bundled in the APK; it is fetched into the same filesDir
* location that earlier releases copied the bundled files to, so
@@ -29,12 +29,17 @@ declare const java: any;
* used for Moonshine below. Every hash here was computed locally from a
* freshly downloaded copy of the file, not copied from a doc page.
*
* - "whisper-base": multilingual base, int8-quantized. Used for non-English
* speech and auto-detection; English-only downloads remain untouched.
* SHA-256/size values come from the maintainer's LFS metadata, with the
* vocabulary hash computed locally. URLs pin the source revision.
*
* Mirrors the on-phone assistant model flow in llama.ts, except each model
* here is multiple files rather than one; they download sequentially through
* FaceclawModelDownloader (resume + pinned sha256 per file).
*/
export type AsrModelId = "moonshine" | "whisper-base-en";
export type AsrModelId = "moonshine" | "whisper-base-en" | "whisper-base";
type AsrModelFile = {
name: string;
@@ -105,6 +110,30 @@ export const ASR_MODELS: Record<AsrModelId, AsrModelDef> = {
],
totalBytes: 160626066,
},
"whisper-base": {
label: "Whisper (multilingual, base)",
dirName: "sherpa-onnx-whisper-base-int8",
baseUrl: "https://huggingface.co/csukuangfj/sherpa-onnx-whisper-base/resolve/bb53ee204431c90d314c1cc08d28d23e5b7927cc/",
files: [
{
name: "base-encoder.int8.onnx",
sha256: "0b8fb1304b6109976038efff5ace81720e00386f3ff6b54ee8c75291ca0a1e11",
sizeBytes: 29120534,
},
{
name: "base-decoder.int8.onnx",
sha256: "9759d217388a01b3a4c7c15533201067b48ae819c4daafc8624e64b9409dc02d",
sizeBytes: 130672026,
},
{
name: "base-tokens.txt",
sha256: "b34b360dbb493e781e479794586d661700670d65564001f23024971d1f2fa126",
sizeBytes: 816730,
},
],
totalBytes: 160609290,
},
};
export type AsrModelState = {
@@ -129,6 +158,7 @@ function freshRuntime(): ModelRuntime {
const runtimes: Record<AsrModelId, ModelRuntime> = {
moonshine: freshRuntime(),
"whisper-base-en": freshRuntime(),
"whisper-base": freshRuntime(),
};
function modelDirPath(id: AsrModelId): string {
+8 -5
View File
@@ -1,6 +1,6 @@
import type { CloudSttClient, CloudSttOptions } from "./cloud-stt";
import { ElevenLabsSttClient } from "./elevenlabs-stt";
import { OpenAiRealtimeSttClient } from "./openai-stt";
import { DEFAULT_OPENAI_STT_MODEL, OpenAiRealtimeSttClient, type OpenAiSttModel } from "./openai-stt";
import { ReconnectingSttClient } from "./reconnecting-stt";
import { SonioxSttClient } from "./soniox-stt";
import type { VoiceProviderKind } from "./voice-control";
@@ -14,11 +14,12 @@ export type VoiceProviderSelection = {
provider: VoiceProviderKind;
/**
* Spoken language the provider should expect (ISO 639-1); empty lets it
* detect the language. Cloud providers only.
* detect the language. Also used by on-device Whisper.
*/
language?: string;
elevenLabsApiKey: string;
openAiApiKey: string;
openAiTranscriptionModel?: OpenAiSttModel;
sonioxApiKey: string;
/** Self-hosted Whisper ("whisper-server"); the key is optional there. */
whisperServerUrl?: string;
@@ -52,7 +53,7 @@ const CLOUD_PROVIDERS: Partial<Record<VoiceProviderKind, CloudProvider>> = {
whisper: {
name: "OpenAI",
apiKey: (selection) => selection.openAiApiKey,
create: (options) => new OpenAiRealtimeSttClient(options),
create: (options, selection) => new OpenAiRealtimeSttClient({ ...options, model: selection.openAiTranscriptionModel }),
},
"whisper-server": {
name: "Whisper server",
@@ -76,8 +77,10 @@ function isConfigured(provider: CloudProvider, selection: VoiceProviderSelection
* What a capture transcribes with: the provider and the language it is told
* to expect. A running capture is shared only by holders asking for the same.
*/
export function transcriptionKey(selection: Pick<VoiceProviderSelection, "provider" | "language">): string {
return `${selection.provider}:${(selection.language ?? "").trim().toLowerCase()}`;
export function transcriptionKey(selection: Pick<VoiceProviderSelection, "provider" | "language" | "openAiTranscriptionModel">): string {
const fallback = selection.provider === "onboard-whisper" ? "en" : "";
const model = selection.provider === "whisper" ? `:${selection.openAiTranscriptionModel ?? DEFAULT_OPENAI_STT_MODEL}` : "";
return `${selection.provider}:${(selection.language ?? fallback).trim().toLowerCase()}${model}`;
}
/** Whether createCloudSttClient would return a cloud client for this selection. */
-13
View File
@@ -1,13 +0,0 @@
import { Utils } from "@nativescript/core";
declare const com: any;
/** Android Keystore-backed, excluded from backups. Never falls back to plain settings. */
export function readHealthExportSecret(): string {
if (!global.isAndroid) return "";
return String(com.faceclaw.app.FaceclawHealthExportSecret.read(Utils.android.getApplicationContext()));
}
export function writeHealthExportSecret(value: string): void {
if (!global.isAndroid) throw new Error("Health export is available on Android only");
com.faceclaw.app.FaceclawHealthExportSecret.write(Utils.android.getApplicationContext(), value);
}
+10 -7
View File
@@ -3,7 +3,7 @@ import { openSocket, type SocketConnection } from "./socket";
/**
* OpenAI realtime speech-to-text over WebSocket (a transcription-only session
* on the Realtime API, with the streaming gpt-realtime-whisper model).
* on the Realtime API, with a configurable transcription model).
* https://developers.openai.com/api/docs/guides/realtime-transcription
*
* Like the ElevenLabs client, push-to-talk defines the utterance boundary:
@@ -16,10 +16,11 @@ import { openSocket, type SocketConnection } from "./socket";
*/
const WS_URL = "wss://api.openai.com/v1/realtime?intent=transcription";
const MODEL_ID = "gpt-realtime-whisper";
export const DEFAULT_OPENAI_STT_MODEL = "gpt-realtime-whisper";
export type OpenAiSttModel = "gpt-realtime-whisper" | "gpt-4o-mini-transcribe" | "gpt-4o-transcribe";
const TARGET_SAMPLE_RATE = 24000;
export type OpenAiSttOptions = CloudSttOptions;
export type OpenAiSttOptions = CloudSttOptions & { model?: OpenAiSttModel };
export class OpenAiRealtimeSttClient implements CloudSttClient {
private ws: SocketConnection | null = null;
@@ -40,7 +41,7 @@ export class OpenAiRealtimeSttClient implements CloudSttClient {
onOpen: () => {
if (this.closed) return;
this.open = true;
this.trySend(JSON.stringify(sessionConfig(this.options.language ?? "")));
this.trySend(JSON.stringify(sessionConfig(this.options.language ?? "", this.options.model)));
for (const chunk of this.pendingChunks.splice(0)) {
this.sendChunk(chunk);
}
@@ -165,7 +166,9 @@ export class OpenAiRealtimeSttClient implements CloudSttClient {
this.options.onDisconnected?.(`OpenAI: ${String(message.error?.message)}`);
return;
}
this.options.onError(`OpenAI: ${String(message.error?.message ?? "unknown error")}`);
this.options.onError(message.error?.code === "model_not_found"
? `OpenAI: ${this.options.model ?? DEFAULT_OPENAI_STT_MODEL} unavailable. Choose a model in Settings > Voice > OpenAI transcription model.`
: `OpenAI: ${String(message.error?.message ?? "unknown error")}`);
return;
default:
return;
@@ -201,7 +204,7 @@ export class OpenAiRealtimeSttClient implements CloudSttClient {
}
function sessionConfig(language: string): object {
function sessionConfig(language: string, model: OpenAiSttModel = DEFAULT_OPENAI_STT_MODEL): object {
return {
type: "session.update",
session: {
@@ -209,7 +212,7 @@ function sessionConfig(language: string): object {
audio: {
input: {
format: { type: "audio/pcm", rate: TARGET_SAMPLE_RATE },
transcription: { model: MODEL_ID, ...(language ? { language } : {}) },
transcription: { model, ...(language ? { language } : {}) },
// Push-to-talk owns the utterance boundary; no server VAD.
turn_detection: null,
},
+24
View File
@@ -0,0 +1,24 @@
/** Languages supported by both Whisper backends, in picker order. */
export const TRANSCRIPTION_LANGUAGES = {
en: "English", fr: "French", de: "German", es: "Spanish", it: "Italian",
pt: "Portuguese", nl: "Dutch", ar: "Arabic", zh: "Chinese", cs: "Czech",
da: "Danish", fi: "Finnish", el: "Greek", he: "Hebrew", hi: "Hindi",
hu: "Hungarian", id: "Indonesian", ja: "Japanese", ko: "Korean",
no: "Norwegian", pl: "Polish", ro: "Romanian", ru: "Russian", sk: "Slovak",
sv: "Swedish", th: "Thai", tr: "Turkish", uk: "Ukrainian", vi: "Vietnamese",
} as const;
export type TranscriptionLanguage = "default" | "auto" | keyof typeof TRANSCRIPTION_LANGUAGES;
/** An empty language asks Whisper to detect it; default preserves each engine's old behavior. */
export function resolveTranscriptionLanguage(
choice: TranscriptionLanguage, provider: string, serverLanguage = "",
): string {
// Moonshine is English-only; Apple's on-device recognizer retains its own locale.
if (provider === "onboard") return "";
if (choice === "default") {
if (provider === "onboard-whisper") return "en";
return provider === "whisper-server" ? serverLanguage.trim().toLowerCase() : "";
}
return choice === "auto" ? "" : choice;
}
+5 -2
View File
@@ -1,3 +1,4 @@
import type { OpenAiSttModel } from "./openai-stt";
import { Utils } from "@nativescript/core";
import { type CloudSttTranscriptEvent, CloudSttClient } from "./cloud-stt";
@@ -24,7 +25,7 @@ export type VoiceControlState = {
detail: string;
};
// "whisper" (no "onboard-" prefix) is the OpenAI CLOUD provider (gpt-realtime-whisper,
// "whisper" (no "onboard-" prefix) is the OpenAI CLOUD provider (a configurable transcription model,
// see openai-stt.ts) -- an unfortunate pre-existing name collision with the model
// family, not with "onboard-whisper" below, which is the on-device sherpa-onnx
// Whisper backend added alongside "onboard" (Moonshine). Kept as-is rather than
@@ -54,11 +55,12 @@ export type PushToTalkOptions = {
provider: VoiceProviderKind;
elevenLabsApiKey: string;
openAiApiKey: string;
openAiTranscriptionModel?: OpenAiSttModel;
sonioxApiKey: string;
whisperServerUrl?: string;
whisperServerModel?: string;
whisperServerApiKey?: string;
/** Spoken language for cloud providers (see VoiceProviderSelection.language). */
/** Spoken language for cloud providers and on-device Whisper; empty detects, absent keeps local English. */
language?: string;
saveRecording: boolean;
/**
@@ -396,6 +398,7 @@ export class FaceclawVoiceControlBridge {
// Which on-device model to load; a no-op setter for every provider except
// "onboard-whisper" (FaceclawVoiceController defaults to Moonshine).
this.controller?.setOnboardModelKind(options.provider === "onboard-whisper" ? "whisper" : "moonshine");
this.controller?.setOnboardLanguage(options.language ?? "en");
const captureId = this.nextNativeCaptureId++;
this.nativeCaptureFinished = new Promise((resolve) => { this.nativeCaptureResolvers.set(captureId, resolve); });
this.controller?.start("onboard", captureId);
+31 -37
View File
@@ -1,4 +1,4 @@
import { readHealthExportSecret, writeHealthExportSecret } from "../native/health-export-secret";
import type { OpenAiSttModel } from "../native/openai-stt";
import { normalizeNightscoutThreshold, type NightscoutThresholds } from "../apps/nightscout/nightscout-alerts";
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
import { DEFAULT_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
@@ -19,6 +19,7 @@ import {
} from "~/assistant/models";
import { isLocalModelReady } from "../native/local-llm";
import { normalizeWhisperServerUrl } from "../native/whisper-server-stt";
import { TRANSCRIPTION_LANGUAGES, resolveTranscriptionLanguage, type TranscriptionLanguage } from "../native/transcription-language";
import { normalizeOpenAiCompatibleUrl } from "../native/openai-chat";
import { isValidSpotifyClientId, SPOTIFY_CLIENT_ID_KEY } from "../native/spotify-auth";
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, openModalMenu } from "./menu";
@@ -261,39 +262,6 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
}
/** A changed credential starts a new delivery history without retaining the old secret. */
class HealthExportKeySetting extends ConfigSettingString {
get(): string { return readHealthExportSecret(); }
set(value: string): string {
const normalized = value.trim();
if (normalized !== this.get()) {
writeHealthExportSecret(normalized);
setStringSetting("health.export.cursor", "");
setStringSetting("health.export.generation", String(Number(getStringSetting("health.export.generation", "0")) + 1));
}
return normalized;
}
getValidValue(): string { return this.get(); }
}
export const healthExportEnabledSetting = new ConfigSettingBoolean({
id: "healthExportEnabled", label: "Export health data", storageKey: "health.export.enabled",
defaultValue: false, reportInAnalytics: false,
description: "Send saved R1 health history to your server over HTTPS. Retries while Faceclaw is running; phone storage is retained.",
});
export const healthExportUrlSetting = new ConfigSettingString({
id: "healthExportUrl", label: "Endpoint URL", storageKey: "health.export.url", defaultValue: "",
normalize: value => (value ?? "").trim(),
validate: value => !value || /^https:\/\/[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::\d{1,5})?(?:\/[^\s?#]*)?$/i.test(value)
? null : "Use an HTTPS URL without credentials, query or fragment",
description: "Full ingestion URL, for example https://health.undefined-dev.fr/v1/health",
});
export const healthExportKeySetting = new HealthExportKeySetting({
id: "healthExportKey", label: "API key", storageKey: "health.export.key", defaultValue: "",
inputKind: "password", formatValue: value => value ? "Configured" : "(empty)",
description: "Device-specific write-only key, stored using Android Keystore.",
});
export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMode>({
id: "batteryDisplayMode",
label: "Style",
@@ -1170,9 +1138,35 @@ export const whisperServerModelSetting = new ConfigSettingString({
description: "Model id sent to the Whisper server. Leave empty to use the first model the server lists.",
});
export const openAiTranscriptionModelSetting = new ConfigSettingEnum<OpenAiSttModel>({
id: "openai-transcription-model",
label: "OpenAI transcription model",
storageKey: "voice.openAiTranscriptionModel",
defaultValue: "gpt-realtime-whisper",
values: ["gpt-realtime-whisper", "gpt-4o-mini-transcribe", "gpt-4o-transcribe"],
description: "Cloud speech-to-text for Translate, Transcribe and dictation. Choose a model available to your OpenAI project. This does not change the Assistant translation model. The transcribe models return text after each committed audio segment.",
});
export const voiceLanguageSetting = new ConfigSettingEnum<TranscriptionLanguage>({
id: "voice-language",
label: "Transcription language",
storageKey: "voice.language",
defaultValue: "default",
values: ["default", "auto", ...(Object.keys(TRANSCRIPTION_LANGUAGES) as (keyof typeof TRANSCRIPTION_LANGUAGES)[])],
formatValue: (value) => value === "default" ? "Provider default"
: value === "auto" ? "Auto-detect" : TRANSCRIPTION_LANGUAGES[value],
description: "Spoken language for OpenAI, on-device Whisper and other cloud transcription providers. " +
"Provider default preserves English for on-device Whisper and auto-detection for cloud providers, with the server's own language below. " +
"On-device Whisper needs the multilingual model for auto-detection or languages other than English. Moonshine remains English-only.",
});
export function getVoiceTranscriptionLanguage(provider: VoiceProvider): string {
return resolveTranscriptionLanguage(voiceLanguageSetting.get(), provider, whisperServerLanguageSetting.get());
}
export const whisperServerLanguageSetting = new ConfigSettingString({
id: "whisper-server-language",
label: "Whisper language",
label: "Whisper server language",
storageKey: "voice.whisperServerLanguage",
defaultValue: "",
editorTitle: "Language code, e.g. en or sk (empty: auto)",
@@ -1180,7 +1174,7 @@ export const whisperServerLanguageSetting = new ConfigSettingString({
formatValue: (value) => value || "Auto-detect",
validate: (value) => (!value.trim() || /^[a-z]{2,3}$/i.test(value.trim()) ? null : "Use a language code like en, sk or cs."),
description:
"Spoken language for the Whisper server. Leave empty to auto-detect; a wrong fixed language makes Whisper translate into it instead of transcribing.",
"Spoken language for the Whisper server when Transcription language is Provider default. Leave empty to auto-detect.",
});
export const whisperServerApiKeySetting = new ConfigSettingString({
@@ -1714,7 +1708,7 @@ export class EditTextSettingLayer implements Layer {
for (let index = 0; index < message.length; index++) {
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
}
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.get(), 52), 220);
const error = this.setting.validationError();
if (error) wrapText(font, error, width - 48).forEach((line, index) =>
image.drawText(font, 22, messageTop + (message.length + 4 + index) * step, line, 180));
+6 -15
View File
@@ -1,4 +1,3 @@
import { healthExportStatus, syncHealthExport } from "../../health/health-export";
import { remoteInputMenuItem } from "./remote-input-menu";
import { knownFolders } from "@nativescript/core";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
@@ -29,9 +28,6 @@ import type { LayerContext } from "../layers";
import { drawRightValueMenuItem, openModalMenu, submenuItem, type MenuItem } from "../menu";
import { shell } from "../shell/shell";
import {
healthExportEnabledSetting,
healthExportUrlSetting,
healthExportKeySetting,
anthropicApiKeySetting,
appSwitcherPositionSetting,
statusBarPositionSetting,
@@ -67,6 +63,7 @@ import {
mapboxApiKeySetting,
mirrorTouchSetting,
openAiApiKeySetting,
openAiTranscriptionModelSetting,
previewColorSetting,
previewScalingSetting,
phoneRotationSetting,
@@ -91,6 +88,7 @@ import {
toggleSettingMenuItem,
useMicControlSetting,
voiceProviderSetting,
voiceLanguageSetting,
screenTimeoutSetting,
wakeToLastAppSetting,
wakeWordActionSetting,
@@ -147,9 +145,11 @@ function settingsSections(): SettingsSection[] {
items: [
enumSettingMenuItem(wakeWordActionSetting),
enumSettingMenuItem(voiceProviderSetting),
enumSettingMenuItem(voiceLanguageSetting),
...whisperServerMenuItems(),
asrModelMenuItem("moonshine"),
asrModelMenuItem("whisper-base-en"),
asrModelMenuItem("whisper-base"),
],
},
{
@@ -191,16 +191,6 @@ function settingsSections(): SettingsSection[] {
];
},
},
...(!global.isIOS ? [{
label: "Health export",
get items() { return [
toggleSettingMenuItem(healthExportEnabledSetting),
textSettingMenuItem(healthExportUrlSetting),
textSettingMenuItem(healthExportKeySetting),
{ label: "Sync now", description: healthExportStatus(), onSelect: () => { void syncHealthExport(); } },
{ label: healthExportStatus(), disabled: true, onSelect: () => {} },
]; },
}] : []),
{
label: "API Keys",
items: [
@@ -298,7 +288,7 @@ function settingsSections(): SettingsSection[] {
toggleSettingMenuItem(showBleBandwidthSetting)] };
// No downloadable on-device models: iOS's on-device option is Apple's recognizer.
if (section.label === "Voice") return { label: "Voice", items: [enumSettingMenuItem(wakeWordActionSetting),
enumSettingMenuItem(voiceProviderSetting), toggleSettingMenuItem(saveTranscribeAudioSetting), ...whisperServerMenuItems()] };
enumSettingMenuItem(voiceProviderSetting), enumSettingMenuItem(voiceLanguageSetting), toggleSettingMenuItem(saveTranscribeAudioSetting), ...whisperServerMenuItems()] };
if (section.label === "Display") return { ...section, items: section.items.filter(item =>
item.label !== screenTimeoutSetting.label) };
return section;
@@ -541,6 +531,7 @@ function asrModelStatusText(id: AsrModelId): string {
*/
function whisperServerMenuItems(): MenuItem[] {
return [
enumSettingMenuItem(openAiTranscriptionModelSetting),
textSettingMenuItem(whisperServerUrlSetting),
textSettingMenuItem(whisperServerModelSetting),
textSettingMenuItem(whisperServerLanguageSetting),
-71
View File
@@ -1,71 +0,0 @@
# R1 health export
Android Settings → Health export uses the existing toggle and text/password
editors. Export defaults off; URL and API key default empty. Only the API key
uses AES-GCM with Android Keystore and an AtomicFile in noBackupFilesDir. Keys
are masked on both glasses and phone. The URL/cursor use shared settings.
The API/image pipeline lives in the dedicated Infrastructure/FaceclawHealth Git
repository. Kubernetes manifests live in the Infrastructure repository under
FaceclawHealth, and SQL dashboards in GrafanaDashboards/Health. Protocol v1 sends normalized HealthSample/SleepSession
fields with original millisecond timestamps. Batches contain at most 200 records
and 240 KB. HTTPS is mandatory, redirects are refused, and only HTTP 200 with
accepted:true advances the cursor. No health content or keys are logged.
The exporter reads existing append journals, including revisions to old months,
without extra BLE pulls. Partial trailing lines are retried. Unresolved sleep
sessions and sample fixtures are excluded. Replayed data is upserted server-side.
A new URL/key resets delivery history safely. One batch runs per minute while
the Android process is alive; this adds no background service or wake lock and
does not promise synchronization while the app is stopped. Disable preserves
local history and existing server data. Watch/iOS export is outside this change.
Software validation: exporter tests for replay, revisions, failed/malformed
acknowledgements, redirects, destination/credential edits, fixtures, partial
records and overlapping requests; full JS suite, TypeScript and Android release
compilation. API tests additionally cover PostgreSQL rollback and deduplication.
Hardware/end-to-end validation remains pending: enable ring health sync, configure
the deployed URL/key, then compare measured timestamps/values and sleep durations
with Grafana. Test offline/reconnect, app restart, disable/re-enable and rotated
keys. Check key masking, log redaction and preservation of other preferences.
No firmware modification is needed.
## Latest heart-rate observations
Live HR pages also carry a last-measured timestamp and value. These are now
stored as `heartRate` with `spanMs: 1`, at the exact measurement timestamp:
this denotes a point observation, **not** a ten-minute average. Existing hourly
records retain `spanMs: 3600000`. The existing local and PostgreSQL keys include
span, so readings and summaries coexist without collisions. Equal BPM at a new
timestamp is a new measurement; repeated timestamps are deduplicated across
restarts and corrected values update the same observation. Local bucket charts
and daily rollups exclude points, including when the cache is rebuilt.
The existing aligned ring pull changes from :01/:31 to :01/:11/:21/:31/:41/:51.
This is a collection cadence, not a sensor setting or a guarantee of six readings
per hour. It uses the same ring worker, connection windows and anti-spam guards;
it makes more collection attempts than before. Offline gaps remain gaps and
there is no new background service. The exporter still sends at most one batch
per minute while the Android process runs.
Timestamp handling deliberately retains the current handshake's legacy clock
convention, inverting its existing phone-timezone offset once. Only a live point
within 20 minutes of page reception and no more than two minutes in the future
is accepted; invalid/missing timestamps and BPM outside 1–300 are skipped.
Reception time is never substituted for measurement time. Old frame-journal
replay continues restoring hourly history but does not reconstruct point readings:
old pages may mix clock domains. No firmware/time-sync migration is attempted.
A timezone change around measurement or an older value can therefore leave a gap;
correct placement across such transitions still requires hardware validation.
The deployed v1 API already accepts span 1 and upserts on device/metric/time/span.
No API image, schema migration, Infrastructure change or key rotation is needed.
The Grafana overview shows separate hourly-average and latest-reading series,
with point markers for readings, not interpolated ten-minute averages.
Software checks cover latest-page conversion, invalid/stale/future readings,
timezone offsets, restart/deduplication, unchanged hourly rollups, export and
all six scheduling slots. Hardware checks remain pending: record raw/current
measurement times across several pulls, compare BPM/time with the stock app,
and check reconnect, timezone/DST transitions and collection battery impact.
+68
View File
@@ -0,0 +1,68 @@
# Whisper transcription languages
Settings > Voice > Transcription language selects French, English, 27 other
languages, or auto-detection. It applies to ordinary dictation and continuous
transcription using OpenAI, on-device Whisper, and the other cloud providers.
Translate retains its own spoken-language preference. Moonshine remains
English-only; Apple's on-device speech recognizer retains its own locale.
The initial **Provider default** preserves existing installations: English for
on-device Whisper, auto-detection for OpenAI/other cloud providers, and the saved
Whisper server language for self-hosted Whisper. Selecting another shared
language overrides the server language without deleting it. Returning to Provider
default restores it. Settings persist through the existing settings store.
For French or auto-detection with **On-device (Whisper)**, download
**On-device model: Whisper (multilingual, base)** in Settings > Voice (~161 MB).
English uses the existing English-only base model; neither model is deleted or
downloaded automatically. A missing model uses the existing “Voice model not
downloaded” status. Language changes restart active continuous transcription;
other captures use the new language when started.
## Software validation
- JavaScript regression tests exercise stored settings/reload, compatible
defaults, French and auto-detection, Translate overrides in Android/iOS capture
options, the OpenAI WebSocket configuration, and local bridge restart/sharing.
- Kotlin tests exercise English/French/other/automatic model selection and file
names. Android release compilation checks the actual sherpa-onnx bridge.
- New model downloads use a pinned Hugging Face revision, per-file SHA-256 and
the existing resumable downloader. Encoder/decoder hashes and sizes come from
repository LFS metadata; the vocabulary hash was computed from its contents.
## Device validation still required
With both phone microphone preview and glasses microphone, check French dictation
(including accents), auto-detection, English rollback, continuous capture while
changing language, cancellation/resumption of model download, and persistence
after restarting the app. Compare OpenAI and offline Whisper on the same phrases.
No paid API call, microphone recording, or firmware update is needed for the
software checks above; recognition accuracy and latency require device testing.
## References
- [OpenAI Realtime transcription: language configuration](https://developers.openai.com/api/docs/guides/realtime-transcription)
- [sherpa-onnx Whisper configuration and automatic language detection](https://github.com/k2-fsa/sherpa-onnx/blob/master/sherpa-onnx/csrc/offline-whisper-model-config.cc)
- [Multilingual base model, pinned revision](https://huggingface.co/csukuangfj/sherpa-onnx-whisper-base/tree/bb53ee204431c90d314c1cc08d28d23e5b7927cc)
## OpenAI transcription model selection
Settings > Voice > OpenAI transcription model selects gpt-realtime-whisper,
gpt-4o-mini-transcribe or gpt-4o-transcribe. For a project whose model list lacks
gpt-realtime-whisper but includes gpt-4o-mini-transcribe, select the latter.
The unset default retains gpt-realtime-whisper for existing installations; no
provider, language or Assistant model preference is overwritten. This setting
applies to Translate's speech recognition as well as Transcribe and dictation.
The two transcribe alternatives produce transcript deltas after a committed
audio segment; existing pause segmentation and push-to-talk release supply the
commits. Choosing a model retargets active continuous capture.
Model access errors name the requested model before the long project error and
point to the setting. Factory/session-wire tests cover model, language, manual
commit and final transcript behavior; settings tests cover persistence and the
Android/iOS option plumbing. No real API inference was performed; actual project
access, recognition and latency remain to be checked on a device. The model list
provided by the operator establishes account visibility, not a successful audio
request.
Reference: [OpenAI transcription session API](https://developers.openai.com/api/reference/resources/realtime/subresources/transcription_sessions/methods/create).
@@ -0,0 +1,18 @@
package com.faceclaw.app
/** The English-only files remain usable after upgrading; other languages need multilingual base. */
data class WhisperModelFiles(val language: String) {
val englishOnly: Boolean get() = language == "en"
val dirName: String get() = if (englishOnly) "sherpa-onnx-whisper-base-en-int8" else "sherpa-onnx-whisper-base-int8"
private val prefix: String get() = if (englishOnly) "base.en" else "base"
val encoder: String get() = "$prefix-encoder.int8.onnx"
val decoder: String get() = "$prefix-decoder.int8.onnx"
val tokens: String get() = "$prefix-tokens.txt"
val files: List<String> get() = listOf(encoder, decoder, tokens)
companion object {
/** Null preserves the old English default; an empty code enables automatic detection. */
fun forLanguage(language: String?): WhisperModelFiles =
WhisperModelFiles(language?.trim()?.lowercase() ?: "en")
}
}
+1 -1
View File
@@ -40,7 +40,6 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
},
});
const load = loader({ global: { isIOS: false, isAndroid: true } }, {
'../../health/health-export': { healthExportStatus: () => 'Export disabled', syncHealthExport() {} },
'./remote-input-menu': { remoteInputMenuItem: () => ({ label: 'Remote input' }) },
'@nativescript/core': { knownFolders: {} },
'../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
@@ -56,6 +55,7 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
ASR_MODELS: {
moonshine: { label: 'Moonshine', sizeBytes: 1 },
'whisper-base-en': { label: 'Whisper Base English', sizeBytes: 1 },
'whisper-base': { label: 'Whisper Base Multilingual', sizeBytes: 1 },
},
asrModelState: () => ({}), cancelAsrModelDownload() {},
deleteAsrModel() {}, startAsrModelDownload() {}, onAsrModelStateChanged: () => () => {},
+1
View File
@@ -26,6 +26,7 @@ function settingsFixture(store = new Map()) {
};
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
if (id.includes('transcription-language')) return require('../.test-build/app/native/transcription-language.js');
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
}};
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/ui/dashboard-settings.ts', 'utf8'), {
+44 -2
View File
@@ -207,6 +207,8 @@ test('provider selection falls back to on-device without a key and connects the
// A running capture is shared only on the same provider and language.
assert.equal(transcriptionKey({ provider: 'soniox', language: ' JA ' }), 'soniox:ja');
assert.notEqual(transcriptionKey({ provider: 'soniox' }), transcriptionKey({ provider: 'soniox', language: 'ja' }));
assert.equal(transcriptionKey({ provider: 'onboard-whisper' }), transcriptionKey({ provider: 'onboard-whisper', language: 'en' }));
assert.notEqual(transcriptionKey({ provider: 'onboard-whisper' }), transcriptionKey({ provider: 'onboard-whisper', language: '' }));
const statuses = [];
const options = { onTranscript() {}, onStatus: status => statuses.push(status), onError() {} };
const selection = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: ' ', sonioxApiKey: 'soniox-key' };
@@ -225,13 +227,13 @@ test('provider selection falls back to on-device without a key and connects the
});
test('a spoken-language hint reaches each provider on the wire, and is left out to auto-detect', () => {
for (const language of ['ja', '']) {
for (const language of ['fr', 'ja', '']) {
const elevenlabs = harness('elevenlabs', true, { language });
assert.equal(new URL(elevenlabs.sockets[0].url).searchParams.get('language_code'), language || null);
const soniox = harness('soniox', true, { language });
soniox.open();
assert.deepEqual(JSON.parse(soniox.sockets[0].sent[0]).language_hints, language ? ['ja'] : undefined);
assert.deepEqual(JSON.parse(soniox.sockets[0].sent[0]).language_hints, language ? [language] : undefined);
const openai = harness('openai', true, { language });
openai.open();
@@ -240,3 +242,43 @@ test('a spoken-language hint reaches each provider on the wire, and is left out
assert.equal(transcription.language, language || undefined);
}
});
test('OpenAI selected transcription models preserve French hints, manual commits and final transcripts', () => {
for (const model of ['gpt-realtime-whisper', 'gpt-4o-mini-transcribe', 'gpt-4o-transcribe']) {
const h = harness('openai', true, { model, language: 'fr' });
h.open();
const input = JSON.parse(h.sockets[0].sent[0]).session.audio.input;
assert.equal(input.transcription.model, model);
assert.equal(input.transcription.language, 'fr');
assert.equal(input.turn_detection, null);
h.client.acceptPcm(pcm(1200, 150));
h.client.acceptPcm(pcm(0, 1500));
assert.ok(h.sockets[0].sent.some(value => JSON.parse(value).type === 'input_audio_buffer.commit'));
h.message({ type: 'input_audio_buffer.committed', item_id: 'one' });
h.message({ type: 'conversation.item.input_audio_transcription.delta', item_id: 'one', delta: 'Bonjour' });
h.message({ type: 'conversation.item.input_audio_transcription.completed', item_id: 'one', transcript: 'Bonjour à tous.' });
assert.equal(h.events.at(-1).text, 'Bonjour à tous.');
assert.equal(h.events.at(-1).isFinal, true);
h.message({ type: 'error', error: { code: 'model_not_found', message: 'Project private-id does not have access' } });
assert.ok(h.errors[0].includes(model));
assert.ok(h.errors[0].includes('OpenAI transcription model'));
}
});
test('OpenAI model selection reaches the factory and separates shared captures only for OpenAI', () => {
const created = [];
const load = loader({ setTimeout, clearTimeout }, {
'./openai-stt': {
DEFAULT_OPENAI_STT_MODEL: 'gpt-realtime-whisper',
OpenAiRealtimeSttClient: class { constructor(options) { created.push(options); } start() {} stop() {} },
},
});
const { createCloudSttClient, transcriptionKey } = load('app/native/cloud-stt-provider.ts');
const selection = { provider: 'whisper', language: 'fr', openAiApiKey: 'test', openAiTranscriptionModel: 'gpt-4o-mini-transcribe' };
createCloudSttClient(selection, { onStatus() {}, onError() {}, onTranscript() {} }, () => false).start();
assert.equal(created[0].model, selection.openAiTranscriptionModel);
assert.equal(created[0].language, 'fr');
assert.notEqual(transcriptionKey(selection), transcriptionKey({ ...selection, openAiTranscriptionModel: 'gpt-realtime-whisper' }));
assert.equal(transcriptionKey({ provider: 'whisper' }), transcriptionKey({ provider: 'whisper', openAiTranscriptionModel: 'gpt-realtime-whisper' }));
assert.equal(transcriptionKey({ ...selection, provider: 'soniox' }), transcriptionKey({ ...selection, provider: 'soniox', openAiTranscriptionModel: 'gpt-4o-transcribe' }));
});
+1
View File
@@ -12,6 +12,7 @@ function settingsFixture(store = new Map()) {
};
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
if (id.includes('transcription-language')) return require('../.test-build/app/native/transcription-language.js');
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
}};
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/ui/dashboard-settings.ts', 'utf8'), {
-122
View File
@@ -1,122 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function setup() {
const files = new Map();
const backend = { list: () => [...files.keys()], read: name => files.get(name) ?? null,
exists: name => files.has(name), append: (name, text) => files.set(name, (files.get(name) ?? '') + text),
write: (name, text) => files.set(name, text) };
const { HealthStore } = loader()('app/health/health-store.ts');
const store = new HealthStore(backend);
const settings = new Map();
let url = 'https://health.example/v1/health', key = 'private-test-key', enabled = true, fixture = false;
let response = { status: 200, json: async () => ({ accepted: true }) };
const requests = [];
const exporter = loader({ setTimeout, setInterval }, {
'./health-store-files': { healthStore: () => store },
'./health-seed': { isFixtureData: () => fixture },
'../ui/dashboard-settings': {
healthExportEnabledSetting: { get: () => enabled },
healthExportUrlSetting: { get: () => url, validationError: () => url.startsWith('https://') ? null : 'HTTPS required' },
healthExportKeySetting: { get: () => key },
},
'../native/settings-store': { getStringSetting: (k, d) => settings.get(k) ?? d, setStringSetting: (k, v) => settings.set(k, v) },
'../util/http': { fetchTextWithUserAgent: async (url, options) => { requests.push({ url, options }); return typeof response === 'function' ? response() : response; } },
})('app/health/health-export.ts');
return { store, files, settings, exporter, requests,
configure: options => { if ('url' in options) url=options.url; if ('enabled' in options) enabled=options.enabled; if ('fixture' in options) fixture=options.fixture; if ('response' in options) response=options.response; } };
}
const sample = { metric:'heartRate',startMs:1700000000000,spanMs:3600000,min:60,max:90,avg:75,total:0 };
test('exports original measurements, acknowledges durably and catches revisions to old buckets', async () => {
const h=setup();h.store.ingestSamples([sample]);
await h.exporter.syncHealthExport();
assert.equal(h.requests.length,1);
assert.deepEqual(JSON.parse(h.requests[0].options.body),{version:1,samples:[sample],sleep:[]});
assert.equal(h.requests[0].options.dontFollowRedirects,true);
assert.ok(!h.settings.get('health.export.cursor').includes('private-test-key'));
await h.exporter.syncHealthExport();assert.equal(h.requests.length,1);
h.store.ingestSamples([{...sample,avg:80}]);await h.exporter.syncHealthExport();
assert.equal(JSON.parse(h.requests[1].options.body).samples[0].avg,80);
h.configure({url:'https://another.example/v1/health'});await h.exporter.syncHealthExport();
assert.equal(h.requests.length,3);
});
test('failed or malformed acknowledgements retain cursor for replay; no secret in status', async () => {
for (const response of [{status:401},{status:503},{status:302},{status:200,json:async()=>({})},()=>Promise.reject(new Error('private-test-key'))]) {
const h=setup();h.store.ingestSamples([sample]);h.configure({response});await h.exporter.syncHealthExport();
assert.equal(h.settings.has('health.export.cursor'),false);
assert.ok(!h.exporter.healthExportStatus().includes('private-test-key'));
h.configure({response:{status:200,json:async()=>({accepted:true})}});
await h.exporter.syncHealthExport();assert.equal(h.requests.length,2);
}
});
test('disabled export, fixtures, missing key configuration and HTTP never upload', async () => {
for (const config of [{enabled:false},{fixture:true},{url:'http://health.example/v1/health'},{url:''}]) {
const h=setup();h.store.ingestSamples([sample]);h.configure(config);
await h.exporter.syncHealthExport();assert.equal(h.requests.length,0);
}
});
test('bounded batches preserve partial lines, unresolved sleep and late appends', () => {
const h=setup();h.store.ingestSamples([sample]);
const name=[...h.files.keys()].find(n=>n.startsWith('samples-'));
const first=h.store.exportBatch({},1);assert.equal(first.scanned,1);
const second=h.store.exportBatch(first.cursor,200);assert.equal(second.samples.length,1);
h.files.set(name,h.files.get(name)+'{"m":');
const partial=h.store.exportBatch(second.cursor);assert.equal(partial.scanned,0);
h.files.set(name,h.files.get(name)+'"hrv","t":1700000000000,"s":3600000,"n":1,"x":3,"a":2,"u":0}\n');
assert.equal(h.store.exportBatch(partial.cursor).samples[0].metric,'hrv');
h.files.set('sleep.jsonl',JSON.stringify({timeResolved:false,startMs:12})+'\n');
assert.equal(h.store.exportBatch({}).sleep.length,0);
});
test('concurrent ticks and changed credentials cannot incorrectly acknowledge a batch', async () => {
const h=setup();h.store.ingestSamples([sample]);let release;
h.configure({response:()=>new Promise(resolve=>{release=resolve;})});
const first=h.exporter.syncHealthExport();await h.exporter.syncHealthExport();
assert.equal(h.requests.length,1);
h.settings.set('health.export.generation','1');release({status:200,json:async()=>({accepted:true})});
await first;assert.equal(h.settings.has('health.export.cursor'),false);
});
test('large sleep histories split into bounded bodies without losing sessions', async () => {
const h=setup();
const sessions=Array.from({length:6},(_,i)=>({timeResolved:true,startMs:1700000000000+i*86400000,
endMs:1700028800000+i*86400000,dayStartMs:1699920000000+i*86400000,
totalSec:28000,wakeSec:800,remSec:4000,lightSec:18000,deepSec:6000,
segments:Array.from({length:2000},()=>({stageId:2,halfMinutes:1}))}));
h.files.set('sleep.jsonl',sessions.map(s=>JSON.stringify(s)+'\n').join(''));
for(let i=0;i<10;i++) await h.exporter.syncHealthExport();
assert.ok(h.requests.length>1);
assert.ok(h.requests.every(r=>r.options.body.length<=240000));
assert.equal(h.requests.reduce((n,r)=>n+JSON.parse(r.options.body).sleep.length,0),sessions.length);
});
test('point heart rates and hourly summaries export separately with original timestamps', async () => {
const h = setup();
const point = { ...sample, spanMs: 1, startMs: sample.startMs + 123456, min: 72, max: 72, avg: 72, total: 72 };
h.store.ingestSamples([sample, point]);
await h.exporter.syncHealthExport();
const body = JSON.parse(h.requests[0].options.body);
assert.deepEqual(body.samples, [sample, point]);
h.store.resetCache();
assert.equal(h.store.ingestSamples([point]), 0);
await h.exporter.syncHealthExport();
assert.equal(h.requests.length, 1);
});
test('a corrected point replaces its old value without changing hourly summaries', async () => {
const h = setup();
const point = { ...sample, spanMs: 1, min: 72, max: 72, avg: 72, total: 72 };
h.store.ingestSamples([sample, point]);
await h.exporter.syncHealthExport();
const correction = { ...point, min: 74, max: 74, avg: 74, total: 74 };
h.store.ingestSamples([correction]);
await h.exporter.syncHealthExport();
assert.deepEqual(JSON.parse(h.requests[1].options.body).samples, [correction]);
assert.equal(h.store.samplesInRange(sample.startMs, sample.startMs + 1, true).length, 2);
assert.equal(h.store.samplesInRange(sample.startMs, sample.startMs + 1)[0].avg, sample.avg);
});
@@ -1,48 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { convertRecords } = loader()('app/health/health-ingest.ts');
const receivedAtMs = Date.UTC(2026, 10, 8, 12);
const page = {
kind: 'hourly', metric: 'heartRate', anchorMs: receivedAtMs,
groups: [{ hourIndex: 0, min: 50, max: 90, avg: 65 }],
latest: { timestampSeconds: (receivedAtMs - 60000) / 1000, value: 72, receivedAtMs, clockOffsetMs: 0 },
};
test('latest observation remains a point, independent of hourly averages and page anchor', () => {
const result = convertRecords([{ ...page, anchorMs: null }]);
assert.equal(result.samples.length, 1);
assert.equal(result.samples[0].spanMs, 1);
assert.equal(result.samples[0].startMs, receivedAtMs - 60000);
assert.equal(result.samples[0].min, 72);
assert.equal(result.samples[0].max, 72);
assert.equal(result.samples[0].avg, 72);
});
test('legacy handshake timezone offset is inverted once, preserving exact timestamps', () => {
for (const clockOffsetMs of [-3600000, -7200000, 7 * 3600000, 0, -19800000]) {
const latest = { ...page.latest, clockOffsetMs,
timestampSeconds: (receivedAtMs - 60000 + clockOffsetMs) / 1000 };
const samples = convertRecords([{ ...page, latest }]).samples;
assert.equal(samples[0].startMs, receivedAtMs - 60000);
assert.equal(samples[1].spanMs, 3600000);
}
});
test('invalid, stale and future latest values never corrupt hourly history', () => {
for (const patch of [
{ value: 0 }, { value: -1 }, { value: 301 }, { value: NaN }, { value: 72.5 },
{ timestampSeconds: -1 }, { timestampSeconds: 0 }, { timestampSeconds: NaN },
{ timestampSeconds: receivedAtMs / 1000 + 121 },
{ timestampSeconds: receivedAtMs / 1000 - 1201 },
{ receivedAtMs: NaN }, { clockOffsetMs: NaN },
]) {
const result = convertRecords([{ ...page, latest: { ...page.latest, ...patch } }]);
assert.equal(result.samples.length, 1, JSON.stringify(patch));
assert.equal(result.samples[0].spanMs, 3600000);
assert.equal(result.skipped.length, 1);
}
for (const metric of ['spo2', 'hrv']) {
assert.equal(convertRecords([{ ...page, metric }]).samples.length, 1);
}
});
-53
View File
@@ -210,56 +210,3 @@ test("a failed journal replay is retried on the next sync and never blocks the l
live.syncLiveRecords();
assert.equal(failures, -1, "replay was not retried");
});
test("live latest heart rate retains measurement time and survives restart without duplicates", () => {
const measuredAt = Math.floor(Date.now() / 1000) * 1000 - 60_000;
function sync(previous, time) {
const env = liveEnvironment();
if (previous) for (const [name, text] of previous.files) env.files.set(name, text);
Object.assign(env.record, {
receivedAtMs: time + 60_000,
tagRaw: (time + new Date(time + 60_000).getTimezoneOffset() * 60_000) / 1000,
current: 72,
});
env.load("health-live").syncLiveRecords();
return env;
}
const first = sync(null, measuredAt);
const repeated = sync(first, measuredAt);
const next = sync(repeated, measuredAt + 600_000);
const store = next.load("health-store-files").healthStore();
const batch = store.exportBatch({});
const points = Array.from(batch.samples).filter(s => s.spanMs === 1);
assert.deepEqual(points.map(s => [s.startMs, s.avg]), [[measuredAt, 72], [measuredAt + 600_000, 72]]);
assert.equal(batch.samples.filter(s => s.spanMs === 3600000).length, 1);
assert.equal(store.samplesInRange(measuredAt - 86400000, measuredAt + 86400000).length, 1,
"existing health charts only see bucket samples");
const counts = () => Array.from(store.dailyRollups('heartRate', measuredAt - 86400000, measuredAt + 86400000).values()).reduce((n, r) => n + r.count, 0);
assert.equal(counts(), 1);
store.rebuildRollups();
assert.equal(counts(), 1, "rebuilding must not mix point readings with hourly aggregates");
});
test("aligned health collection requests all six ten-minute slots without timer drift", () => {
const { msUntilNextAlignedPull, ALIGNED_PULL_MINUTES } = liveEnvironment().load('health-live').__alignedPullInternals;
assert.deepEqual(Array.from(ALIGNED_PULL_MINUTES), [1, 11, 21, 31, 41, 51]);
for (const minute of ALIGNED_PULL_MINUTES) {
assert.equal(msUntilNextAlignedPull(new Date(2026, 10, 8, 12, minute, 0)), 600000);
assert.equal(msUntilNextAlignedPull(new Date(2026, 10, 8, 12, minute - 1, 30)), 30000);
}
assert.equal(msUntilNextAlignedPull(new Date(2026, 10, 8, 12, 59, 0)), 120000);
});
test("journal replay restores hourly history without assigning a clock to old point readings", () => {
const receivedAtMs = Math.floor(Date.now() / 1000) * 1000;
let replay;
const ringProtocol = { decodeFrameJournal: () => ({ size: () => 1, get: () => replay }) };
const env = liveEnvironment({ ringProtocol });
replay = { ...env.record, current: 80, receivedAtMs,
tagRaw: (receivedAtMs + new Date(receivedAtMs).getTimezoneOffset() * 60000) / 1000 };
env.files.set('/health/ring-frames.jsonl', 'synthetic journal');
env.load('health-live').syncLiveRecords();
const samples = env.load('health-store-files').healthStore().exportBatch({}).samples;
assert.equal(samples.length, 1);
assert.equal(samples[0].spanMs, 3600000);
});
+4 -2
View File
@@ -6,7 +6,8 @@ const ts = require('typescript');
const path = require('node:path');
// The provider settings ios-preview-controller hands the voice bridge.
const voiceSettings = { voiceProviderSetting: { get: () => 'onboard' }, elevenLabsApiKeySetting: { get: () => '' },
openAiApiKeySetting: { get: () => '' }, sonioxApiKeySetting: { get: () => '' },
getVoiceTranscriptionLanguage: () => '',
openAiTranscriptionModelSetting: { get: () => 'gpt-realtime-whisper' }, openAiApiKeySetting: { get: () => '' }, sonioxApiKeySetting: { get: () => '' },
whisperServerUrlSetting: { get: () => '' }, whisperServerModelSetting: { get: () => '' },
whisperServerLanguageSetting: { get: () => '' }, whisperServerApiKeySetting: { get: () => '' } };
function load(file, context) {
@@ -168,6 +169,7 @@ test('settings-driven repaint runs after font cache invalidation, regardless of
let cachedFont = 'Light';
const api = load('app/ui/dashboard-settings.ts', { global: { isIOS: true },
require: id => id.includes('settings-store') ? { onSettingsStoreChanged: fn => listeners.push(fn) }
: id.endsWith('/transcription-language') ? load('app/native/transcription-language.ts', {})
: { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] },
setTimeout: fn => tasks.push(fn),
});
@@ -384,7 +386,7 @@ test('iOS continuous capture is shared by windows and restarts after a disconnec
recordTo: name => { bridge.recording = name; },
setRawSession: session => { bridge.rawSession = session; } };
const settings = { ...voiceSettings, voiceProviderSetting: { get: () => 'whisper-server' },
whisperServerUrlSetting: { get: () => 'http://whisper.local:8000' }, whisperServerLanguageSetting: { get: () => 'en' },
whisperServerUrlSetting: { get: () => 'http://whisper.local:8000' }, getVoiceTranscriptionLanguage: () => 'en',
saveTranscribeAudioSetting: { get: () => true } };
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : id === '../ui/dashboard-settings' ? settings
@@ -0,0 +1,35 @@
package com.faceclaw.app
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class WhisperModelFilesTest {
@Test fun existingEnglishFilesRemainUsable() {
for (language in listOf(null, "en", " EN ")) {
val model = WhisperModelFiles.forLanguage(language)
assertTrue(model.englishOnly)
assertEquals("en", model.language)
assertEquals("sherpa-onnx-whisper-base-en-int8", model.dirName)
assertEquals(listOf("base.en-encoder.int8.onnx", "base.en-decoder.int8.onnx", "base.en-tokens.txt"), model.files)
}
}
@Test fun frenchAndOtherLanguagesUseMultilingualFiles() {
for (language in listOf("fr", "de", "ja", " FR ")) {
val model = WhisperModelFiles.forLanguage(language)
assertFalse(model.englishOnly)
assertEquals(language.trim().lowercase(), model.language)
assertEquals("sherpa-onnx-whisper-base-int8", model.dirName)
assertEquals(listOf("base-encoder.int8.onnx", "base-decoder.int8.onnx", "base-tokens.txt"), model.files)
}
}
@Test fun autoDetectionUsesMultilingualFilesWithAnEmptyLanguage() {
val model = WhisperModelFiles.forLanguage("")
assertFalse(model.englishOnly)
assertEquals("", model.language)
assertEquals(WhisperModelFiles.forLanguage("fr").files, model.files)
}
}
+1
View File
@@ -28,6 +28,7 @@
"../app/ui/menu-core.ts",
"../app/phone-ui/phone-gestures.ts",
"../app/native/java-direct-buffer.ts",
"../app/native/transcription-language.ts",
"../app/native/notification-types.ts",
"../app/g2/firmware-compat.ts",
"../app/g2/glasses-hardware-identity.ts",
+24 -2
View File
@@ -163,7 +163,8 @@ function androidBridge() {
starts: 0,
setListener(listener) { this.listener = listener; },
setCommunicator() {}, setUsePhoneMic() {}, setSaveRecordings() {}, setEndpointing() {},
setNoiseSuppression() {}, setBeamFilter() {}, clearSpeakerVerification() {}, setOnboardModelKind() {},
setNoiseSuppression() {}, setBeamFilter() {}, clearSpeakerVerification() {},
setOnboardModelKind(kind) { this.modelKind = kind; }, setOnboardLanguage(language) { this.language = language; },
start(_mode, id) { this.captureId = id; this.active = true; this.starts++; },
stop() { this.active = false; },
isCapturing() { return this.active; },
@@ -171,7 +172,8 @@ function androidBridge() {
const { FaceclawVoiceControlBridge } = load('app/native/voice-control.ts', {
'@nativescript/core': { Utils: { android: { getApplicationContext: () => ({}) } } },
'./speech-pause': { SpeechPauseDetector: class { reset() {} } },
'./cloud-stt-provider': { createCloudSttClient: () => null, transcriptionKey: options => options.provider },
'./cloud-stt-provider': { createCloudSttClient: () => null,
transcriptionKey: options => `${options.provider}:${options.language ?? (options.provider === 'onboard-whisper' ? 'en' : '')}` },
}, { global: { isAndroid: true }, com: { faceclaw: { app: {
FaceclawVoiceController: function () { return controller; },
FaceclawVoiceControllerListener: function (listener) { return listener; },
@@ -179,6 +181,26 @@ function androidBridge() {
return { bridge: new FaceclawVoiceControlBridge(), controller };
}
test('local Whisper receives French and restarts for auto or English, sharing an unchanged language', () => {
const { bridge, controller } = androidBridge();
bridge.startContinuousCapture({ provider: 'onboard-whisper', language: 'fr' });
assert.equal(controller.modelKind, 'whisper');
assert.equal(controller.language, 'fr');
bridge.startPushToTalk({ provider: 'onboard-whisper', language: 'fr' });
assert.equal(controller.starts, 1);
bridge.retargetContinuousCapture({ provider: 'onboard-whisper', language: '' });
assert.equal(controller.language, '');
assert.equal(controller.starts, 2);
bridge.retargetContinuousCapture({ provider: 'onboard-whisper' });
// An omitted language preserves the native bridge's original English behavior.
assert.equal(controller.language, 'en');
assert.equal(controller.starts, 3);
bridge.retargetContinuousCapture({ provider: 'onboard-whisper', language: 'en' });
assert.equal(controller.language, 'en');
assert.equal(controller.starts, 3);
bridge.stop();
});
test('native completion is capture-specific, follows the final, and does not wait for shared capture', async () => {
const { bridge, controller } = androidBridge();
const options = { provider: 'onboard-whisper' };
+146
View File
@@ -0,0 +1,146 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
function load(file, requireModule = () => ({}), globals = {}) {
const exports = {};
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, { exports, require: requireModule, console, global: { isAndroid: true }, ...globals });
return exports;
}
const languages = load('app/native/transcription-language.ts');
function settings(values = new Map()) {
return load('app/ui/dashboard-settings.ts', name => name.endsWith('/transcription-language') ? languages
: name.includes('settings-store') ? {
getStringSetting: (key, fallback) => values.get(key) ?? fallback,
setStringSetting: (key, value) => values.set(key, value),
getBooleanSetting: (_key, fallback) => fallback,
onSettingsStoreChanged() {},
} : { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] });
}
test('language defaults preserve local English, cloud detection and an existing server preference', () => {
const values = new Map([['voice.whisperServerLanguage', 'sk']]);
const s = settings(values);
assert.equal(s.voiceLanguageSetting.get(), 'default');
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), 'en');
assert.equal(s.getVoiceTranscriptionLanguage('whisper'), '');
assert.equal(s.getVoiceTranscriptionLanguage('whisper-server'), 'sk');
assert.deepEqual([...values], [['voice.whisperServerLanguage', 'sk']]);
});
test('French and auto-detection persist across restart without overwriting server exceptions', () => {
const values = new Map([['voice.whisperServerLanguage', 'sk']]);
let s = settings(values);
s.voiceLanguageSetting.set('fr');
s = settings(values);
assert.equal(s.voiceLanguageSetting.displayValue(), 'French');
for (const provider of ['whisper', 'onboard-whisper', 'whisper-server', 'elevenlabs', 'soniox']) {
assert.equal(s.getVoiceTranscriptionLanguage(provider), 'fr');
}
assert.equal(s.getVoiceTranscriptionLanguage('onboard'), '');
s.voiceLanguageSetting.set('auto');
s = settings(values);
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), '');
assert.equal(s.getVoiceTranscriptionLanguage('whisper'), '');
s.voiceLanguageSetting.set('default');
assert.equal(s.getVoiceTranscriptionLanguage('whisper-server'), 'sk');
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), 'en');
});
test('corrupt language preferences revert to the compatible provider defaults', () => {
const s = settings(new Map([['voice.language', 'invalid']]));
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), 'en');
assert.equal(s.getVoiceTranscriptionLanguage('whisper'), '');
});
test('Android and iOS capture options use the shared language and preserve Translate overrides', () => {
const s = settings();
s.voiceLanguageSetting.set('fr');
s.voiceProviderSetting.set('whisper');
s.openAiTranscriptionModelSetting.set('gpt-4o-mini-transcribe');
for (const [file, name, method] of [
['app/g2/dashboard-controller.ts', 'DashboardController', 'voiceCaptureOptions'],
['app/g2/ios-preview-controller.ts', 'IosPreviewController', 'voiceProvider'],
]) {
const host = { continuousClients: new Map() };
host.transcriptionChoice = () => [...host.continuousClients.values()].find(x => x.transcription)?.transcription;
// Run each real capture-options method with only its native dependencies stubbed.
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const tree = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
const declaration = tree.statements.find(n => ts.isClassDeclaration(n) && n.name.text === name);
const member = declaration.members.find(n => n.name?.getText(tree) === method);
const capture = loadBody(member.body.getText(tree), s, host);
assert.equal(capture().language, 'fr');
assert.equal(capture().openAiTranscriptionModel, 'gpt-4o-mini-transcribe');
host.continuousClients.set('translate', { transcription: { provider: 'soniox', language: 'ja' } });
assert.equal(capture().provider, 'soniox');
assert.equal(capture().language, 'ja');
host.continuousClients.clear();
assert.equal(capture().language, 'fr');
assert.equal(capture().openAiTranscriptionModel, 'gpt-4o-mini-transcribe');
}
});
function loadBody(body, s, host) {
const globals = { ...s, wearerVerificationOptions: () => null, micSession: { captureProcessingOptions: () => ({}) } };
return vm.runInNewContext(`(function(communicator) ${body})`, globals).bind(host, null);
}
test('multilingual downloads and deletion leave an existing English model intact', () => {
const files = new Map(), downloads = [];
const asr = load('app/native/asr-model.ts', () => ({
Utils: { android: { getApplicationContext: () => ({ getFilesDir: () => ({ getAbsolutePath: () => '/files' }) }) } },
}), {
java: { io: { File: class {
constructor(name) { this.name = name; }
exists() { return files.has(this.name); }
length() { return files.get(this.name) ?? 0; }
delete() { return files.delete(this.name); }
} } },
com: { faceclaw: { app: {
FaceclawModelDownloaderListener: function(listener) { return listener; },
FaceclawModelDownloader: class {
constructor(url, destination, hash, size, listener) {
Object.assign(this, { url, destination, hash, size, listener }); downloads.push(this);
}
start() {}
cancel() {}
},
} } },
});
const english = asr.ASR_MODELS['whisper-base-en'];
for (const file of english.files) files.set(`/files/faceclaw-voice-asr/${english.dirName}/${file.name}`, file.sizeBytes);
assert.equal(asr.isAsrModelReady('whisper-base-en'), true);
assert.equal(asr.isAsrModelReady('whisper-base'), false);
asr.startAsrModelDownload('whisper-base');
assert.equal(asr.asrModelState('whisper-base').status, 'downloading');
for (let index = 0; index < 3; index++) {
const download = downloads[index];
assert.match(download.url, /sherpa-onnx-whisper-base\/resolve\/[a-f0-9]{40}\/base-/);
assert.match(download.hash, /^[a-f0-9]{64}$/);
files.set(download.destination, download.size);
download.listener.onDone();
}
assert.equal(downloads.length, 3);
assert.equal(asr.isAsrModelReady('whisper-base'), true);
asr.deleteAsrModel('whisper-base');
assert.equal(asr.isAsrModelReady('whisper-base'), false);
assert.equal(asr.isAsrModelReady('whisper-base-en'), true);
});
test('OpenAI transcription model preserves legacy default and persists independently of language', () => {
const values = new Map();
let s = settings(values);
assert.equal(s.openAiTranscriptionModelSetting.get(), 'gpt-realtime-whisper');
s.openAiTranscriptionModelSetting.set('gpt-4o-mini-transcribe');
s.voiceLanguageSetting.set('fr');
s = settings(values);
assert.equal(s.openAiTranscriptionModelSetting.get(), 'gpt-4o-mini-transcribe');
assert.equal(s.voiceLanguageSetting.get(), 'fr');
assert.equal(settings(new Map([['voice.openAiTranscriptionModel', 'invalid']])).openAiTranscriptionModelSetting.get(), 'gpt-realtime-whisper');
});