chore: preload whisper models

This commit is contained in:
haritabh-z01 2025-07-06 16:02:51 +05:30
parent 3f8ea518f6
commit c0cbbcdda9
9 changed files with 198 additions and 12 deletions

View file

@ -19,6 +19,7 @@ const t = initTRPC.create({
declare global {
var modelManagerService: any;
var transcriptionService: any;
}
export const modelsRouter = t.router({
@ -120,9 +121,14 @@ export const modelsRouter = t.router({
if (!globalThis.modelManagerService) {
throw new Error("Model manager service not initialized");
}
return await globalThis.modelManagerService.setSelectedModel(
input.modelId,
);
await globalThis.modelManagerService.setSelectedModel(input.modelId);
// Notify transcription service about model change
if (globalThis.transcriptionService) {
await globalThis.transcriptionService.handleModelChange();
}
return true;
}),
// Subscriptions using Observables

View file

@ -32,6 +32,66 @@ const SetShortcutSchema = z.object({
shortcut: z.string(),
});
export const settingsRouter = t.router({
// Get all settings
getSettings: t.procedure.query(async () => {
try {
if (!globalThis.settingsService) {
throw new Error("SettingsService not available");
}
return await globalThis.settingsService.getAllSettings();
} catch (error) {
if (globalThis.logger) {
globalThis.logger.main.error("Error getting settings:", error);
}
return {};
}
}),
// Update transcription settings
updateTranscriptionSettings: t.procedure
.input(
z.object({
language: z.string().optional(),
autoTranscribe: z.boolean().optional(),
confidenceThreshold: z.number().optional(),
enablePunctuation: z.boolean().optional(),
enableTimestamps: z.boolean().optional(),
preloadWhisperModel: z.boolean().optional(),
}),
)
.mutation(async ({ input }) => {
try {
if (!globalThis.settingsService) {
throw new Error("SettingsService not available");
}
// Check if preloadWhisperModel setting is changing
const currentSettings =
await globalThis.settingsService.getTranscriptionSettings();
const preloadChanged =
input.preloadWhisperModel !== undefined &&
currentSettings &&
input.preloadWhisperModel !== currentSettings.preloadWhisperModel;
await globalThis.settingsService.setTranscriptionSettings(input);
// Handle model preloading change
if (preloadChanged && globalThis.transcriptionService) {
await globalThis.transcriptionService.handleModelChange();
}
return true;
} catch (error) {
if (globalThis.logger) {
globalThis.logger.main.error(
"Error updating transcription settings:",
error,
);
}
throw error;
}
}),
// Get formatter configuration
getFormatterConfig: t.procedure.query(async () => {
try {