transcription-commands.ts
1 import type InterBrainPlugin from '../../../main'; 2 import { getRealtimeTranscriptionService } from '../services/transcription-service'; 3 import { UIService } from '../../../services/ui-service'; 4 5 /** 6 * Register real-time transcription commands 7 */ 8 export function registerTranscriptionCommands(plugin: InterBrainPlugin): void { 9 const transcriptionService = getRealtimeTranscriptionService(); 10 const uiService = new UIService(plugin.app); 11 12 /** 13 * Command: Start Real-Time Transcription 14 */ 15 plugin.addCommand({ 16 id: 'start-realtime-transcription', 17 name: 'Start Real-Time Transcription', 18 hotkeys: [{ modifiers: ['Mod', 'Shift'], key: 't' }], 19 callback: async () => { 20 // Check if already running 21 if (transcriptionService.isRunning()) { 22 uiService.showWarning('Transcription already running'); 23 return; 24 } 25 26 // Validate active file is markdown 27 const activeFile = plugin.app.workspace.getActiveFile(); 28 if (!activeFile || !activeFile.path.endsWith('.md')) { 29 uiService.showError('Please open a markdown file for transcript output'); 30 return; 31 } 32 33 // Get full file path (construct manually since getFullPath is private) 34 35 const vaultPath = (plugin.app.vault.adapter as any).basePath; 36 const transcriptPath = require('path').join(vaultPath, activeFile.path); 37 38 // Start transcription 39 try { 40 await transcriptionService.startTranscription(transcriptPath, { 41 model: 'small.en' 42 }); 43 } catch (error) { 44 console.error('[Transcription Commands] Failed to start:', error); 45 } 46 } 47 }); 48 49 /** 50 * Command: Stop Real-Time Transcription 51 */ 52 plugin.addCommand({ 53 id: 'stop-realtime-transcription', 54 name: 'Stop Real-Time Transcription', 55 hotkeys: [{ modifiers: ['Mod', 'Shift'], key: 't' }], // Same key toggles 56 callback: async () => { 57 if (!transcriptionService.isRunning()) { 58 uiService.showWarning('No active transcription'); 59 return; 60 } 61 62 await transcriptionService.stopTranscription(); 63 } 64 }); 65 } 66 67 /** 68 * Cleanup transcription service on plugin unload 69 */ 70 export function cleanupTranscriptionService(): void { 71 const transcriptionService = getRealtimeTranscriptionService(); 72 transcriptionService.cleanup(); 73 }