From c5b57e85b0759bac594a50d9dc870fa1b26d155b Mon Sep 17 00:00:00 2001 From: Guillaume ETHEVE Date: Fri, 6 Nov 2026 02:13:43 +0100 Subject: [PATCH] fix: distinguish automatic local language from legacy English captures --- app/native/cloud-stt-provider.ts | 5 +++-- tests/cloud-stt.test.cjs | 2 ++ tests/voice-finalization.test.cjs | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/native/cloud-stt-provider.ts b/app/native/cloud-stt-provider.ts index 566cb1d7..51bde438 100644 --- a/app/native/cloud-stt-provider.ts +++ b/app/native/cloud-stt-provider.ts @@ -14,7 +14,7 @@ export type VoiceProviderSelection = { provider: VoiceProviderKind; /** * Spoken language the provider should expect (ISO 639-1); empty lets it - * detect the language. Cloud providers only. + * detect the language. Also used by on-device Whisper. */ language?: string; elevenLabsApiKey: string; @@ -77,7 +77,8 @@ 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): string { - return `${selection.provider}:${(selection.language ?? "").trim().toLowerCase()}`; + const fallback = selection.provider === "onboard-whisper" ? "en" : ""; + return `${selection.provider}:${(selection.language ?? fallback).trim().toLowerCase()}`; } /** Whether createCloudSttClient would return a cloud client for this selection. */ diff --git a/tests/cloud-stt.test.cjs b/tests/cloud-stt.test.cjs index a092deb3..5ca17214 100644 --- a/tests/cloud-stt.test.cjs +++ b/tests/cloud-stt.test.cjs @@ -207,6 +207,8 @@ test('provider selection falls back to on-device without a key and connects the // A running capture is shared only on the same provider and language. assert.equal(transcriptionKey({ provider: 'soniox', language: ' JA ' }), 'soniox:ja'); assert.notEqual(transcriptionKey({ provider: 'soniox' }), transcriptionKey({ provider: 'soniox', language: 'ja' })); + assert.equal(transcriptionKey({ provider: 'onboard-whisper' }), transcriptionKey({ provider: 'onboard-whisper', language: 'en' })); + assert.notEqual(transcriptionKey({ provider: 'onboard-whisper' }), transcriptionKey({ provider: 'onboard-whisper', language: '' })); const statuses = []; const options = { onTranscript() {}, onStatus: status => statuses.push(status), onError() {} }; const selection = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: ' ', sonioxApiKey: 'soniox-key' }; diff --git a/tests/voice-finalization.test.cjs b/tests/voice-finalization.test.cjs index b433418f..565151e0 100644 --- a/tests/voice-finalization.test.cjs +++ b/tests/voice-finalization.test.cjs @@ -173,7 +173,7 @@ function androidBridge() { '@nativescript/core': { Utils: { android: { getApplicationContext: () => ({}) } } }, './speech-pause': { SpeechPauseDetector: class { reset() {} } }, './cloud-stt-provider': { createCloudSttClient: () => null, - transcriptionKey: options => `${options.provider}:${options.language ?? ''}` }, + transcriptionKey: options => `${options.provider}:${options.language ?? (options.provider === 'onboard-whisper' ? 'en' : '')}` }, }, { global: { isAndroid: true }, com: { faceclaw: { app: { FaceclawVoiceController: function () { return controller; }, FaceclawVoiceControllerListener: function (listener) { return listener; }, @@ -193,8 +193,11 @@ test('local Whisper receives French and restarts for auto or English, sharing an assert.equal(controller.starts, 2); bridge.retargetContinuousCapture({ provider: 'onboard-whisper' }); // An omitted language preserves the native bridge's original English behavior. + assert.equal(controller.language, 'en'); + assert.equal(controller.starts, 3); bridge.retargetContinuousCapture({ provider: 'onboard-whisper', language: 'en' }); assert.equal(controller.language, 'en'); + assert.equal(controller.starts, 3); bridge.stop(); });