impress_asr_input/src/electron-main.ts
impressionyang 7c51542918 Initial commit: Impress ASR Input 项目基础框架
功能:
- 基于 ONNX 的语音识别引擎
- 多语言支持(中文、英文、日语、韩语)
- 模型加载器(支持 SenseVoice/Whisper/Paraformer)
- 音频采集和处理模块(VAD、重采样、归一化)
- 文本输出模块(剪贴板)
- CLI 命令行工具
- Electron GUI 界面
- Windows x64 打包配置

文档:
- PRD 产品需求文档
- README 项目说明
- 开发指南
- Windows 构建指南

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-20 16:10:11 +08:00

106 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Impress ASR Input - Electron 主进程
* 注意:此文件需要 electron 依赖运行前请执行npm install electron --save-dev
*/
import { app, BrowserWindow, ipcMain, globalShortcut, clipboard } from 'electron';
import { join } from 'path';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
let mainWindow: BrowserWindow | null = null;
function createWindow() {
mainWindow = new BrowserWindow({
width: 400,
height: 600,
title: 'Impress ASR Input',
webPreferences: {
preload: join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
resizable: false,
skipTaskbar: false,
alwaysOnTop: false,
});
// 加载主界面
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:5173');
} else {
mainWindow.loadFile(join(__dirname, '../ui/index.html'));
}
mainWindow.on('closed', () => {
mainWindow = null;
});
}
// 应用就绪时创建窗口
app.whenReady().then(() => {
createWindow();
// 注册全局热键
globalShortcut.register('CommandOrControl+Shift+Space', () => {
mainWindow?.webContents.send('toggle-recording');
});
globalShortcut.register('CommandOrControl+Escape', () => {
mainWindow?.webContents.send('stop-recording');
});
});
// IPC 处理
ipcMain.handle('start-recording', async () => {
// 启动录音
console.log('开始录音');
return { success: true };
});
ipcMain.handle('stop-recording', async () => {
// 停止录音
console.log('停止录音');
return { success: true };
});
ipcMain.handle('copy-to-clipboard', async (_, text: string) => {
clipboard.writeText(text);
return { success: true };
});
ipcMain.handle('get-settings', async () => {
// 获取设置
return {
language: 'zh',
outputMode: 'clipboard',
modelPath: './models/model.onnx',
};
});
ipcMain.handle('save-settings', async (_event: any, settings: Record<string, unknown>) => {
// 保存设置
console.log('保存设置:', settings);
return { success: true };
});
// 所有窗口关闭时退出应用
app.on('window-all-closed', () => {
globalShortcut.unregisterAll();
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// 应用退出前清理
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});