forked from Blendman974/faceclaw
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6208b55c56 | ||
|
|
a9df3de59b | ||
|
|
3eb9b09e3d
|
||
|
|
3dd307483d | ||
|
|
9ca3574ae7 | ||
|
|
54ba6b4f10
|
||
|
|
b4b073412f
|
||
|
|
ceeadea9bf |
No files matched your search
@@ -231,17 +231,16 @@ class FaceclawBleManager(context: Context) {
|
||||
fun connect(address: String?, timeoutMs: Int): Boolean = connect(address, timeoutMs, false)
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL (2026-09-11): the ring specifically needs autoConnect=true.
|
||||
* Even's own vendor app connects the ring with Android's autoConnect flag
|
||||
* set (confirmed via its own BLE debug log, "connect() - device: ...,
|
||||
* auto: true"), while every other faceclaw connection (both glasses arms)
|
||||
* uses autoConnect=false. Direct connect (false) is faster to establish
|
||||
* but Android supervises it less patiently; a live test showed the
|
||||
* ring-only direct connection dying almost exactly 5 seconds in,
|
||||
* repeatedly, with nothing else competing for it. autoConnect=true can
|
||||
* take much longer to actually complete (Android manages it as a
|
||||
* background reconnect, not an immediate attempt), so this needs its own
|
||||
* longer timeout. Like [connect], waits on an attempt already pending.
|
||||
* autoConnect=true is used for the ring and both glasses arms. The ring specifically
|
||||
* needs it (Even's own vendor app connects the ring with Android's autoConnect flag
|
||||
* set, confirmed via its own BLE debug log, "connect() - device: ...,
|
||||
* auto: true"). A live test showed a ring-only direct connection dying almost
|
||||
* exactly 5 seconds in, repeatedly, with nothing else competing for it, and the
|
||||
* glasses arms showed the same "less patiently supervised" direct-connect drop.
|
||||
* Direct connect (false) is faster to establish but Android supervises it less
|
||||
* patiently. autoConnect=true can take much longer to actually complete (Android
|
||||
* manages it as a background reconnect, not an immediate attempt), so it needs its
|
||||
* own longer timeout. Like [connect], waits on an attempt already pending.
|
||||
*/
|
||||
fun connect(address: String?, timeoutMs: Int, autoConnect: Boolean): Boolean {
|
||||
val key = requireAddress(address)
|
||||
|
||||
+24
-1
@@ -125,6 +125,27 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
return "connecting"
|
||||
}
|
||||
|
||||
/** Fresh, read-only phone DND state; unavailable filters retain normal wake behavior. */
|
||||
@JvmStatic
|
||||
fun isPhoneDoNotDisturbEnabled(context: Context?): Boolean {
|
||||
val filter = try {
|
||||
val manager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
|
||||
manager?.currentInterruptionFilter
|
||||
} catch (t: Throwable) {
|
||||
null
|
||||
} ?: try {
|
||||
activeService?.currentInterruptionFilter
|
||||
} catch (t: Throwable) {
|
||||
null
|
||||
}
|
||||
return when (filter) {
|
||||
NotificationManager.INTERRUPTION_FILTER_PRIORITY,
|
||||
NotificationManager.INTERRUPTION_FILTER_NONE,
|
||||
NotificationManager.INTERRUPTION_FILTER_ALARMS -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
/** Run on the main thread whenever getListenerState may have changed. */
|
||||
@JvmStatic
|
||||
fun addListenerStateObserver(observer: Runnable?) {
|
||||
@@ -517,7 +538,9 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
|
||||
private fun emitNotificationPosted(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||
// Capture before mainHandler posting: a later DND change must not alter this arrival.
|
||||
val canWakeScreen = !isPhoneDoNotDisturbEnabled(activeService)
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey, canWakeScreen) }
|
||||
}
|
||||
|
||||
private fun emitNotificationRemoved(key: String?) {
|
||||
|
||||
@@ -74,6 +74,7 @@ class FaceclawVoiceController(context: Context) {
|
||||
@Volatile
|
||||
private var communicator: FaceclawBleCommunicator? = null
|
||||
private var whisperModel = WhisperModelFiles.forLanguage(null)
|
||||
private var frenchWhisper = false
|
||||
|
||||
private val host = object : VoiceCaptureHost {
|
||||
override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } }
|
||||
@@ -160,9 +161,15 @@ class FaceclawVoiceController(context: Context) {
|
||||
session.setOnboardModelKind(kind)
|
||||
}
|
||||
|
||||
/** Select the dedicated French fine-tune before setting the capture language. */
|
||||
fun setFrenchWhisper(enabled: Boolean) {
|
||||
frenchWhisper = enabled
|
||||
whisperModel = WhisperModelFiles.forSelection(whisperModel.language, enabled)
|
||||
}
|
||||
|
||||
/** Language for the next on-device Whisper capture; empty enables auto-detection. */
|
||||
fun setOnboardLanguage(language: String?) {
|
||||
whisperModel = WhisperModelFiles.forLanguage(language)
|
||||
whisperModel = WhisperModelFiles.forSelection(language, frenchWhisper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,7 +96,8 @@ export function createEvenHubWindow(
|
||||
})),
|
||||
// Glasses-first: the app runs without the phone showing it; this reveals
|
||||
// its phone UI (config pages, etc.) over the dashboard on demand.
|
||||
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
||||
...(session.manifest.packageId === "dev.guillaume.evenanchor" && session.contextMenuItems().length > 0
|
||||
? [] : [{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } }]),
|
||||
],
|
||||
actions: options.actions,
|
||||
baseLayer: appLayer,
|
||||
|
||||
@@ -16,6 +16,7 @@ import { mediaControllerBridge } from "../native/media-controller";
|
||||
import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||
import { weatherBridge } from "../native/weather";
|
||||
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
|
||||
import { isPhoneDoNotDisturbEnabled } from "../native/phone-do-not-disturb";
|
||||
import { watchNotificationListenerBinding } from "../native/notification-access";
|
||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
|
||||
@@ -364,7 +365,7 @@ class DashboardController {
|
||||
private offAndroidNotification: (() => void) | null = null;
|
||||
private offAndroidNotificationRemoved: (() => void) | null = null;
|
||||
/** New notifications wait here briefly before popping up (see NotificationPopupDelay). */
|
||||
private readonly notificationPopups = new NotificationPopupDelay((notificationKey) => this.popUpAndroidNotification(notificationKey));
|
||||
private readonly notificationPopups = new NotificationPopupDelay((notificationKey, canWakeScreen) => this.popUpAndroidNotification(notificationKey, canWakeScreen));
|
||||
private lastInput = "waiting...";
|
||||
private lastSys = "none yet";
|
||||
private shellRenderInProgress = false;
|
||||
@@ -472,7 +473,7 @@ class DashboardController {
|
||||
app.boot?.(this.buildAppContext(app));
|
||||
}
|
||||
timerEngine.onChange(() => this.refreshAlarmReliabilityWarning());
|
||||
this.offAndroidNotification = onAndroidNotificationPosted((notificationKey) => this.handleAndroidNotificationPosted(notificationKey));
|
||||
this.offAndroidNotification = onAndroidNotificationPosted((notificationKey, canWakeScreen) => this.handleAndroidNotificationPosted(notificationKey, canWakeScreen));
|
||||
this.offAndroidNotificationRemoved = onAndroidNotificationRemoved((notificationKey) => this.handleAndroidNotificationRemoved(notificationKey));
|
||||
watchNotificationListenerBinding();
|
||||
readActiveNotifications(ALL_NOTIFICATIONS);
|
||||
@@ -3008,12 +3009,13 @@ class DashboardController {
|
||||
this.schedulePreviewUpdate();
|
||||
}
|
||||
|
||||
private handleAndroidNotificationPosted(notificationKey: string): void {
|
||||
private handleAndroidNotificationPosted(notificationKey: string, canWakeScreen = true): void {
|
||||
// The tray shows the notification at once; its popup waits out a short
|
||||
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
||||
if (notification && shouldPopUpNewNotification(notification.packageName)) {
|
||||
this.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification));
|
||||
this.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification),
|
||||
canWakeScreen && !isPhoneDoNotDisturbEnabled());
|
||||
}
|
||||
this.requestShellRender();
|
||||
}
|
||||
@@ -3031,10 +3033,13 @@ class DashboardController {
|
||||
}
|
||||
|
||||
/** A posted notification waited out its popup delay: show it, if it is still there. */
|
||||
private popUpAndroidNotification(notificationKey: string): void {
|
||||
private popUpAndroidNotification(notificationKey: string, canWakeScreen = true): void {
|
||||
try {
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
||||
if (!notification || !shouldPopUpNewNotification(notification.packageName)) return;
|
||||
// Keep the arrival-time restriction and re-check DND immediately before
|
||||
// waking: a delayed popup must neither outlive DND nor bypass a new DND.
|
||||
if (!shell.isScreenOn() && (!canWakeScreen || isPhoneDoNotDisturbEnabled())) return;
|
||||
// New notifications open a shell modal over the app viewport; if the
|
||||
// screen was off, wake for it and go back to sleep when it is closed.
|
||||
// Waking while already on would steal focus, so only wake from sleep.
|
||||
|
||||
+18
-1
@@ -34,12 +34,15 @@ declare const java: any;
|
||||
* SHA-256/size values come from the maintainer's LFS metadata, with the
|
||||
* vocabulary hash computed locally. URLs pin the source revision.
|
||||
*
|
||||
* - "whisper-small-fr": a dedicated French fine-tune, exported and quantized
|
||||
* with sherpa-onnx 1.13.0. Versioned release assets include its Apache license.
|
||||
*
|
||||
* 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" | "whisper-base";
|
||||
export type AsrModelId = "moonshine" | "whisper-base-en" | "whisper-base" | "whisper-small-fr";
|
||||
|
||||
type AsrModelFile = {
|
||||
name: string;
|
||||
@@ -134,6 +137,19 @@ export const ASR_MODELS: Record<AsrModelId, AsrModelDef> = {
|
||||
],
|
||||
totalBytes: 160609290,
|
||||
},
|
||||
"whisper-small-fr": {
|
||||
label: "Whisper (French, small)",
|
||||
dirName: "sherpa-onnx-whisper-small-fr-int8-v1",
|
||||
// Pinned export of bofenghuang/whisper-small-cv11-french; see docs/models/whisper-small-fr.
|
||||
baseUrl: "https://git.undefined-dev.fr/api/packages/Blendman974/generic/faceclaw-asr/whisper-small-fr-v1/",
|
||||
files: [
|
||||
{"name": "small-fr-encoder.int8.onnx", "sha256": "ec34fc42182f37727ad982d254b18a6001f5dcccebc5a36060031995f1782d5d", "sizeBytes": 112413414},
|
||||
{"name": "small-fr-decoder.int8.onnx", "sha256": "b554e35dc8c593b550a82cd01ebb00c1347e8c2b089b780b4c4fe16450cd7dc0", "sizeBytes": 262200764},
|
||||
{"name": "small-fr-tokens.txt", "sha256": "b34b360dbb493e781e479794586d661700670d65564001f23024971d1f2fa126", "sizeBytes": 816730},
|
||||
{"name": "LICENSE.txt", "sha256": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30", "sizeBytes": 11358},
|
||||
],
|
||||
totalBytes: 375442266,
|
||||
},
|
||||
};
|
||||
|
||||
export type AsrModelState = {
|
||||
@@ -159,6 +175,7 @@ const runtimes: Record<AsrModelId, ModelRuntime> = {
|
||||
moonshine: freshRuntime(),
|
||||
"whisper-base-en": freshRuntime(),
|
||||
"whisper-base": freshRuntime(),
|
||||
"whisper-small-fr": freshRuntime(),
|
||||
};
|
||||
|
||||
function modelDirPath(id: AsrModelId): string {
|
||||
|
||||
@@ -78,9 +78,10 @@ function isConfigured(provider: CloudProvider, selection: VoiceProviderSelection
|
||||
* to expect. A running capture is shared only by holders asking for the same.
|
||||
*/
|
||||
export function transcriptionKey(selection: Pick<VoiceProviderSelection, "provider" | "language" | "openAiTranscriptionModel">): string {
|
||||
const fallback = selection.provider === "onboard-whisper" ? "en" : "";
|
||||
const fallback = selection.provider === "onboard-whisper-fr" ? "fr" : selection.provider === "onboard-whisper" ? "en" : "";
|
||||
const language = selection.provider === "onboard-whisper-fr" ? "fr" : (selection.language ?? fallback).trim().toLowerCase();
|
||||
const model = selection.provider === "whisper" ? `:${selection.openAiTranscriptionModel ?? DEFAULT_OPENAI_STT_MODEL}` : "";
|
||||
return `${selection.provider}:${(selection.language ?? fallback).trim().toLowerCase()}${model}`;
|
||||
return `${selection.provider}:${language}${model}`;
|
||||
}
|
||||
|
||||
/** Whether createCloudSttClient would return a cloud client for this selection. */
|
||||
|
||||
@@ -26,7 +26,7 @@ let cachedAtMs = 0;
|
||||
const keyedIconCache = new Map<string, { icon: GrayImage | null; atMs: number }>();
|
||||
const KEYED_ICON_CACHE_MAX = 128;
|
||||
let notificationListenerProxy: any = null;
|
||||
const notificationPostedListeners = new Set<(notificationKey: string) => void>();
|
||||
const notificationPostedListeners = new Set<(notificationKey: string, canWakeScreen?: boolean) => void>();
|
||||
const notificationRemovedListeners = new Set<(notificationKey: string) => void>();
|
||||
let listenerStateObserver: any = null;
|
||||
const listenerStateListeners = new Set<() => void>();
|
||||
@@ -358,7 +358,7 @@ export function dismissAllNotifications(): boolean {
|
||||
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissAllNotifications());
|
||||
}
|
||||
|
||||
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
|
||||
export function onAndroidNotificationPosted(listener: (notificationKey: string, canWakeScreen?: boolean) => void): () => void {
|
||||
return addNotificationListener(notificationPostedListeners, listener);
|
||||
}
|
||||
|
||||
@@ -412,8 +412,8 @@ function onListenerStateChanged(listener: () => void): () => void {
|
||||
}
|
||||
|
||||
function addNotificationListener(
|
||||
listeners: Set<(notificationKey: string) => void>,
|
||||
listener: (notificationKey: string) => void,
|
||||
listeners: Set<(notificationKey: string, canWakeScreen?: boolean) => void>,
|
||||
listener: (notificationKey: string, canWakeScreen?: boolean) => void,
|
||||
): () => void {
|
||||
listeners.add(listener);
|
||||
ensureNativeNotificationListener();
|
||||
@@ -458,8 +458,8 @@ function normalizeNotification(value: any): AndroidNotification | null {
|
||||
function ensureNativeNotificationListener(): void {
|
||||
if (!global.isAndroid || notificationListenerProxy) return;
|
||||
notificationListenerProxy = new com.faceclaw.app.FaceclawNotificationListener({
|
||||
onNotificationPosted: (notificationKey: string) => {
|
||||
dispatchNotificationEvent(notificationPostedListeners, notificationKey);
|
||||
onNotificationPosted: (notificationKey: string, canWakeScreen?: boolean) => {
|
||||
dispatchNotificationEvent(notificationPostedListeners, notificationKey, canWakeScreen);
|
||||
},
|
||||
onNotificationRemoved: (notificationKey: string) => {
|
||||
dispatchNotificationEvent(notificationRemovedListeners, notificationKey);
|
||||
@@ -470,13 +470,21 @@ function ensureNativeNotificationListener(): void {
|
||||
);
|
||||
}
|
||||
|
||||
function dispatchNotificationEvent(listeners: Set<(notificationKey: string) => void>, notificationKey: string): void {
|
||||
function dispatchNotificationEvent(
|
||||
listeners: Set<(notificationKey: string, canWakeScreen?: boolean) => void>,
|
||||
notificationKey: string,
|
||||
canWakeScreen = true,
|
||||
): void {
|
||||
invalidateIconCaches();
|
||||
const key = String(notificationKey);
|
||||
const snapshot = Array.from(listeners);
|
||||
setTimeout(() => {
|
||||
for (const listener of snapshot) {
|
||||
listener(key);
|
||||
if (listeners === notificationPostedListeners) {
|
||||
listener(key, canWakeScreen);
|
||||
} else {
|
||||
listener(key);
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Utils } from "@nativescript/core";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
/** Read the phone's current interruption filter; never change its DND policy. */
|
||||
export function isPhoneDoNotDisturbEnabled(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
try {
|
||||
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.isPhoneDoNotDisturbEnabled(
|
||||
Utils.android.getApplicationContext(),
|
||||
));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ export type TranscriptionLanguage = "default" | "auto" | keyof typeof TRANSCRIPT
|
||||
export function resolveTranscriptionLanguage(
|
||||
choice: TranscriptionLanguage, provider: string, serverLanguage = "",
|
||||
): string {
|
||||
if (provider === "onboard-whisper-fr") return "fr";
|
||||
// Moonshine is English-only; Apple's on-device recognizer retains its own locale.
|
||||
if (provider === "onboard") return "";
|
||||
if (choice === "default") {
|
||||
|
||||
@@ -32,7 +32,7 @@ export type VoiceControlState = {
|
||||
// renamed, since it's a persisted settings value on real installs already.
|
||||
// "whisper-server" is a self-hosted OpenAI-compatible Whisper over HTTP
|
||||
// (whisper-server-stt.ts).
|
||||
export type VoiceProviderKind = "onboard" | "onboard-whisper" | "elevenlabs" | "whisper" | "soniox" | "whisper-server";
|
||||
export type VoiceProviderKind = "onboard" | "onboard-whisper" | "onboard-whisper-fr" | "elevenlabs" | "whisper" | "soniox" | "whisper-server";
|
||||
|
||||
export type VoiceTranscriptEvent = CloudSttTranscriptEvent & {
|
||||
/**
|
||||
@@ -397,8 +397,10 @@ export class FaceclawVoiceControlBridge {
|
||||
this.started = true;
|
||||
// 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 frenchWhisper = options.provider === "onboard-whisper-fr";
|
||||
this.controller?.setOnboardModelKind(options.provider === "onboard-whisper" || frenchWhisper ? "whisper" : "moonshine");
|
||||
this.controller?.setFrenchWhisper(frenchWhisper);
|
||||
this.controller?.setOnboardLanguage(frenchWhisper ? "fr" : options.language ?? "en");
|
||||
const captureId = this.nextNativeCaptureId++;
|
||||
this.nativeCaptureFinished = new Promise((resolve) => { this.nativeCaptureResolvers.set(captureId, resolve); });
|
||||
this.controller?.start("onboard", captureId);
|
||||
|
||||
@@ -1078,13 +1078,14 @@ export function effectiveRingConnectionMode(): RingConnectionMode {
|
||||
// keeps its name (it's a persisted setting on real installs) but its label
|
||||
// below now says "OpenAI" to tell the two apart in the picker.
|
||||
// "whisper-server" is a self-hosted OpenAI-compatible Whisper (e.g. vLLM).
|
||||
export type VoiceProvider = "onboard" | "onboard-whisper" | "elevenlabs" | "whisper" | "soniox" | "whisper-server";
|
||||
export type VoiceProvider = "onboard" | "onboard-whisper" | "onboard-whisper-fr" | "elevenlabs" | "whisper" | "soniox" | "whisper-server";
|
||||
|
||||
// On iOS "onboard" is Apple's on-device recognizer, and there is no
|
||||
// "onboard-whisper" (the sherpa-onnx models are Android-only).
|
||||
const voiceProviderLabels: Record<VoiceProvider, string> = {
|
||||
onboard: global.isIOS ? "On-device (Apple)" : "On-device (Moonshine)",
|
||||
"onboard-whisper": "On-device (Whisper)",
|
||||
"onboard-whisper-fr": "On-device (Whisper French)",
|
||||
elevenlabs: "ElevenLabs",
|
||||
whisper: "OpenAI (Whisper)",
|
||||
soniox: "Soniox",
|
||||
@@ -1098,7 +1099,7 @@ export const voiceProviderSetting = new ConfigSettingEnum<VoiceProvider>({
|
||||
defaultValue: "onboard",
|
||||
values: global.isIOS
|
||||
? ["onboard", "elevenlabs", "whisper", "soniox", "whisper-server"]
|
||||
: ["onboard", "onboard-whisper", "elevenlabs", "whisper", "soniox", "whisper-server"],
|
||||
: ["onboard", "onboard-whisper", "onboard-whisper-fr", "elevenlabs", "whisper", "soniox", "whisper-server"],
|
||||
formatValue: (value) => voiceProviderLabels[value] ?? value,
|
||||
isDisabled: (value) => {
|
||||
if (value === "elevenlabs") return elevenLabsApiKeySetting.get().trim().length === 0;
|
||||
@@ -1109,7 +1110,7 @@ export const voiceProviderSetting = new ConfigSettingEnum<VoiceProvider>({
|
||||
},
|
||||
description: global.isIOS
|
||||
? "Speech-to-text engine for voice input. ElevenLabs, OpenAI, and Soniox are cloud services that need an API key (Settings > API Keys), with significantly better accuracy than on-device transcription. Whisper server is your own OpenAI-compatible Whisper (set its URL below). On-device uses your iPhone's speech language and never leaves the phone."
|
||||
: "Speech-to-text engine for voice input. ElevenLabs, OpenAI, and Soniox are cloud services that need an API key, with significantly better accuracy than on-device transcription. Whisper server is your own OpenAI-compatible Whisper (set its URL below). The two On-device options need their voice model downloaded (below) and never leave the phone.",
|
||||
: "Speech-to-text engine for voice input. ElevenLabs, OpenAI, and Soniox are cloud services that need an API key, with significantly better accuracy than on-device transcription. Whisper server is your own OpenAI-compatible Whisper (set its URL below). The On-device options need their voice model downloaded (below) and never leave the phone. Whisper French uses the French-only small model and always transcribes in French.",
|
||||
});
|
||||
|
||||
const wakeWordActionLabels: Record<WakeWordAction, string> = {
|
||||
@@ -1351,7 +1352,7 @@ export const voiceLanguageSetting = new ConfigSettingEnum<TranscriptionLanguage>
|
||||
: 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.",
|
||||
"On-device Whisper needs the multilingual model for auto-detection or languages other than English. The dedicated Whisper French provider always uses French, without changing this preference. Moonshine remains English-only.",
|
||||
});
|
||||
|
||||
export function getVoiceTranscriptionLanguage(provider: VoiceProvider): string {
|
||||
|
||||
@@ -173,6 +173,7 @@ function settingsSections(): SettingsSection[] {
|
||||
asrModelMenuItem("moonshine"),
|
||||
asrModelMenuItem("whisper-base-en"),
|
||||
asrModelMenuItem("whisper-base"),
|
||||
asrModelMenuItem("whisper-small-fr"),
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -33,11 +33,11 @@ export const scheduleTimeout: ScheduleFn = (run, delayMs) => {
|
||||
};
|
||||
|
||||
export class NotificationPopupDelay {
|
||||
private readonly pending = new Map<string, { dueAtMs: number; cancel: () => void }>();
|
||||
private readonly pending = new Map<string, { dueAtMs: number; cancel: () => void; wakePolicy: { canWakeScreen: boolean } }>();
|
||||
|
||||
/** `ready` receives each notification that survived its delay, to re-check and pop up. */
|
||||
constructor(
|
||||
private readonly ready: (notificationKey: string) => void,
|
||||
private readonly ready: (notificationKey: string, canWakeScreen: boolean) => void,
|
||||
private readonly schedule: ScheduleFn = scheduleTimeout,
|
||||
private readonly now: () => number = Date.now,
|
||||
) {}
|
||||
@@ -49,18 +49,22 @@ export class NotificationPopupDelay {
|
||||
* foreground-service placeholder into a real message (same key) gets the
|
||||
* shorter delay.
|
||||
*/
|
||||
post(notificationKey: string, delayMs: number): void {
|
||||
post(notificationKey: string, delayMs: number, canWakeScreen = true): void {
|
||||
const dueAtMs = this.now() + delayMs;
|
||||
const existing = this.pending.get(notificationKey);
|
||||
// Share this object with an existing timer: a repost may restrict wake,
|
||||
// but cannot turn a DND-silenced pending notification into a fresh alert.
|
||||
const wakePolicy = existing?.wakePolicy ?? { canWakeScreen: true };
|
||||
wakePolicy.canWakeScreen = wakePolicy.canWakeScreen && canWakeScreen;
|
||||
if (existing) {
|
||||
if (existing.dueAtMs <= dueAtMs) return;
|
||||
existing.cancel();
|
||||
}
|
||||
const cancel = this.schedule(() => {
|
||||
this.pending.delete(notificationKey);
|
||||
this.ready(notificationKey);
|
||||
this.ready(notificationKey, wakePolicy.canWakeScreen);
|
||||
}, delayMs);
|
||||
this.pending.set(notificationKey, { dueAtMs, cancel });
|
||||
this.pending.set(notificationKey, { dueAtMs, cancel, wakePolicy });
|
||||
}
|
||||
|
||||
/** The notification went away before popping up; returns whether it was waiting. */
|
||||
|
||||
@@ -75,6 +75,7 @@ import { ShellModalLayer } from "./modal-layer";
|
||||
import { NotificationModalQueue } from "./notification-modal-queue";
|
||||
import { NotificationPopupTimeout } from "./notification-popup-timeout";
|
||||
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../../native/notification-icons";
|
||||
import { isPhoneDoNotDisturbEnabled } from "../../native/phone-do-not-disturb";
|
||||
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||
import type { InProcessWindow } from "./in-process-window";
|
||||
import { BrightnessPickerLayer } from "./brightness-picker-layer";
|
||||
@@ -939,6 +940,7 @@ class Shell {
|
||||
* shown: in the notification modal, waking the screen for it if it was off.
|
||||
*/
|
||||
postAppNotification(notification: AppNotification): void {
|
||||
if (!this.screenOn && isPhoneDoNotDisturbEnabled()) return;
|
||||
this.appNotifications.set(notification.key, notification);
|
||||
const wokeScreen = this.screenOn ? false : this.wake("sidebar");
|
||||
this.openNotificationModal(notification.key, wokeScreen);
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,71 @@
|
||||
# On-device Whisper French
|
||||
|
||||
Android Settings → Voice now offers `On-device (Whisper French)` and a separate
|
||||
`On-device model: Whisper (French, small)` download (~375 MB decimal). Download
|
||||
first, then choose the provider. Recognition stays on the phone; no API key is
|
||||
required. This is speech-to-text in French, not translation.
|
||||
|
||||
This provider always requests `language=fr`, `task=transcribe`, without writing
|
||||
the shared language preference. Switching back to existing Moonshine, English
|
||||
Whisper or multilingual Whisper restores their previous behavior. Downloads,
|
||||
cancellation/resume and deletion reuse the existing model manager and leave
|
||||
other model directories untouched. Missing French files do not silently select
|
||||
multilingual base. iOS and the Microphones app's separate Moonshine caption
|
||||
engine are outside this addition.
|
||||
|
||||
## Provenance and distribution
|
||||
|
||||
- Source: https://huggingface.co/bofenghuang/whisper-small-cv11-french
|
||||
- Pinned revision: `83d7df2928fb2218721c543dcc0be29ef8db2f96`.
|
||||
- The model author's declared license is Apache-2.0; `LICENSE.txt` is distributed
|
||||
with the downloadable model. The original Whisper implementation is MIT;
|
||||
sherpa-onnx's exporter is Apache-2.0.
|
||||
- Exporter: sherpa-onnx v1.13.0 `scripts/whisper/export-onnx.py`.
|
||||
- Export: strict tensor-name conversion from HF Whisper to OpenAI Whisper,
|
||||
then upstream sherpa tensor-cache export, opset 17, dynamic int8 MatMul.
|
||||
- Assets: https://git.undefined-dev.fr/Blendman974/faceclaw/releases/tag/models-whisper-small-fr-v1
|
||||
- Model files use the public Gitea generic package registry (`faceclaw-asr`,
|
||||
version `whisper-small-fr-v1`), because the encoder and decoder exceed the
|
||||
instance’s 100 MB attachment limit. No infrastructure limit is changed.
|
||||
- The JSON manifest records file lengths and SHA-256 hashes. Both the source
|
||||
checkpoint and exporter are checksum-verified before execution. The existing
|
||||
Android downloader checks each downloaded asset against its pinned hash.
|
||||
- Only encoder, decoder, vocabulary and license are downloaded to the phone;
|
||||
the original checkpoint and unquantized intermediate models are not shipped.
|
||||
|
||||
## Reproducing the export
|
||||
|
||||
Use an isolated Python environment with the versions used for this release:
|
||||
Python 3.14, torch 2.9.0+cpu (CPU wheel index), openai-whisper 20250625,
|
||||
onnx 1.23.2, onnxruntime 1.31.1 and sherpa-onnx 1.13.0. These are development
|
||||
requirements only; no Python or additional runtime is added to the app.
|
||||
On NixOS expose the host C++ runtime and zlib through LD_LIBRARY_PATH.
|
||||
|
||||
```sh
|
||||
python tools/export-whisper-small-fr.py --output /tmp/whisper-small-fr
|
||||
python tools/test-whisper-small-fr.py \
|
||||
--model-dir /tmp/whisper-small-fr --wav /path/to/french-test.wav
|
||||
```
|
||||
|
||||
The exporter downloads the pinned source (~484 MB), writes unquantized and
|
||||
quantized intermediate models, and produces `manifest.json`. Artifact changes
|
||||
require a new versioned release and explicit catalog hash changes; never replace
|
||||
v1 assets in place. These scripts do not upload or publish files automatically.
|
||||
|
||||
## Validation
|
||||
|
||||
The exported int8 files were actually decoded on CPU with sherpa-onnx 1.13.0,
|
||||
the same version used by Android. A public 4.97-second French sample from
|
||||
`csukuangfj/sherpa-onnx-nemo-parakeet-tdt-0.6b-v3/test_wavs/fr.wav` produced:
|
||||
|
||||
> Ne vous demandez pas ce que votre pays peut faire pour vous, demandez-vous plutôt ce que vous pouvez faire pour lui.
|
||||
|
||||
This is a smoke test, not a recognition-quality benchmark or a measurement of
|
||||
Pixel latency. Application tests cover provider persistence, French selection
|
||||
without rewriting other languages, switching back, capture sharing, interrupted
|
||||
download/resume, file hashes and independent deletion. Kotlin tests cover the
|
||||
native file selection and preservation of existing filenames/defaults.
|
||||
|
||||
Hardware checks remain pending: real French dictation through phone and glasses
|
||||
microphones, latency and RAM on the Pixel, airplane-mode use after downloading,
|
||||
reconnection and long utterances. No firmware changes are required.
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"source": "bofenghuang/whisper-small-cv11-french",
|
||||
"revision": "83d7df2928fb2218721c543dcc0be29ef8db2f96",
|
||||
"sourceSha256": "855a879fa3a71e75f29ed59fcfce287cf21bcdaab23530cd6f8c4ad192677afb",
|
||||
"exporterSha256": "5e0ddabfac8330ee9aecaba4c1b4286d1cd9f88df4cd30e54706b011bf976e45",
|
||||
"torchVersion": "2.9.0+cpu",
|
||||
"files": [
|
||||
{
|
||||
"name": "small-fr-encoder.int8.onnx",
|
||||
"sha256": "ec34fc42182f37727ad982d254b18a6001f5dcccebc5a36060031995f1782d5d",
|
||||
"sizeBytes": 112413414
|
||||
},
|
||||
{
|
||||
"name": "small-fr-decoder.int8.onnx",
|
||||
"sha256": "b554e35dc8c593b550a82cd01ebb00c1347e8c2b089b780b4c4fe16450cd7dc0",
|
||||
"sizeBytes": 262200764
|
||||
},
|
||||
{
|
||||
"name": "small-fr-tokens.txt",
|
||||
"sha256": "b34b360dbb493e781e479794586d661700670d65564001f23024971d1f2fa126",
|
||||
"sizeBytes": 816730
|
||||
},
|
||||
{
|
||||
"name": "LICENSE.txt",
|
||||
"sha256": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30",
|
||||
"sizeBytes": 11358
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
# Phone Do Not Disturb and notification wake
|
||||
|
||||
## Behavior
|
||||
|
||||
Faceclaw automatically follows **Android's current Do Not Disturb interruption
|
||||
filter** for notification-triggered screen wake. No separate Faceclaw setting or
|
||||
notification-policy modification is needed.
|
||||
|
||||
- Phone DND active and glasses asleep: a mirrored notification does **not** wake
|
||||
the glasses or open a sleeping-screen popup. The notification is not dismissed
|
||||
on the phone and stays available in the Notifications app/status tray.
|
||||
- Glasses already awake: popups keep their normal behavior, including the visible
|
||||
app background and the existing source filters/display timeout. DND does not
|
||||
force an awake screen off or steal focus.
|
||||
- DND off: new eligible notifications wake normally. Silenced notifications are
|
||||
not kept in a wake backlog and disabling DND does not replay them.
|
||||
- Priority-only, total-silence and alarms-only filters all count as DND. Android
|
||||
priority exceptions do not make a mirrored notification wake the glasses.
|
||||
- App-generated notification popups also respect DND while asleep, including
|
||||
Nightscout alerts; those local-only popups are not retained for replay. The
|
||||
dedicated Timers alarm engine and manual/ring/head-up wake are unchanged.
|
||||
- iOS Focus/DND synchronization is **not implemented** by this Android reader;
|
||||
the non-Android reader returns false and preserves existing behavior.
|
||||
|
||||
Reading the filter is read-only. No setter, policy-access permission request,
|
||||
new broadcast receiver or polling loop is introduced. If the Android service or
|
||||
filter cannot be read, the reader reports DND inactive/unknown and preserves the
|
||||
previous wake behavior; it does not pretend to know an unavailable phone state.
|
||||
|
||||
## Race handling
|
||||
|
||||
The native listener captures wake eligibility before posting its asynchronous
|
||||
notification callback. The TypeScript bridge forwards that immutable flag. The
|
||||
controller combines it with a fresh DND read on JS delivery and retains the
|
||||
restriction through the existing 500 ms/foreground-service popup delay. Reposts
|
||||
can restrict a pending notification but cannot make a DND-silenced pending alert
|
||||
eligible to wake by shortening or retaining its timer.
|
||||
|
||||
Immediately before waking, the controller checks DND again. This covers both
|
||||
DND becoming active during a delay and DND being disabled after a notification
|
||||
arrived silently. The flag limits **wake**, not a popup on an already-awake
|
||||
screen. On listener reconnect, the existing recent-notification reconciliation
|
||||
samples the current phone filter; it cannot reconstruct historical DND changes
|
||||
while the listener/process was disconnected.
|
||||
|
||||
## Validation
|
||||
|
||||
Commands from the repository root:
|
||||
|
||||
```sh
|
||||
npm test
|
||||
npm exec -- tsc --noEmit
|
||||
npm run lint
|
||||
npm run test:kotlin
|
||||
git diff --check
|
||||
```
|
||||
|
||||
Baseline on `build/all-features` commit `54ba6b4f`: 1,335 tests, 1,332 passed,
|
||||
3 skipped, no failures. With the feature, the full suite passes 1,351 tests
|
||||
(1,354 total, 3 skipped), with no failures. TypeScript `--noEmit` and lint pass;
|
||||
lint retains five warnings in untouched files and no warning from this feature.
|
||||
The targeted wake/bridge/delay suite passes all 23 tests; the initial broader
|
||||
regression selection also passed all 62 tests covering controller behavior,
|
||||
delay/reposts, source filters, modal queue/backdrop and existing shell consumers.
|
||||
|
||||
New wake-policy tests were observed failing first (DND caused an unwanted wake,
|
||||
arrival metadata was lost, and reposts could unsilence a delayed popup), then
|
||||
passing after implementation. Native-boundary tests use the actual transpiled
|
||||
bridge with a fake Android boundary; Kotlin source-contract checks do not prove
|
||||
an Android compilation or actual OEM DND behavior.
|
||||
|
||||
Native Kotlin tests were attempted but cannot start in this environment:
|
||||
`JAVA_HOME is not set and no 'java' command could be found in your PATH.` No APK,
|
||||
physical phone/glasses test or release is claimed by these checks.
|
||||
|
||||
## Device acceptance checks before release
|
||||
|
||||
1. Grant the app its usual notification-listener access and connect the glasses.
|
||||
2. With glasses asleep, enable each supported Android DND mode and send a
|
||||
notification from an enabled source. Verify the glasses remain asleep and
|
||||
the notification can still be opened manually from the Notifications app.
|
||||
3. Turn DND off: verify no old notification wakes the glasses. Send a new
|
||||
notification and verify normal popup/wake and return-to-sleep behavior.
|
||||
4. With the glasses already awake, enable DND and send a notification. Verify
|
||||
the normal popup and visible app background, with no focus-stealing wake.
|
||||
5. Enable/disable DND during the popup delay, including a foreground-service
|
||||
placeholder and updates under the same notification key. Verify no delayed
|
||||
DND arrival wakes the glasses after the restriction changes.
|
||||
6. Check local-only app notification wake, normal manual/ring/head-up wake,
|
||||
Timers, disabled sources, notification withdrawal and listener reconnect.
|
||||
+9
-5
@@ -1,16 +1,20 @@
|
||||
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"
|
||||
/** Existing English/multilingual files stay usable; the dedicated French provider uses its own download. */
|
||||
data class WhisperModelFiles(val language: String, val frenchOnly: Boolean = false) {
|
||||
val englishOnly: Boolean get() = !frenchOnly && language == "en"
|
||||
val dirName: String get() = if (frenchOnly) "sherpa-onnx-whisper-small-fr-int8-v1" else if (englishOnly) "sherpa-onnx-whisper-base-en-int8" else "sherpa-onnx-whisper-base-int8"
|
||||
private val prefix: String get() = if (frenchOnly) "small-fr" else 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 {
|
||||
/** A dedicated French fine-tune never silently substitutes the generic base model. */
|
||||
fun forSelection(language: String?, frenchOnly: Boolean): WhisperModelFiles =
|
||||
if (frenchOnly) WhisperModelFiles("fr", true) else forLanguage(language)
|
||||
|
||||
/** Null preserves the old English default; an empty code enables automatic detection. */
|
||||
fun forLanguage(language: String?): WhisperModelFiles =
|
||||
WhisperModelFiles(language?.trim()?.lowercase() ?: "en")
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
interface FaceclawNotificationListener {
|
||||
fun onNotificationPosted(key: String?): Unit
|
||||
fun onNotificationPosted(key: String?, canWakeScreen: Boolean): Unit
|
||||
fun onNotificationRemoved(key: String?): Unit
|
||||
}
|
||||
+6
@@ -12,6 +12,12 @@ class ConnectionOptions {
|
||||
// giving up. Both are dialed at once, so a slow or missing arm gets the whole
|
||||
// window (it stays under Android's own ~30 s direct-connect timeout).
|
||||
const val ARM_CONNECT_WINDOW_MS = 20_000
|
||||
// When autoConnect (background reconnect) fails to reach an arm, a direct connect
|
||||
// is retried: its aggressive scan can catch an arm that advertises only briefly,
|
||||
// and the cached bond can sometimes recover a half-open link that stopped
|
||||
// advertising after a dropped link. This is the direct retry's own window,
|
||||
// independent of ARM_CONNECT_WINDOW_MS (already spent on the autoConnect attempt).
|
||||
const val DIRECT_CONNECT_FALLBACK_TIMEOUT_MS = 15_000
|
||||
const val SERVICES_TIMEOUT_MS = 5_000
|
||||
const val DESCRIPTOR_TIMEOUT_MS = 5_000
|
||||
const val RING_DESIRED_MTU = 247
|
||||
|
||||
+18
-7
@@ -2339,9 +2339,12 @@ class GlassesSessionCore(
|
||||
try {
|
||||
// Dial both arms at once, so the left arm's attempt is already pending (and
|
||||
// can land) while the right arm is being set up; they share one window.
|
||||
// autoConnect=true for both arms: a direct connection is supervised less
|
||||
// patiently by Android's stack and was observed dropping the link shortly
|
||||
// after it came up (the same failure that made the ring require autoConnect).
|
||||
val deadlineMs = now() + ConnectionOptions.ARM_CONNECT_WINDOW_MS
|
||||
link.beginConnect(rightAddress, false)
|
||||
link.beginConnect(leftAddress, false)
|
||||
link.beginConnect(rightAddress, true)
|
||||
link.beginConnect(leftAddress, true)
|
||||
connectArm(rightAddress, true, deadlineMs)
|
||||
connectArm(leftAddress, true, deadlineMs)
|
||||
if (!sleepDuringConnectSettling(800)) {
|
||||
@@ -2450,8 +2453,16 @@ class GlassesSessionCore(
|
||||
|
||||
internal fun connectArm(address: String, enableRenderNotify: Boolean, deadlineMs: Long) {
|
||||
val timeoutMs = maxOf(deadlineMs - now(), ConnectionOptions.CONNECT_TIMEOUT_MS.toLong())
|
||||
if (!link.connect(address, timeoutMs.toInt())) {
|
||||
throw ArmUnreachableException(if (address.equals(leftAddress, ignoreCase = true)) "left" else "right", address)
|
||||
if (!link.connect(address, timeoutMs.toInt(), true)) {
|
||||
// autoConnect only connects on a fresh advertisement; an arm stuck in a
|
||||
// half-open state (it stopped advertising after a dropped link) never
|
||||
// produces one. Retry direct: the aggressive scan plus the cached bond
|
||||
// can recover it. Still unreachable after that is a real failure.
|
||||
logLine("autoConnect timed out for " + address + "; retrying direct connect")
|
||||
ConnectionCounters.increment("g2.connect-fallback-direct")
|
||||
if (!link.connect(address, ConnectionOptions.DIRECT_CONNECT_FALLBACK_TIMEOUT_MS, false)) {
|
||||
throw ArmUnreachableException(if (address.equals(leftAddress, ignoreCase = true)) "left" else "right", address)
|
||||
}
|
||||
}
|
||||
// requestConnectionPriority has no callback in this Android compile target, so there is
|
||||
// no reliable completion point to keep it in the global GATT operation pipeline. But it's
|
||||
@@ -2538,9 +2549,9 @@ class GlassesSessionCore(
|
||||
logLine("connecting direct ring $ringAddress")
|
||||
// autoConnect=true (see SessionLink.connect's 3-arg overload) -
|
||||
// matches what Even's own app does for this device specifically.
|
||||
// Direct connect (false, the default used for the glasses) was
|
||||
// measured dying ~5s into an otherwise-idle ring connection,
|
||||
// repeatedly, with nothing else competing for it.
|
||||
// Direct connect (false) was measured dying ~5s into an
|
||||
// otherwise-idle ring connection, repeatedly, with nothing else
|
||||
// competing for it.
|
||||
if (!link.connect(ringAddress, ConnectionOptions.RING_CONNECT_TIMEOUT_MS, true)) {
|
||||
throw IllegalStateException("connect failed: $ringAddress")
|
||||
}
|
||||
|
||||
+2
-1
@@ -18,7 +18,8 @@ interface SessionLink {
|
||||
|
||||
/**
|
||||
* [connect] with the platform's background-reconnect mode (Android's autoConnect) when
|
||||
* [autoConnect] is set. The R1 ring needs it; platforms without the distinction ignore it.
|
||||
* [autoConnect] is set. The R1 ring and the G2 glasses arms both need it; platforms
|
||||
* without the distinction ignore it.
|
||||
*/
|
||||
fun connect(address: String, timeoutMs: Int, autoConnect: Boolean): Boolean = connect(address, timeoutMs)
|
||||
|
||||
|
||||
@@ -288,6 +288,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
||||
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
|
||||
'./notification-popup-timeout': {},
|
||||
'../../native/notification-icons': {}, '../../native/notification-sources': {},
|
||||
'../../native/phone-do-not-disturb': { isPhoneDoNotDisturbEnabled: () => false },
|
||||
'../../assistant/tool-registry': {}, './geometry': {
|
||||
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
|
||||
screenWidth: () => 640, screenHeight: () => 480,
|
||||
|
||||
@@ -55,6 +55,7 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
|
||||
'../../native/asr-model': {
|
||||
ASR_MODELS: {
|
||||
moonshine: { label: 'Moonshine', sizeBytes: 1 },
|
||||
'whisper-small-fr': { label: 'Whisper French Small', sizeBytes: 1 },
|
||||
'whisper-base-en': { label: 'Whisper Base English', sizeBytes: 1 },
|
||||
'whisper-base': { label: 'Whisper Base Multilingual', sizeBytes: 1 },
|
||||
},
|
||||
|
||||
@@ -136,6 +136,7 @@ test('system menu hides brightness in Auto and opens its picker between Voice in
|
||||
'../dashboard-settings': f.settings, './geometry': f.geometry, './brightness-picker-layer': f.picker,
|
||||
'./chrome-layer': { ShellChromeLayer: class {} },
|
||||
'./notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts'),
|
||||
'../../native/phone-do-not-disturb': { isPhoneDoNotDisturbEnabled: () => false },
|
||||
});
|
||||
shell.registerWindow({ windowId: 'test', appId: 'test', closeable: true, handleInput() {} });
|
||||
shell.openSystemMenu('test');
|
||||
|
||||
@@ -209,6 +209,8 @@ test('provider selection falls back to on-device without a key and connects the
|
||||
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: '' }));
|
||||
assert.equal(transcriptionKey({ provider: 'onboard-whisper-fr', language: 'en' }), 'onboard-whisper-fr:fr');
|
||||
assert.notEqual(transcriptionKey({ provider: 'onboard-whisper-fr' }), transcriptionKey({ provider: 'onboard-whisper', language: 'fr' }));
|
||||
const statuses = [];
|
||||
const options = { onTranscript() {}, onStatus: status => statuses.push(status), onError() {} };
|
||||
const selection = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: ' ', sonioxApiKey: 'soniox-key' };
|
||||
|
||||
@@ -32,4 +32,15 @@ class WhisperModelFilesTest {
|
||||
assertEquals("", model.language)
|
||||
assertEquals(WhisperModelFiles.forLanguage("fr").files, model.files)
|
||||
}
|
||||
@Test fun frenchFineTuneUsesDistinctFilesRegardlessOfTheGenericLanguage() {
|
||||
for (language in listOf(null, "en", "de", "", "fr")) {
|
||||
val model = WhisperModelFiles.forSelection(language, true)
|
||||
assertTrue(model.frenchOnly)
|
||||
assertFalse(model.englishOnly)
|
||||
assertEquals("fr", model.language)
|
||||
assertEquals("sherpa-onnx-whisper-small-fr-int8-v1", model.dirName)
|
||||
assertEquals(listOf("small-fr-encoder.int8.onnx", "small-fr-decoder.int8.onnx", "small-fr-tokens.txt"), model.files)
|
||||
assertEquals(WhisperModelFiles.forLanguage(language), WhisperModelFiles.forSelection(language, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,6 +304,7 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => active,
|
||||
shouldPopUpNewNotification,
|
||||
isPhoneDoNotDisturbEnabled: () => false,
|
||||
notificationPopupDelayMs,
|
||||
shell: {
|
||||
isScreenOn: () => false,
|
||||
|
||||
@@ -84,6 +84,32 @@ test("reposts can bring a popup forward but never push it back", () => {
|
||||
assert.deepEqual(ready, ["a", "b"], "the earlier timer was cancelled");
|
||||
});
|
||||
|
||||
test("a notification retains its arrival-time no-wake policy through the popup delay", () => {
|
||||
const clock = makeClock();
|
||||
const ready = [];
|
||||
const delay = new NotificationPopupDelay((key, canWakeScreen) => ready.push([key, canWakeScreen]), clock.schedule, clock.now);
|
||||
delay.post("quiet", 500, false);
|
||||
delay.post("normal", 500);
|
||||
clock.advance(500);
|
||||
assert.deepEqual(ready, [["quiet", false], ["normal", true]]);
|
||||
});
|
||||
|
||||
test("a repost cannot re-enable wake after a DND arrival or discard a new DND restriction", () => {
|
||||
for (const firstAllowed of [false, true]) {
|
||||
for (const nextDelay of [500, 100]) {
|
||||
const clock = makeClock();
|
||||
const ready = [];
|
||||
const delay = new NotificationPopupDelay((key, canWakeScreen) => ready.push([key, canWakeScreen]), clock.schedule, clock.now);
|
||||
delay.post("message", 500, firstAllowed);
|
||||
clock.advance(50);
|
||||
delay.post("message", nextDelay, !firstAllowed);
|
||||
clock.advance(1000);
|
||||
assert.deepEqual(ready, [["message", false]], `firstAllowed=${firstAllowed}, nextDelay=${nextDelay}`);
|
||||
assert.deepEqual(delay.pendingKeys(), []);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("foreground-service notifications wait longer, unless urgent", () => {
|
||||
assert.equal(notificationPopupDelayMs({ category: "msg" }), NOTIFICATION_POPUP_DELAY_MS);
|
||||
assert.equal(notificationPopupDelayMs({ category: "", foregroundService: true }), FOREGROUND_SERVICE_POPUP_DELAY_MS);
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
const kotlinServicePath = 'App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt';
|
||||
function source(file) { return fs.readFileSync(path.resolve(__dirname, '..', file), 'utf8'); }
|
||||
|
||||
// Structural source contracts only: these do not compile or execute Android/Kotlin.
|
||||
test('structural Kotlin contract: fresh read-only DND getter maps restrictive filters and fails open', () => {
|
||||
const service = source(kotlinServicePath);
|
||||
const getter = service.match(/@JvmStatic\s+fun isPhoneDoNotDisturbEnabled\(context: Context\?\): Boolean \{([\s\S]*?)\n \}/);
|
||||
assert.ok(getter, 'missing static context-based DND getter');
|
||||
assert.match(getter[1], /context\?\.getSystemService\(Context\.NOTIFICATION_SERVICE\) as\? NotificationManager/);
|
||||
assert.match(getter[1], /manager\?\.currentInterruptionFilter/);
|
||||
assert.match(getter[1], /activeService\?\.currentInterruptionFilter/);
|
||||
assert.match(getter[1], /catch \([^)]*: Throwable\)/);
|
||||
assert.match(getter[1], /NotificationManager\.INTERRUPTION_FILTER_PRIORITY,\s*NotificationManager\.INTERRUPTION_FILTER_NONE,\s*NotificationManager\.INTERRUPTION_FILTER_ALARMS -> true/);
|
||||
assert.match(getter[1], /else -> false/);
|
||||
assert.doesNotMatch(getter[1], /setInterruptionFilter|requestInterruptionFilter|Settings\.|postDelayed/);
|
||||
assert.doesNotMatch(service, /override fun onInterruptionFilterChanged/);
|
||||
assert.match(source('App_Resources/Android/app.gradle'), /minSdkVersion 24\b/);
|
||||
});
|
||||
|
||||
test('structural Kotlin contract: posted callback snapshots DND before main-handler delivery, including reconnect', () => {
|
||||
const service = source(kotlinServicePath);
|
||||
const emit = service.match(/private fun emitNotificationPosted\(key: String\?\) \{([\s\S]*?)\n \}/);
|
||||
assert.ok(emit);
|
||||
assert.match(emit[1], /val canWakeScreen = !isPhoneDoNotDisturbEnabled\(activeService\)/);
|
||||
assert.match(emit[1], /listener\.onNotificationPosted\(eventKey, canWakeScreen\)/);
|
||||
assert.ok(emit[1].indexOf('val canWakeScreen') < emit[1].indexOf('emitNotificationEvent('));
|
||||
assert.equal((emit[1].match(/isPhoneDoNotDisturbEnabled/g) ?? []).length, 1);
|
||||
const dispatch = service.match(/private fun emitNotificationEvent\([\s\S]*?\n \}/)[0];
|
||||
assert.match(dispatch, /mainHandler\.post \{[\s\S]*deliver\(listener, key\)/);
|
||||
assert.doesNotMatch(dispatch, /isPhoneDoNotDisturbEnabled/);
|
||||
assert.match(service, /for \(key in posted\) \{\s*emitNotificationPosted\(key\)/);
|
||||
assert.match(service, /private fun emitNotificationRemoved\(key: String\?\) \{\s*emitNotificationEvent\(key\) \{ listener, eventKey -> listener\.onNotificationRemoved\(eventKey\) \}/);
|
||||
const callback = source('native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawNotificationListener.kt');
|
||||
assert.match(callback, /fun onNotificationPosted\(key: String\?, canWakeScreen: Boolean\): Unit/);
|
||||
assert.match(callback, /fun onNotificationRemoved\(key: String\?\): Unit/);
|
||||
});
|
||||
|
||||
function notificationBridge() {
|
||||
const tasks = [];
|
||||
let proxy;
|
||||
let observer;
|
||||
const service = {
|
||||
addNotificationListener(value) { proxy = value; },
|
||||
removeNotificationListener(value) { assert.equal(value, proxy); proxy = undefined; },
|
||||
addListenerStateObserver(value) { observer = value; },
|
||||
removeListenerStateObserver(value) { assert.equal(value, observer); observer = undefined; },
|
||||
};
|
||||
const api = loader({
|
||||
global: { isAndroid: true },
|
||||
setTimeout(fn, delay) { assert.equal(delay, 0); tasks.push(fn); },
|
||||
com: { faceclaw: { app: {
|
||||
FaceclawMediaNotificationListenerService: service,
|
||||
FaceclawNotificationListener: function (callbacks) { return callbacks; },
|
||||
} } },
|
||||
java: { lang: { Runnable: function (callbacks) { return callbacks; } } },
|
||||
}, {
|
||||
'../graphics/image': {}, './frame-timings': { spanCurrent: (_name, fn) => fn() },
|
||||
'../util/array-util': { toUint8Array: value => value },
|
||||
'./notification-sources': {}, './image-files': { PHOTO_TONE: { gamma: 1 } },
|
||||
'./notification-types': { NOTIFICATION_ICON_SIZE: 24 },
|
||||
})('app/native/notification-icons.ts');
|
||||
return {
|
||||
api, service, get proxy() { return proxy; }, get observer() { return observer; },
|
||||
flush() { while (tasks.length) tasks.shift()(); },
|
||||
};
|
||||
}
|
||||
|
||||
test('native posted wake permission remains immutable across asynchronous bridge dispatch', () => {
|
||||
const bridge = notificationBridge();
|
||||
const posted = [];
|
||||
const off = bridge.api.onAndroidNotificationPosted((key, canWakeScreen) => posted.push([key, canWakeScreen]));
|
||||
let dnd = true;
|
||||
bridge.service.isPhoneDoNotDisturbEnabled = () => dnd;
|
||||
const reader = loadDnd({ service: bridge.service });
|
||||
bridge.proxy.onNotificationPosted('dnd-active', !reader.isPhoneDoNotDisturbEnabled());
|
||||
dnd = false;
|
||||
bridge.proxy.onNotificationPosted('dnd-off', !reader.isPhoneDoNotDisturbEnabled());
|
||||
bridge.proxy.onNotificationPosted('legacy');
|
||||
assert.deepEqual(posted, []);
|
||||
bridge.flush();
|
||||
assert.deepEqual(posted, [['dnd-active', false], ['dnd-off', true], ['legacy', true]]);
|
||||
dnd = true;
|
||||
assert.equal(reader.isPhoneDoNotDisturbEnabled(), true);
|
||||
dnd = false;
|
||||
assert.equal(reader.isPhoneDoNotDisturbEnabled(), false);
|
||||
bridge.flush();
|
||||
assert.equal(posted.length, 3, 'DND transitions alone do not replay notification posts');
|
||||
off();
|
||||
assert.equal(bridge.proxy, undefined);
|
||||
});
|
||||
|
||||
test('removed callbacks retain their key-only contract', () => {
|
||||
const bridge = notificationBridge();
|
||||
const removed = [];
|
||||
const off = bridge.api.onAndroidNotificationRemoved((...args) => removed.push(args));
|
||||
bridge.proxy.onNotificationRemoved('gone');
|
||||
bridge.flush();
|
||||
assert.deepEqual(removed, [['gone']]);
|
||||
off();
|
||||
});
|
||||
|
||||
test('posted, removed and listener-state observers retain async dispatch and eager cache invalidation', () => {
|
||||
const bridge = notificationBridge();
|
||||
const posted = [];
|
||||
const removed = [];
|
||||
let changed = 0;
|
||||
let iconReads = 0;
|
||||
bridge.service.getNotificationIconGrayForKey = () => { iconReads++; return new Uint8Array(); };
|
||||
const offPosted = bridge.api.onAndroidNotificationPosted(key => posted.push(key));
|
||||
const offRemoved = bridge.api.onAndroidNotificationRemoved(key => removed.push(key));
|
||||
const offChanged = bridge.api.onAndroidNotificationsChanged(() => changed++);
|
||||
const readIcon = () => bridge.api.readNotificationIconByKey('same-key', false);
|
||||
readIcon();
|
||||
readIcon();
|
||||
assert.equal(iconReads, 1);
|
||||
bridge.proxy.onNotificationPosted('same-key', false);
|
||||
readIcon();
|
||||
assert.equal(iconReads, 2, 'DND-blocked post still invalidates cached icons eagerly');
|
||||
assert.equal(changed, 0);
|
||||
bridge.flush();
|
||||
assert.deepEqual(posted, ['same-key']);
|
||||
assert.equal(changed, 1);
|
||||
bridge.proxy.onNotificationRemoved('same-key');
|
||||
readIcon();
|
||||
assert.equal(iconReads, 3);
|
||||
assert.deepEqual(removed, []);
|
||||
bridge.flush();
|
||||
assert.deepEqual(removed, ['same-key']);
|
||||
assert.equal(changed, 2);
|
||||
bridge.observer.run();
|
||||
readIcon();
|
||||
assert.equal(iconReads, 4);
|
||||
assert.equal(changed, 2);
|
||||
bridge.flush();
|
||||
assert.equal(changed, 3);
|
||||
assert.deepEqual(posted, ['same-key'], 'listener-state changes do not replay posts');
|
||||
offPosted();
|
||||
offRemoved();
|
||||
assert.ok(bridge.proxy, 'changed observer retains its native listeners');
|
||||
offChanged();
|
||||
assert.equal(bridge.proxy, undefined);
|
||||
assert.equal(bridge.observer, undefined);
|
||||
});
|
||||
|
||||
function loadDnd({ isAndroid = true, service, context = {} } = {}) {
|
||||
return loader({
|
||||
global: { isAndroid },
|
||||
com: { faceclaw: { app: { FaceclawMediaNotificationListenerService: service } } },
|
||||
}, { '@nativescript/core': { Utils: { android: { getApplicationContext: () => context } } } })(
|
||||
'app/native/phone-do-not-disturb.ts',
|
||||
);
|
||||
}
|
||||
|
||||
test('phone DND reader samples the native getter with application context on every Android read', () => {
|
||||
const context = {};
|
||||
let enabled = false;
|
||||
let reads = 0;
|
||||
const api = loadDnd({ context, service: {
|
||||
isPhoneDoNotDisturbEnabled(actualContext) {
|
||||
assert.equal(actualContext, context);
|
||||
reads++;
|
||||
return enabled;
|
||||
},
|
||||
} });
|
||||
assert.equal(api.isPhoneDoNotDisturbEnabled(), false);
|
||||
enabled = true;
|
||||
assert.equal(api.isPhoneDoNotDisturbEnabled(), true);
|
||||
enabled = false;
|
||||
assert.equal(api.isPhoneDoNotDisturbEnabled(), false);
|
||||
assert.equal(reads, 3);
|
||||
});
|
||||
|
||||
test('phone DND reader returns false when the native boundary is unavailable or throws', () => {
|
||||
for (const service of [undefined, {}, { isPhoneDoNotDisturbEnabled() { throw new Error('unavailable'); } }]) {
|
||||
assert.equal(loadDnd({ service }).isPhoneDoNotDisturbEnabled(), false);
|
||||
}
|
||||
const api = loader({ global: { isAndroid: true } }, {
|
||||
'@nativescript/core': { Application: {} },
|
||||
})('app/native/phone-do-not-disturb.ts');
|
||||
assert.equal(api.isPhoneDoNotDisturbEnabled(), false);
|
||||
});
|
||||
|
||||
test('phone DND reader returns false outside Android without touching native APIs', () => {
|
||||
const service = { isPhoneDoNotDisturbEnabled() { assert.fail('native getter must not run'); } };
|
||||
assert.equal(loadDnd({ isAndroid: false, service }).isPhoneDoNotDisturbEnabled(), false);
|
||||
const api = loader({ global: { isIOS: true } }, {
|
||||
'@nativescript/core': { Application: {} },
|
||||
})('app/native/phone-do-not-disturb.ts');
|
||||
assert.equal(api.isPhoneDoNotDisturbEnabled(), false);
|
||||
});
|
||||
@@ -0,0 +1,182 @@
|
||||
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');
|
||||
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
|
||||
|
||||
function evaluateMembers(fileName, className, names, globals) {
|
||||
const source = ts.createSourceFile(fileName, fs.readFileSync(path.join(__dirname, '..', fileName), 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const declaration = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === className);
|
||||
const members = names.map(name => {
|
||||
const member = declaration.members.find(node => node.name?.getText(source) === name);
|
||||
assert.ok(member, `production member ${className}.${name} exists`);
|
||||
return member.getText(source);
|
||||
});
|
||||
const context = { exports: {}, ...globals };
|
||||
vm.runInNewContext(ts.transpileModule(`export class Harness { ${members.join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
return context.exports.Harness;
|
||||
}
|
||||
|
||||
function controller() {
|
||||
const state = {
|
||||
dnd: false, screenOn: false, sourceAllowed: true, wakes: 0, renders: 0,
|
||||
modals: [], removed: [], active: [{ key: 'message', packageName: 'com.mail', category: 'msg' }],
|
||||
};
|
||||
let now = 0;
|
||||
const timers = [];
|
||||
const clock = {
|
||||
schedule(run, delay) {
|
||||
const timer = { due: now + delay, run, cancelled: false };
|
||||
timers.push(timer);
|
||||
return () => { timer.cancelled = true; };
|
||||
},
|
||||
advance(ms = 500) {
|
||||
const end = now + ms;
|
||||
for (;;) {
|
||||
const next = timers.filter(t => !t.cancelled && t.due <= end).sort((a, b) => a.due - b.due)[0];
|
||||
if (!next) break;
|
||||
now = next.due;
|
||||
next.cancelled = true;
|
||||
next.run();
|
||||
}
|
||||
now = end;
|
||||
},
|
||||
};
|
||||
const Harness = evaluateMembers('app/g2/dashboard-controller.ts', 'DashboardController', [
|
||||
'notificationPopups', 'handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification',
|
||||
], {
|
||||
NotificationPopupDelay: class extends NotificationPopupDelay {
|
||||
constructor(ready) { super(ready, clock.schedule, () => now); }
|
||||
},
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => state.active,
|
||||
shouldPopUpNewNotification: () => state.sourceAllowed,
|
||||
notificationPopupDelayMs,
|
||||
isPhoneDoNotDisturbEnabled: () => state.dnd,
|
||||
shell: {
|
||||
isScreenOn: () => state.screenOn,
|
||||
wake: () => { state.wakes++; state.screenOn = true; return true; },
|
||||
openNotificationModal: (key, woke) => state.modals.push({ key, woke }),
|
||||
notificationRemoved: key => state.removed.push(key),
|
||||
},
|
||||
});
|
||||
const host = new Harness();
|
||||
host.requestShellRender = () => state.renders++;
|
||||
host.appendLog = () => {};
|
||||
host.formatError = String;
|
||||
return { state, host, advance: clock.advance };
|
||||
}
|
||||
|
||||
test('phone DND prevents a mirrored notification waking sleeping glasses without deleting it', () => {
|
||||
const { host, state, advance } = controller();
|
||||
state.dnd = true;
|
||||
host.handleAndroidNotificationPosted('message');
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
assert.equal(state.renders, 1, 'the notification tray still refreshes');
|
||||
assert.equal(state.active.length, 1, 'the phone notification stays available for manual viewing');
|
||||
});
|
||||
|
||||
test('a notification captured during phone DND cannot wake after DND turns off during its delay', () => {
|
||||
const { host, state, advance } = controller();
|
||||
// Native captured DND before its asynchronous callback; it is off by JS delivery.
|
||||
host.handleAndroidNotificationPosted('message', false);
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
});
|
||||
|
||||
test('DND sampled at JS arrival remains restrictive if disabled before the popup timer', () => {
|
||||
const { host, state, advance } = controller();
|
||||
state.dnd = true;
|
||||
host.handleAndroidNotificationPosted('message', true);
|
||||
state.dnd = false;
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
});
|
||||
|
||||
test('enabling DND during the popup delay prevents a previously eligible wake', () => {
|
||||
const { host, state, advance } = controller();
|
||||
host.handleAndroidNotificationPosted('message', true);
|
||||
state.dnd = true;
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
});
|
||||
|
||||
test('DND leaves an already-awake notification popup normal without stealing focus', () => {
|
||||
const { host, state, advance } = controller();
|
||||
state.screenOn = true;
|
||||
state.dnd = true;
|
||||
host.handleAndroidNotificationPosted('message', false);
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, [{ key: 'message', woke: false }]);
|
||||
});
|
||||
|
||||
test('DND silent arrivals are not replayed on disable, but new notifications wake normally', () => {
|
||||
const { host, state, advance } = controller();
|
||||
state.dnd = true;
|
||||
host.handleAndroidNotificationPosted('message', false);
|
||||
advance();
|
||||
state.dnd = false;
|
||||
advance(10_000);
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
assert.deepEqual(Array.from(host.notificationPopups.pendingKeys()), []);
|
||||
host.handleAndroidNotificationPosted('message', true);
|
||||
advance();
|
||||
assert.equal(state.wakes, 1);
|
||||
assert.deepEqual(state.modals, [{ key: 'message', woke: true }]);
|
||||
});
|
||||
|
||||
test('a DND popup arriving while awake cannot wake the screen if it sleeps during the delay', () => {
|
||||
const { host, state, advance } = controller();
|
||||
state.screenOn = true;
|
||||
state.dnd = true;
|
||||
host.handleAndroidNotificationPosted('message', false);
|
||||
state.screenOn = false;
|
||||
state.dnd = false;
|
||||
advance();
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
});
|
||||
|
||||
function appNotificationHost() {
|
||||
const state = { dnd: true, wakes: 0, modals: [] };
|
||||
const Harness = evaluateMembers('app/ui/shell/shell.ts', 'Shell', ['postAppNotification'], {
|
||||
isPhoneDoNotDisturbEnabled: () => state.dnd,
|
||||
});
|
||||
const host = new Harness();
|
||||
host.screenOn = false;
|
||||
host.appNotifications = new Map();
|
||||
host.wake = () => { state.wakes++; host.screenOn = true; return true; };
|
||||
host.openNotificationModal = (key, woke) => state.modals.push({ key, woke });
|
||||
return { host, state };
|
||||
}
|
||||
|
||||
test('phone DND also prevents an app-generated notification waking sleeping glasses without retaining an unreachable popup', () => {
|
||||
const { host, state } = appNotificationHost();
|
||||
host.postAppNotification({ key: 'local-alert' });
|
||||
assert.equal(state.wakes, 0);
|
||||
assert.deepEqual(state.modals, []);
|
||||
assert.equal(host.appNotifications.size, 0);
|
||||
});
|
||||
|
||||
test('app-generated notifications keep normal awake behavior during DND and wake normally when DND is off', () => {
|
||||
for (const screenOn of [true, false]) {
|
||||
const { host, state } = appNotificationHost();
|
||||
host.screenOn = screenOn;
|
||||
state.dnd = screenOn;
|
||||
host.postAppNotification({ key: 'local-alert' });
|
||||
assert.equal(state.wakes, screenOn ? 0 : 1);
|
||||
assert.deepEqual(state.modals, [{ key: 'local-alert', woke: !screenOn }]);
|
||||
assert.equal(host.appNotifications.size, 1);
|
||||
}
|
||||
});
|
||||
@@ -164,6 +164,7 @@ function androidBridge() {
|
||||
setListener(listener) { this.listener = listener; },
|
||||
setCommunicator() {}, setUsePhoneMic() {}, setSaveRecordings() {}, setEndpointing() {},
|
||||
setNoiseSuppression() {}, setBeamFilter() {}, clearSpeakerVerification() {},
|
||||
setFrenchWhisper(enabled) { this.frenchWhisper = enabled; },
|
||||
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; },
|
||||
@@ -173,7 +174,7 @@ function androidBridge() {
|
||||
'@nativescript/core': { Utils: { android: { getApplicationContext: () => ({}) } } },
|
||||
'./speech-pause': { SpeechPauseDetector: class { reset() {} } },
|
||||
'./cloud-stt-provider': { createCloudSttClient: () => null,
|
||||
transcriptionKey: options => `${options.provider}:${options.language ?? (options.provider === 'onboard-whisper' ? 'en' : '')}` },
|
||||
transcriptionKey: options => `${options.provider}:${options.provider === 'onboard-whisper-fr' ? 'fr' : options.language ?? (options.provider === 'onboard-whisper' ? 'en' : '')}` },
|
||||
}, { global: { isAndroid: true }, com: { faceclaw: { app: {
|
||||
FaceclawVoiceController: function () { return controller; },
|
||||
FaceclawVoiceControllerListener: function (listener) { return listener; },
|
||||
@@ -237,3 +238,16 @@ test('a shared capture restarts for a holder that needs another provider, and is
|
||||
assert.equal(controller.active, true);
|
||||
assert.equal(bridge.holdsCapture('ptt'), true);
|
||||
});
|
||||
|
||||
test('dedicated French Whisper selects its own files and switches back without retaining the override', () => {
|
||||
const { bridge, controller } = androidBridge();
|
||||
bridge.startContinuousCapture({ provider: 'onboard-whisper-fr', language: 'en' });
|
||||
assert.equal(controller.modelKind, 'whisper');
|
||||
assert.equal(controller.frenchWhisper, true);
|
||||
assert.equal(controller.language, 'fr');
|
||||
bridge.retargetContinuousCapture({ provider: 'onboard-whisper' });
|
||||
assert.equal(controller.frenchWhisper, false);
|
||||
assert.equal(controller.language, 'en');
|
||||
assert.equal(controller.starts, 2);
|
||||
bridge.stop();
|
||||
});
|
||||
@@ -144,3 +144,67 @@ test('OpenAI transcription model preserves legacy default and persists independe
|
||||
assert.equal(s.voiceLanguageSetting.get(), 'fr');
|
||||
assert.equal(settings(new Map([['voice.openAiTranscriptionModel', 'invalid']])).openAiTranscriptionModelSetting.get(), 'gpt-realtime-whisper');
|
||||
});
|
||||
|
||||
test('French provider persists independently and never overwrites shared language preferences', () => {
|
||||
const values = new Map([['voice.language', 'ja'], ['voice.provider', 'onboard-whisper']]);
|
||||
let s = settings(values);
|
||||
s.voiceProviderSetting.set('onboard-whisper-fr');
|
||||
s = settings(values);
|
||||
assert.equal(s.voiceProviderSetting.get(), 'onboard-whisper-fr');
|
||||
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper-fr'), 'fr');
|
||||
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), 'ja');
|
||||
assert.equal(s.voiceLanguageSetting.get(), 'ja');
|
||||
s.voiceProviderSetting.set('onboard-whisper');
|
||||
assert.equal(s.getVoiceTranscriptionLanguage('onboard-whisper'), 'ja');
|
||||
});
|
||||
|
||||
test('French model download resumes, verifies every file including its license, and preserves other models', () => {
|
||||
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() {}
|
||||
},
|
||||
} } },
|
||||
});
|
||||
for (const id of ['moonshine', 'whisper-base-en', 'whisper-base']) {
|
||||
const model = asr.ASR_MODELS[id];
|
||||
for (const file of model.files) files.set(`/files/faceclaw-voice-asr/${model.dirName}/${file.name}`, file.sizeBytes);
|
||||
}
|
||||
const model = asr.ASR_MODELS['whisper-small-fr'];
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, '../docs/models/whisper-small-fr/manifest.json')));
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(model.files)), manifest.files);
|
||||
assert.equal(model.totalBytes, model.files.reduce((total, file) => total + file.sizeBytes, 0));
|
||||
assert.equal(asr.isAsrModelReady('whisper-small-fr'), false);
|
||||
asr.startAsrModelDownload('whisper-small-fr');
|
||||
files.set(downloads[0].destination, downloads[0].size);
|
||||
downloads[0].listener.onDone();
|
||||
downloads[1].listener.onError('network unavailable');
|
||||
assert.equal(asr.asrModelState('whisper-small-fr').status, 'absent');
|
||||
asr.startAsrModelDownload('whisper-small-fr');
|
||||
assert.equal(downloads[2].destination, downloads[1].destination, 'resume the missing decoder');
|
||||
for (let index = 2; index < 5; index++) {
|
||||
const download = downloads[index];
|
||||
assert.match(download.url, /api\/packages\/Blendman974\/generic\/faceclaw-asr\/whisper-small-fr-v1\//);
|
||||
assert.match(download.hash, /^[a-f0-9]{64}$/);
|
||||
files.set(download.destination, download.size);
|
||||
download.listener.onDone();
|
||||
}
|
||||
assert.equal(asr.isAsrModelReady('whisper-small-fr'), true);
|
||||
asr.deleteAsrModel('whisper-small-fr');
|
||||
assert.equal(asr.isAsrModelReady('whisper-small-fr'), false);
|
||||
for (const id of ['moonshine', 'whisper-base-en', 'whisper-base']) assert.equal(asr.isAsrModelReady(id), true);
|
||||
});
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export the pinned French fine-tune to sherpa-onnx 1.13.0, using CPU only.
|
||||
|
||||
See docs/models/whisper-small-fr/README.md for the isolated export environment.
|
||||
This script never uploads assets or touches installed/downloaded phone models.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from types import SimpleNamespace
|
||||
import urllib.request
|
||||
|
||||
SOURCE_REVISION = '83d7df2928fb2218721c543dcc0be29ef8db2f96'
|
||||
SOURCE_BASE = f'https://huggingface.co/bofenghuang/whisper-small-cv11-french/resolve/{SOURCE_REVISION}/'
|
||||
WEIGHTS_SHA256 = '855a879fa3a71e75f29ed59fcfce287cf21bcdaab23530cd6f8c4ad192677afb'
|
||||
EXPORTER_URL = 'https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/v1.13.0/scripts/whisper/export-onnx.py'
|
||||
EXPORTER_SHA256 = '5e0ddabfac8330ee9aecaba4c1b4286d1cd9f88df4cd30e54706b011bf976e45'
|
||||
MODEL_NAME = 'small-fr'
|
||||
|
||||
|
||||
def digest(path):
|
||||
with path.open('rb') as stream:
|
||||
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
|
||||
|
||||
def download(url, path, expected=None):
|
||||
if not path.exists():
|
||||
temp = path.with_suffix(path.suffix + '.part')
|
||||
urllib.request.urlretrieve(url, temp)
|
||||
temp.replace(path)
|
||||
if expected and digest(path) != expected:
|
||||
raise ValueError(f'Checksum mismatch: {path.name}')
|
||||
|
||||
|
||||
def openai_key(key):
|
||||
"""HF Whisper and OpenAI Whisper have identical tensors, differently named."""
|
||||
if not key.startswith('model.'):
|
||||
raise ValueError(f'Unexpected weight: {key}')
|
||||
key = key.removeprefix('model.')
|
||||
replacements = [
|
||||
('embed_positions.weight', 'positional_embedding'),
|
||||
('embed_tokens', 'token_embedding'), ('layers.', 'blocks.'),
|
||||
('self_attn_layer_norm', 'attn_ln'), ('encoder_attn_layer_norm', 'cross_attn_ln'),
|
||||
('final_layer_norm', 'mlp_ln'), ('self_attn', 'attn'), ('encoder_attn', 'cross_attn'),
|
||||
('k_proj', 'key'), ('q_proj', 'query'), ('v_proj', 'value'), ('out_proj', 'out'),
|
||||
('fc1', 'mlp.0'), ('fc2', 'mlp.2'),
|
||||
('encoder.layer_norm', 'encoder.ln_post'), ('decoder.layer_norm', 'decoder.ln'),
|
||||
]
|
||||
for old, new in replacements:
|
||||
key = key.replace(old, new)
|
||||
return key
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
output = args.output.resolve()
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
download(SOURCE_BASE + 'pytorch_model.bin', output / 'pytorch_model.bin', WEIGHTS_SHA256)
|
||||
download(SOURCE_BASE + 'config.json', output / 'config.json')
|
||||
download(EXPORTER_URL, output / 'sherpa-export.py', EXPORTER_SHA256)
|
||||
|
||||
import torch
|
||||
import whisper
|
||||
from whisper.model import ModelDimensions, disable_sdpa
|
||||
torch.set_num_threads(1)
|
||||
torch.set_num_interop_threads(1)
|
||||
torch.manual_seed(0)
|
||||
config = json.loads((output / 'config.json').read_text())
|
||||
dimensions = ModelDimensions(
|
||||
n_mels=config['num_mel_bins'], n_audio_ctx=config['max_source_positions'],
|
||||
n_audio_state=config['d_model'], n_audio_head=config['encoder_attention_heads'],
|
||||
n_audio_layer=config['encoder_layers'], n_vocab=config['vocab_size'],
|
||||
n_text_ctx=config['max_target_positions'], n_text_state=config['d_model'],
|
||||
n_text_head=config['decoder_attention_heads'], n_text_layer=config['decoder_layers'],
|
||||
)
|
||||
model = whisper.Whisper(dimensions)
|
||||
weights = torch.load(output / 'pytorch_model.bin', map_location='cpu', weights_only=True)
|
||||
converted = {openai_key(key): value for key, value in weights.items()}
|
||||
model.load_state_dict(converted, strict=True)
|
||||
del weights, converted
|
||||
model.eval()
|
||||
|
||||
spec = importlib.util.spec_from_file_location('sherpa_export', output / 'sherpa-export.py')
|
||||
exporter = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(exporter)
|
||||
exporter.get_args = lambda: SimpleNamespace(model=MODEL_NAME)
|
||||
exporter.load_model = lambda _name: model
|
||||
original_export = torch.onnx.export
|
||||
|
||||
def legacy_export(*values, **options):
|
||||
options['dynamo'] = False # sherpa 1.13.0 uses TorchScript's exporter.
|
||||
return original_export(*values, **options)
|
||||
|
||||
torch.onnx.export = legacy_export
|
||||
old_cwd = Path.cwd()
|
||||
try:
|
||||
os.chdir(output)
|
||||
with disable_sdpa():
|
||||
exporter.main()
|
||||
finally:
|
||||
torch.onnx.export = original_export
|
||||
os.chdir(old_cwd)
|
||||
|
||||
license_path = Path(__file__).resolve().parents[1] / 'docs/models/whisper-small-fr/LICENSE.txt'
|
||||
shutil.copyfile(license_path, output / 'LICENSE.txt')
|
||||
names = [f'{MODEL_NAME}-encoder.int8.onnx', f'{MODEL_NAME}-decoder.int8.onnx', f'{MODEL_NAME}-tokens.txt', 'LICENSE.txt']
|
||||
manifest = {
|
||||
'source': 'bofenghuang/whisper-small-cv11-french', 'revision': SOURCE_REVISION,
|
||||
'sourceSha256': WEIGHTS_SHA256, 'exporterSha256': EXPORTER_SHA256,
|
||||
'torchVersion': torch.__version__,
|
||||
'files': [{'name': name, 'sha256': digest(output / name), 'sizeBytes': (output / name).stat().st_size} for name in names],
|
||||
}
|
||||
(output / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
print(json.dumps(manifest, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify released hashes and decode a public/test WAV with sherpa-onnx CPU."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import time
|
||||
import wave
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--model-dir', type=Path, required=True)
|
||||
parser.add_argument('--wav', type=Path, required=True)
|
||||
parser.add_argument('--expected', help='Optional expected transcription substring')
|
||||
args = parser.parse_args()
|
||||
model_dir = args.model_dir
|
||||
manifest = json.loads((model_dir / 'manifest.json').read_text())
|
||||
for entry in manifest['files']:
|
||||
path = model_dir / entry['name']
|
||||
with path.open('rb') as stream:
|
||||
actual = hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
if actual != entry['sha256'] or path.stat().st_size != entry['sizeBytes']:
|
||||
raise ValueError(f'Model file integrity check failed: {path.name}')
|
||||
|
||||
import numpy as np
|
||||
import sherpa_onnx
|
||||
with wave.open(str(args.wav)) as audio:
|
||||
if audio.getnchannels() != 1 or audio.getsampwidth() != 2:
|
||||
raise ValueError('Provide a mono PCM16 WAV')
|
||||
sample_rate = audio.getframerate()
|
||||
samples = np.frombuffer(audio.readframes(audio.getnframes()), dtype='<i2').astype(np.float32) / 32768
|
||||
recognizer = sherpa_onnx.OfflineRecognizer.from_whisper(
|
||||
encoder=str(model_dir / 'small-fr-encoder.int8.onnx'),
|
||||
decoder=str(model_dir / 'small-fr-decoder.int8.onnx'),
|
||||
tokens=str(model_dir / 'small-fr-tokens.txt'), num_threads=1,
|
||||
language='fr', task='transcribe',
|
||||
)
|
||||
stream = recognizer.create_stream()
|
||||
stream.accept_waveform(sample_rate, samples)
|
||||
start = time.monotonic()
|
||||
recognizer.decode_stream(stream)
|
||||
text = stream.result.text.strip()
|
||||
if not text or (args.expected and args.expected.casefold() not in text.casefold()):
|
||||
raise ValueError(f'Unexpected transcription: {text!r}')
|
||||
print(json.dumps({'sherpaVersion': sherpa_onnx.__version__, 'text': text,
|
||||
'audioSeconds': len(samples) / sample_rate,
|
||||
'decodeSeconds': time.monotonic() - start}, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user