diff --git a/config/main-sync-fs-baseline.txt b/config/main-sync-fs-baseline.txt index e2c5517cf6e..a52a24f1b40 100644 --- a/config/main-sync-fs-baseline.txt +++ b/config/main-sync-fs-baseline.txt @@ -496,6 +496,7 @@ 10 src/main/speech/openai-api-key-store.ts 2 src/main/speech/speech-model-download-cleanup.ts 1 src/main/speech/speech-model-download-transport.ts +1 src/main/speech/speech-model-files.ts 2 src/main/speech/speech-model-http-download.ts 2 src/main/speech/stt-gpu-failure-marker.ts 1 src/main/speech/stt-worker-model-config.ts diff --git a/package.json b/package.json index eb1be844fe2..87488709503 100644 --- a/package.json +++ b/package.json @@ -394,6 +394,7 @@ "@orca/windows-registry": "workspace:*", "@orca/windows-security": "workspace:*", "@transcribe-cpp/darwin-arm64-metal": "0.4.1", + "@transcribe-cpp/darwin-x64-cpu": "0.4.1", "@transcribe-cpp/linux-arm64-cpu-vulkan": "0.4.1", "@transcribe-cpp/linux-x64-cpu-vulkan": "0.4.1", "@transcribe-cpp/win32-x64-cpu-vulkan": "0.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3051c0d9d1a..153d8340ac6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -705,6 +705,9 @@ importers: '@transcribe-cpp/darwin-arm64-metal': specifier: 0.4.1 version: 0.4.1 + '@transcribe-cpp/darwin-x64-cpu': + specifier: 0.4.1 + version: 0.4.1 '@transcribe-cpp/linux-arm64-cpu-vulkan': specifier: 0.4.1 version: 0.4.1 diff --git a/src/main/runtime/speech/runtime-mobile-dictation-controller.ts b/src/main/runtime/speech/runtime-mobile-dictation-controller.ts index 39e907f9bbb..e5ece2e4290 100644 --- a/src/main/runtime/speech/runtime-mobile-dictation-controller.ts +++ b/src/main/runtime/speech/runtime-mobile-dictation-controller.ts @@ -1,5 +1,6 @@ import { getDefaultVoiceSettings } from '../../../shared/constants' import { MOBILE_DICTATION_RECONNECT_GRACE_MS } from '../../../shared/rpc-contract/speech-params' +import { speechModelNotReadyError } from '../../../shared/speech-model-retirement' import { getSpeechModelManager, getSpeechSttService } from '../../speech/speech-runtime-service' import { getCatalogModel, isLocalSpeechModel } from '../../speech/model-catalog' import { @@ -56,7 +57,7 @@ export class RuntimeMobileDictationController { } const modelState = await getSpeechModelManager(store).getModelState(modelId) if (modelState.status !== 'ready') { - throw new Error(`voice_model_not_ready:${modelState.status}`) + throw new Error(speechModelNotReadyError(modelState)) } const clientId = params.clientId if (!clientId) { diff --git a/src/main/speech/model-catalog.ts b/src/main/speech/model-catalog.ts index ae62f7a9868..b9fd5eea380 100644 --- a/src/main/speech/model-catalog.ts +++ b/src/main/speech/model-catalog.ts @@ -1,9 +1,15 @@ import type { SpeechModelManifest } from '../../shared/speech-types' import { DICTATION_LANGUAGES, + NEMOTRON_DICTATION_LANGUAGES, SENSE_VOICE_DICTATION_LANGUAGES } from '../../shared/dictation-language' import { getSpeechModelDownloadMetadata } from './model-download-catalog' +import { getGgufSpeechModelDownload } from './speech-model-gguf-downloads' + +const legacy = (id: Parameters[0]) => ({ + legacyDownloadFiles: getSpeechModelDownloadMetadata(id).downloadFiles +}) export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ { @@ -14,10 +20,10 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ type: 'transducer', provider: 'local', language: 'multilingual', - ...getSpeechModelDownloadMetadata('parakeet-tdt-0.6b-v3-int8'), + ...getGgufSpeechModelDownload('parakeet-tdt-0.6b-v3-int8'), + ...legacy('parakeet-tdt-0.6b-v3-int8'), sampleRate: 16000, streaming: false, - modelingUnit: 'bpe', recommended: true }, { @@ -28,10 +34,10 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ type: 'transducer', provider: 'local', language: 'en', - ...getSpeechModelDownloadMetadata('parakeet-tdt-0.6b-v2-int8'), + ...getGgufSpeechModelDownload('parakeet-tdt-0.6b-v2-int8'), + ...legacy('parakeet-tdt-0.6b-v2-int8'), sampleRate: 16000, - streaming: false, - modelingUnit: 'bpe' + streaming: false }, { id: 'zipformer-bilingual-zh-en', @@ -43,7 +49,9 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ ...getSpeechModelDownloadMetadata('zipformer-bilingual-zh-en'), sampleRate: 16000, streaming: true, - modelingUnit: 'cjkchar+bpe' + modelingUnit: 'cjkchar+bpe', + // transcribe-cpp has no zipformer; SenseVoice covers Chinese and English. + replacedBy: 'sense-voice-zh-en-ja-ko-yue' }, { id: 'paraformer-bilingual-zh-en', @@ -55,7 +63,9 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ language: 'zh-en', ...getSpeechModelDownloadMetadata('paraformer-bilingual-zh-en'), sampleRate: 16000, - streaming: true + streaming: true, + // transcribe-cpp has no paraformer; SenseVoice covers Chinese and English. + replacedBy: 'sense-voice-zh-en-ja-ko-yue' }, { id: 'zipformer-streaming-en-20m', @@ -81,7 +91,9 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ ...getSpeechModelDownloadMetadata('zipformer-streaming-zh-14m'), sampleRate: 16000, streaming: true, - modelingUnit: 'cjkchar' + modelingUnit: 'cjkchar', + // transcribe-cpp has no zipformer. + replacedBy: 'nemotron-3.5-asr-streaming-0.6b' }, { id: 'zipformer-streaming-korean', @@ -93,7 +105,9 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ ...getSpeechModelDownloadMetadata('zipformer-streaming-korean'), sampleRate: 16000, streaming: true, - modelingUnit: 'bpe' + modelingUnit: 'bpe', + // transcribe-cpp has no zipformer. + replacedBy: 'nemotron-3.5-asr-streaming-0.6b' }, { id: 'parakeet-tdt-ctc-0.6b-ja-int8', @@ -104,7 +118,9 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ language: 'ja', ...getSpeechModelDownloadMetadata('parakeet-tdt-ctc-0.6b-ja-int8'), sampleRate: 16000, - streaming: false + streaming: false, + // No GGUF conversion exists; SenseVoice covers Japanese. + replacedBy: 'sense-voice-zh-en-ja-ko-yue' }, { id: 'whisper-tiny', @@ -113,7 +129,8 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ type: 'whisper', provider: 'local', language: 'multilingual', - ...getSpeechModelDownloadMetadata('whisper-tiny'), + ...getGgufSpeechModelDownload('whisper-tiny'), + ...legacy('whisper-tiny'), dictationLanguages: DICTATION_LANGUAGES, sampleRate: 16000, streaming: false @@ -126,11 +143,26 @@ export const SPEECH_MODEL_CATALOG: SpeechModelManifest[] = [ type: 'senseVoice', provider: 'local', language: 'multilingual', - ...getSpeechModelDownloadMetadata('sense-voice-zh-en-ja-ko-yue'), + ...getGgufSpeechModelDownload('sense-voice-zh-en-ja-ko-yue'), + ...legacy('sense-voice-zh-en-ja-ko-yue'), dictationLanguages: SENSE_VOICE_DICTATION_LANGUAGES, sampleRate: 16000, streaming: false }, + { + id: 'nemotron-3.5-asr-streaming-0.6b', + label: 'Nemotron 3.5', + description: + 'Korean, Chinese, Japanese and many more languages, with automatic language detection.', + type: 'transducer', + provider: 'local', + language: 'multilingual', + ...getGgufSpeechModelDownload('nemotron-3.5-asr-streaming-0.6b'), + dictationLanguages: NEMOTRON_DICTATION_LANGUAGES, + sampleRate: 16000, + // Decoded per chunk for now; live text arrives with the streaming engine path. + streaming: false + }, { id: 'openai-gpt-4o-mini-transcribe', label: 'GPT-4o mini Transcribe', diff --git a/src/main/speech/model-manager.test.ts b/src/main/speech/model-manager.test.ts index d374b2b0bc0..5767578b0fa 100644 --- a/src/main/speech/model-manager.test.ts +++ b/src/main/speech/model-manager.test.ts @@ -134,6 +134,32 @@ describe('ModelManager', () => { } }) + it('reports a model downloaded in the old sherpa-onnx format as needing an update', async () => { + const dir = mkdtempSync(join(tmpdir(), 'orca-model-manager-')) + try { + const manager = new ModelManager(dir, openElectronSpeechDownloadRequest) + const modelDir = manager.getModelDir('parakeet-tdt-0.6b-v2-int8') + mkdirSync(modelDir, { recursive: true }) + for (const [name, size] of [ + ['encoder.int8.onnx', 652_184_296], + ['decoder.int8.onnx', 7_257_753], + ['joiner.int8.onnx', 1_739_080], + ['tokens.txt', 9_384] + ] as const) { + writeFileSync(join(modelDir, name), '') + truncateSync(join(modelDir, name), size) + } + + await expect(manager.getModelState('parakeet-tdt-0.6b-v2-int8')).resolves.toEqual({ + id: 'parakeet-tdt-0.6b-v2-int8', + status: 'not-downloaded', + needsUpdate: true + }) + } finally { + rmSync(dir, { recursive: true, force: true }) + } + }) + it('aborts an in-flight model download request when cancelled', async () => { const dir = mkdtempSync(join(tmpdir(), 'orca-model-manager-')) try { diff --git a/src/main/speech/model-manager.ts b/src/main/speech/model-manager.ts index 00e3b0de910..aaa212b7101 100644 --- a/src/main/speech/model-manager.ts +++ b/src/main/speech/model-manager.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, rmSync, statSync } from 'node:fs' +import { existsSync, mkdirSync, rmSync } from 'node:fs' import { rename, rm } from 'node:fs/promises' import { join, relative, resolve } from 'node:path' import type { @@ -14,6 +14,7 @@ import { type SpeechModelCacheDir } from './model-cache-path' import { SpeechModelDownloadTransport } from './speech-model-download-transport' +import { hasSpeechModelFiles } from './speech-model-files' import type { OpenSpeechDownloadRequest } from './speech-model-download-response' import { getAppEnvironment } from '../../shared/app-environment' import { @@ -108,11 +109,14 @@ export class ModelManager extends SpeechModelDownloadTransport { } const modelDir = this.getModelDir(modelId) - if (existsSync(modelDir) && this.validateModelFiles(manifest, modelDir)) { + if (existsSync(modelDir) && hasSpeechModelFiles(manifest.downloadFiles, modelDir)) { const state: SpeechModelState = { id: modelId, status: 'ready' } this.modelStates.set(modelId, state) return state } + if (existsSync(modelDir) && hasSpeechModelFiles(manifest.legacyDownloadFiles, modelDir)) { + return { id: modelId, status: 'not-downloaded', needsUpdate: true } + } return { id: modelId, status: 'not-downloaded' } } @@ -135,19 +139,6 @@ export class ModelManager extends SpeechModelDownloadTransport { return modelDir } - private validateModelFiles(manifest: SpeechModelManifest, modelDir: string): boolean { - if (!manifest.downloadFiles) { - return false - } - return manifest.downloadFiles.every(({ name, sizeBytes }) => { - try { - return statSync(join(modelDir, name)).size === sizeBytes - } catch { - return false - } - }) - } - async downloadModel(modelId: string): Promise { // Do not await migration: downloads cannot race it, and cancellation needs synchronous setup. if (this.activeDownloads.has(modelId)) { @@ -166,7 +157,7 @@ export class ModelManager extends SpeechModelDownloadTransport { } const modelDir = this.getModelDir(modelId) - if (existsSync(modelDir) && this.validateModelFiles(manifest, modelDir)) { + if (existsSync(modelDir) && hasSpeechModelFiles(manifest.downloadFiles, modelDir)) { this.updateState(modelId, 'ready') return } @@ -330,7 +321,7 @@ export class ModelManager extends SpeechModelDownloadTransport { completedBytes += file.sizeBytes } - if (!this.validateModelFiles(manifest, stagingDir)) { + if (!hasSpeechModelFiles(manifest.downloadFiles, stagingDir)) { throw new Error('Model files missing after download') } } diff --git a/src/main/speech/speech-model-files.ts b/src/main/speech/speech-model-files.ts new file mode 100644 index 00000000000..7e454c142b1 --- /dev/null +++ b/src/main/speech/speech-model-files.ts @@ -0,0 +1,20 @@ +import { statSync } from 'node:fs' +import { join } from 'node:path' +import type { SpeechModelDownloadFile } from '../../shared/speech-types' + +/** Whether every listed file is in `modelDir` at its expected size. */ +export function hasSpeechModelFiles( + files: readonly SpeechModelDownloadFile[] | undefined, + modelDir: string +): boolean { + if (!files) { + return false + } + return files.every(({ name, sizeBytes }) => { + try { + return statSync(join(modelDir, name)).size === sizeBytes + } catch { + return false + } + }) +} diff --git a/src/main/speech/speech-model-gguf-downloads.ts b/src/main/speech/speech-model-gguf-downloads.ts new file mode 100644 index 00000000000..36211084182 --- /dev/null +++ b/src/main/speech/speech-model-gguf-downloads.ts @@ -0,0 +1,60 @@ +import type { SpeechModelDownloadFile } from '../../shared/speech-types' + +type GgufDownload = readonly [ + repository: string, + revision: string, + name: string, + sizeBytes: number, + sha256: string +] + +// handy-computer's GGUF conversions for transcribe-cpp 0.4.x, pinned by revision and hash. +const GGUF_DOWNLOADS = { + 'parakeet-tdt-0.6b-v3-int8': [ + 'handy-computer/parakeet-tdt-0.6b-v3-gguf', + '85ac09ea12fc4b1112fa76810059364bc6adc9de', + 'parakeet-tdt-0.6b-v3-Q8_0.gguf', + 739_508_576, + '5859f77944efcd8eafa23a6350731960b2b55b2203df51f319665c807d802cc7' + ], + 'parakeet-tdt-0.6b-v2-int8': [ + 'handy-computer/parakeet-tdt-0.6b-v2-gguf', + '07cee0616125a08ef619729bb47f40ef747e4bc4', + 'parakeet-tdt-0.6b-v2-Q8_0.gguf', + 729_574_912, + 'f0d0e99cebb6d3b83f1f7069b82b5d3c2e39a54545b0da039cb4bafd9c4e5caa' + ], + 'whisper-tiny': [ + 'handy-computer/whisper-tiny-gguf', + '6687f30c99641ee265df421e582354adbc8848fc', + 'whisper-tiny-Q8_0.gguf', + 45_981_088, + '325b9c7997cd1eff81ef709d55766565e71be696130cc3a3d444713798706834' + ], + 'sense-voice-zh-en-ja-ko-yue': [ + 'handy-computer/SenseVoiceSmall-gguf', + '4a08b8e900b38a977e32eb08d5d0697d6e72ba04', + 'SenseVoiceSmall-Q8_0.gguf', + 252_684_608, + '6c759ee4c9748c9b3f7a5a60ca74f0f7e685fb9d45d1378fce7cfd62f59adf29' + ], + 'nemotron-3.5-asr-streaming-0.6b': [ + 'handy-computer/nemotron-3.5-asr-streaming-0.6b-gguf', + '6d44e540bc31b0de1dbe174a3cea87f53a7f22fb', + 'nemotron-3.5-asr-streaming-0.6b-Q8_0.gguf', + 751_094_240, + 'b94545b313b3223fda7b2857a52681da813935c2127643d1e9ff0c23d988089c' + ] +} satisfies Record + +export type GgufSpeechModelId = keyof typeof GGUF_DOWNLOADS + +export function getGgufSpeechModelDownload(modelId: GgufSpeechModelId): { + downloadFiles: SpeechModelDownloadFile[] + files: string[] + sizeBytes: number +} { + const [repository, revision, name, sizeBytes, sha256] = GGUF_DOWNLOADS[modelId] + const url = `https://huggingface.co/${repository}/resolve/${revision}/${encodeURIComponent(name)}?download=true` + return { downloadFiles: [{ name, url, sizeBytes, sha256 }], files: [name], sizeBytes } +} diff --git a/src/main/speech/stt-session-start.ts b/src/main/speech/stt-session-start.ts index 03d0945b3ad..4d21c3c6364 100644 --- a/src/main/speech/stt-session-start.ts +++ b/src/main/speech/stt-session-start.ts @@ -1,3 +1,4 @@ +import { SPEECH_MODEL_NEEDS_UPDATE_ERROR } from '../../shared/speech-model-retirement' import { engineDictationLanguage } from '../../shared/dictation-language' import type { SpeechModelManifest } from '../../shared/speech-types' import { getCatalogModel } from './model-catalog' @@ -125,7 +126,11 @@ async function requireModelReady(state: SttSessionState, modelId: string): Promi const modelState = await state.modelManager.getModelState(modelId) if (modelState.status !== 'ready') { await teardownIdleSttEngine(state, modelId) - throw new Error(`Model not ready: ${modelState.status}`) + throw new Error( + modelState.needsUpdate + ? SPEECH_MODEL_NEEDS_UPDATE_ERROR + : `Model not ready: ${modelState.status}` + ) } } diff --git a/src/main/speech/stt-transcribe-cpp-recognizer.ts b/src/main/speech/stt-transcribe-cpp-recognizer.ts index 5230e3a3446..dddd649d07d 100644 --- a/src/main/speech/stt-transcribe-cpp-recognizer.ts +++ b/src/main/speech/stt-transcribe-cpp-recognizer.ts @@ -45,11 +45,15 @@ export async function createTranscribeCppRecognizer( // The child runs one call at a time, so every stream can share one session. const session = model.createSession({ nThreads: performanceCoreThreads() }) const vocabulary = await readVocabulary(init.hotwordsFilePath) + const { languages } = model.capabilities + // The setting is ISO-639-1; Nemotron names locales (ko-KR) and rejects the bare code. + const language = init.language + ? (languages.find((code) => code === init.language) ?? + languages.find((code) => code.startsWith(`${init.language}-`))) + : undefined const options: TranscribeCpp.TranscribeOptions = { timestamps: 'none', - ...(init.language && model.capabilities.languages.includes(init.language) - ? { language: init.language } - : {}), + ...(language ? { language } : {}), ...(vocabulary.length > 0 && model.supports('vocabulary') ? { vocabulary } : {}) } const modelRate = model.capabilities.nativeSampleRate || init.sampleRate diff --git a/src/renderer/src/components/dictation/dictation-toasts.ts b/src/renderer/src/components/dictation/dictation-toasts.ts index 42c4a21d44c..1f8ec8f87c4 100644 --- a/src/renderer/src/components/dictation/dictation-toasts.ts +++ b/src/renderer/src/components/dictation/dictation-toasts.ts @@ -3,6 +3,7 @@ import { useAppStore } from '@/store' import { translate } from '@/i18n/i18n' import { compactIpcErrorMessage } from '@/lib/ipc-error' import { hostDictationErrorMessage } from '../../../../shared/host-dictation-error-messages' +import { SPEECH_MODEL_NEEDS_UPDATE_ERROR } from '../../../../shared/speech-model-retirement' function openVoiceSettingsAction(): { label: string; onClick: () => void } { return { @@ -76,6 +77,14 @@ export function showDictationStartErrorToast(message: string): void { 'Microphone access denied. Grant access in system settings, then restart Orca.' ) ) + } else if (message.includes(SPEECH_MODEL_NEEDS_UPDATE_ERROR)) { + toast( + translate( + 'auto.components.dictation.DictationController.modelNeedsUpdate', + 'Your speech model needs an update to keep working. Update it to the faster version in Settings > Voice.' + ), + { action: openVoiceSettingsAction() } + ) } else if (message.includes('not ready') || detail.startsWith('voice_model_not_ready')) { toast( translate( diff --git a/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.fixture.tsx b/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.fixture.tsx new file mode 100644 index 00000000000..11f928d1abb --- /dev/null +++ b/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.fixture.tsx @@ -0,0 +1,59 @@ +import { defineFixture } from '../../../component-fixtures/component-fixture' +import { getDefaultVoiceSettings } from '../../../../../shared/constants' +import type { SpeechModelManifest } from '../../../../../shared/speech-types' +import { VoiceSpeechModelSection } from './VoiceSpeechModelSection' + +function model(id: string, label: string, sizeBytes: number, description: string) { + return { + id, + label, + description, + type: 'transducer', + provider: 'local', + language: 'en', + sizeBytes, + sampleRate: 16000, + streaming: false + } satisfies SpeechModelManifest +} + +const catalog = [ + model('v3', 'Parakeet TDT v3', 739_508_576, 'Highest accuracy for 25 European languages.'), + model( + 'v2', + 'Parakeet TDT v2', + 729_574_912, + 'English only. Faster than v3 with similar accuracy.' + ), + model( + 'nemotron', + 'Nemotron 3.5', + 751_094_240, + '28 languages including Korean, Chinese and Japanese.' + ) +] + +export const updateAvailable = defineFixture({ + width: 640, + render: () => ( + {}} + onOpenOpenAiDialog={() => {}} + onRefreshModelStates={() => {}} + /> + ), + interact: (frame) => { + frame + .querySelector('button') + ?.dispatchEvent( + new PointerEvent('pointerdown', { bubbles: true, button: 0, pointerType: 'mouse' }) + ) + } +}) diff --git a/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.tsx b/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.tsx index 3ba1877dd02..a7bfa6c4191 100644 --- a/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.tsx +++ b/src/renderer/src/components/settings/voice/VoiceSpeechModelSection.tsx @@ -92,6 +92,8 @@ export function VoiceSpeechModelSection({ mState?.status === 'downloading' || mState?.status === 'extracting' const isActive = voiceSettings.sttModel === manifest.id const isCloud = manifest.provider === 'openai' + // Only the old sherpa-onnx files are on disk; downloading replaces them. + const needsUpdate = mState?.needsUpdate === true && !isDownloading const deletePending = pendingDeleteModelIds.has(manifest.id) const sizeMb = manifest.sizeBytes ? Math.round(manifest.sizeBytes / 1_000_000) : null @@ -164,8 +166,17 @@ export function VoiceSpeechModelSection({

{speechModelDescription(manifest)}

+ {needsUpdate && ( +

+ {t( + 'auto.components.settings.VoicePane.updateToFasterVersion', + 'Update to the faster version ({{value0}} MB)', + { value0: sizeMb } + )} +

+ )} - {!isCloud && isReady ? ( + {!isCloud && (isReady || needsUpdate) ? (