@@ -8,8 +8,19 @@ import { ipcMain, nativeTheme, shell, dialog, BrowserWindow, app } from 'electro
88import { join } from 'node:path'
99import { existsSync } from 'node:fs'
1010import { IPC_CHANNELS , CHANNEL_IPC_CHANNELS , CHAT_IPC_CHANNELS , AGENT_IPC_CHANNELS , ENVIRONMENT_IPC_CHANNELS , INSTALLER_IPC_CHANNELS , PROXY_IPC_CHANNELS , GITHUB_RELEASE_IPC_CHANNELS , SYSTEM_PROMPT_IPC_CHANNELS , MEMORY_IPC_CHANNELS , CHAT_TOOL_IPC_CHANNELS , FEISHU_IPC_CHANNELS , DINGTALK_IPC_CHANNELS , WECHAT_IPC_CHANNELS } from '@proma/shared'
11- import { USER_PROFILE_IPC_CHANNELS , SETTINGS_IPC_CHANNELS , QUICK_TASK_IPC_CHANNELS , APP_ICON_IPC_CHANNELS , DOCK_BADGE_IPC_CHANNELS } from '../types'
12- import type { QuickTaskSubmitInput } from '../types'
11+ import { USER_PROFILE_IPC_CHANNELS , SETTINGS_IPC_CHANNELS , QUICK_TASK_IPC_CHANNELS , VOICE_DICTATION_IPC_CHANNELS , APP_ICON_IPC_CHANNELS , DOCK_BADGE_IPC_CHANNELS } from '../types'
12+ import type {
13+ QuickTaskSubmitInput ,
14+ VoiceDictationAudioChunkInput ,
15+ VoiceDictationCommitInput ,
16+ VoiceDictationCommitResult ,
17+ VoiceDictationResizeInput ,
18+ VoiceDictationSettings ,
19+ VoiceDictationSettingsUpdate ,
20+ VoiceDictationStartInput ,
21+ VoiceDictationStopInput ,
22+ VoiceDictationTestResult ,
23+ } from '../types'
1324import type {
1425 RuntimeStatus ,
1526 GitRepoStatus ,
@@ -2607,4 +2618,101 @@ export function registerIpcHandlers(): void {
26072618 return reregisterAllGlobalShortcuts ( )
26082619 }
26092620 )
2621+
2622+ // ===== 语音输入 =====
2623+
2624+ ipcMain . handle (
2625+ VOICE_DICTATION_IPC_CHANNELS . GET_SETTINGS ,
2626+ async ( ) : Promise < VoiceDictationSettings > => {
2627+ const { getVoiceDictationSettings } = await import ( './lib/voice-dictation-settings-service' )
2628+ return getVoiceDictationSettings ( )
2629+ }
2630+ )
2631+
2632+ ipcMain . handle (
2633+ VOICE_DICTATION_IPC_CHANNELS . UPDATE_SETTINGS ,
2634+ async ( _ , updates : VoiceDictationSettingsUpdate ) : Promise < VoiceDictationSettings > => {
2635+ const { updateVoiceDictationSettings } = await import ( './lib/voice-dictation-settings-service' )
2636+ return updateVoiceDictationSettings ( updates )
2637+ }
2638+ )
2639+
2640+ ipcMain . handle (
2641+ VOICE_DICTATION_IPC_CHANNELS . TEST_CONNECTION ,
2642+ async ( _ , updates ?: VoiceDictationSettingsUpdate ) : Promise < VoiceDictationTestResult > => {
2643+ const { getVoiceDictationSettings } = await import ( './lib/voice-dictation-settings-service' )
2644+ const { testDoubaoAsrConnection } = await import ( './lib/doubao-asr-service' )
2645+ const settings = { ...getVoiceDictationSettings ( ) , ...( updates ?? { } ) }
2646+ return testDoubaoAsrConnection ( settings )
2647+ }
2648+ )
2649+
2650+ ipcMain . handle (
2651+ VOICE_DICTATION_IPC_CHANNELS . TOGGLE ,
2652+ async ( event ) : Promise < void > => {
2653+ const { toggleVoiceDictationWindow } = await import ( './lib/voice-dictation-window' )
2654+ const sourceWindow = BrowserWindow . fromWebContents ( event . sender )
2655+ toggleVoiceDictationWindow ( { targetIsProma : ! ! sourceWindow } )
2656+ }
2657+ )
2658+
2659+ ipcMain . handle (
2660+ VOICE_DICTATION_IPC_CHANNELS . START ,
2661+ async ( event , input : VoiceDictationStartInput ) : Promise < void > => {
2662+ const { getVoiceDictationSettings } = await import ( './lib/voice-dictation-settings-service' )
2663+ const { startDoubaoAsrSession } = await import ( './lib/doubao-asr-service' )
2664+ const win = BrowserWindow . fromWebContents ( event . sender )
2665+ if ( ! win ) throw new Error ( '语音输入窗口不存在' )
2666+ await startDoubaoAsrSession ( input . sessionId , getVoiceDictationSettings ( ) , win )
2667+ }
2668+ )
2669+
2670+ ipcMain . handle (
2671+ VOICE_DICTATION_IPC_CHANNELS . SEND_AUDIO ,
2672+ async ( _ , input : VoiceDictationAudioChunkInput ) : Promise < void > => {
2673+ const { sendDoubaoAsrAudio } = await import ( './lib/doubao-asr-service' )
2674+ sendDoubaoAsrAudio ( input . sessionId , input . data )
2675+ }
2676+ )
2677+
2678+ ipcMain . handle (
2679+ VOICE_DICTATION_IPC_CHANNELS . STOP ,
2680+ async ( _ , input : VoiceDictationStopInput ) : Promise < void > => {
2681+ const { stopDoubaoAsrSession } = await import ( './lib/doubao-asr-service' )
2682+ await stopDoubaoAsrSession ( input . sessionId )
2683+ }
2684+ )
2685+
2686+ ipcMain . handle (
2687+ VOICE_DICTATION_IPC_CHANNELS . CANCEL ,
2688+ async ( _ , input : VoiceDictationStopInput ) : Promise < void > => {
2689+ const { cancelDoubaoAsrSession } = await import ( './lib/doubao-asr-service' )
2690+ cancelDoubaoAsrSession ( input . sessionId )
2691+ }
2692+ )
2693+
2694+ ipcMain . handle (
2695+ VOICE_DICTATION_IPC_CHANNELS . COMMIT ,
2696+ async ( _ , input : VoiceDictationCommitInput ) : Promise < VoiceDictationCommitResult > => {
2697+ const { getVoiceDictationSettings } = await import ( './lib/voice-dictation-settings-service' )
2698+ const { commitVoiceDictationText } = await import ( './lib/text-output-service' )
2699+ return commitVoiceDictationText ( input . text , getVoiceDictationSettings ( ) )
2700+ }
2701+ )
2702+
2703+ ipcMain . handle (
2704+ VOICE_DICTATION_IPC_CHANNELS . HIDE ,
2705+ async ( ) : Promise < void > => {
2706+ const { hideVoiceDictationWindow } = await import ( './lib/voice-dictation-window' )
2707+ hideVoiceDictationWindow ( )
2708+ }
2709+ )
2710+
2711+ ipcMain . handle (
2712+ VOICE_DICTATION_IPC_CHANNELS . RESIZE ,
2713+ async ( _ , input : VoiceDictationResizeInput ) : Promise < void > => {
2714+ const { resizeVoiceDictationWindow } = await import ( './lib/voice-dictation-window' )
2715+ resizeVoiceDictationWindow ( input . height )
2716+ }
2717+ )
26102718}
0 commit comments