功能: - 基于 ONNX 的语音识别引擎 - 多语言支持(中文、英文、日语、韩语) - 模型加载器(支持 SenseVoice/Whisper/Paraformer) - 音频采集和处理模块(VAD、重采样、归一化) - 文本输出模块(剪贴板) - CLI 命令行工具 - Electron GUI 界面 - Windows x64 打包配置 文档: - PRD 产品需求文档 - README 项目说明 - 开发指南 - Windows 构建指南 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
106 lines
2.4 KiB
TypeScript
106 lines
2.4 KiB
TypeScript
/**
|
||
* 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();
|
||
});
|