diff --git a/src/ui/main_window.cpp b/src/ui/main_window.cpp index 915167d..fd9b969 100644 --- a/src/ui/main_window.cpp +++ b/src/ui/main_window.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #ifdef Q_OS_WIN #include @@ -210,6 +212,10 @@ void MainWindow::setupTrayIcon() { activateWindow(); raise(); }); + auto* restartAction = trayMenu_->addAction("重启"); + connect(restartAction, &QAction::triggered, this, [this]() { + doRestart(); + }); trayMenu_->addSeparator(); auto* exitAction = trayMenu_->addAction("退出"); connect(exitAction, &QAction::triggered, this, [this]() { @@ -255,8 +261,11 @@ void MainWindow::setupMenuBar() { // 文件菜单 auto* fileMenu = menuBar()->addMenu("文件"); - auto* exportAction = fileMenu->addAction("导出结果"); - exportAction->setShortcut(QKeySequence("Ctrl+E")); + auto* restartAction = fileMenu->addAction("重启"); + restartAction->setShortcut(QKeySequence("Ctrl+R")); + connect(restartAction, &QAction::triggered, this, [this]() { + doRestart(); + }); fileMenu->addSeparator(); @@ -269,6 +278,14 @@ void MainWindow::setupMenuBar() { // 帮助菜单 auto* helpMenu = menuBar()->addMenu("帮助"); + auto* usageAction = helpMenu->addAction("使用说明"); + usageAction->setShortcut(QKeySequence("F1")); + connect(usageAction, &QAction::triggered, this, [this] { + showUsage(); + }); + + helpMenu->addSeparator(); + auto* aboutAction = helpMenu->addAction("关于"); connect(aboutAction, &QAction::triggered, this, [this] { QMessageBox::about(this, "关于", @@ -304,6 +321,103 @@ void MainWindow::doExit() { qApp->quit(); } +void MainWindow::doRestart() { + LOG_INFO(kTag, "应用重启"); + if (voiceInputService_) { + voiceInputService_->stop(); + } + if (trayIcon_) { + trayIcon_->hide(); + } + + QString appPath = qApp->applicationFilePath(); +#ifdef Q_OS_WIN + // Windows 使用 cmd /c start 启动,避免阻塞 + QProcess::startDetached("cmd", {"/c", "start", "", "\"" + appPath + "\""}); +#else + QProcess::startDetached(appPath, {}); +#endif + + qApp->quit(); +} + +void MainWindow::showUsage() { + const QString usageText = + "

使用说明

" + "

一、基本功能

" + "

实时语音识别:按下快捷键开始录音,语音实时转为文字显示在识别结果区。

" + "

音频文件转写:选择本地音频文件(支持 WAV/MP3/FLAC/OGG 等格式),点击开始转写即可将整个文件转为文字。

" + "

配置管理:在配置页面设置模型路径、ONNX 线程数、识别语言、快捷键等参数。

" + + "

二、快捷键操作

" + "" + "" + "" + "" + "" + "
语音输入默认 F8(可在配置中自定义)
使用说明F1
重启应用Ctrl+R
退出应用Ctrl+Q
" + + "

三、语音输入使用流程

" + "
    " + "
  1. 配置页面中设置正确的 STT 模型路径并保存。
  2. " + "
  3. 设置语音输入快捷键(如 F8)。
  4. " + "
  5. 将光标定位到需要输入文字的目标应用(如微信、Word、浏览器等)。
  6. " + "
  7. 按下快捷键开始说话,说完后再次按下快捷键停止。
  8. " + "
  9. 识别的文字将通过模拟按键自动输入到目标应用中。
  10. " + "
" + + "

四、文件转写使用流程

" + "
    " + "
  1. 切换到音频文件转写标签页。
  2. " + "
  3. 点击选择文件按钮选择音频文件,支持拖放文件到窗口。
  4. " + "
  5. 点击开始转写,等待处理完成。
  6. " + "
  7. 转写结果显示在下方文本区,可点击复制结果复制到剪贴板,或点击导出结果保存为文本文件。
  8. " + "
" + + "

五、配置说明

" + "" + "" + "" + "" + "" + "" + "" + "" + "
模型路径SenseVoice ONNX 模型文件路径(.onnx)
词表路径Tokenizer 词表文件路径(tokens.txt)
推理设备CPU / GPU(需 GPU 版本 ONNX Runtime)
线程数ONNX 推理线程数,建议 2-4
语音快捷键触发语音输入的快捷键
主题深色 / 浅色界面主题
字体大小全局界面字体大小
" + + "

六、系统托盘

" + "

关闭主窗口时程序最小化到系统托盘,托盘图标菜单支持:

" + "
    " + "
  • 显示主窗口:恢复主窗口显示
  • " + "
  • 重启:重启应用程序
  • " + "
  • 退出:完全退出程序
  • " + "
" + "

双击托盘图标可快速显示主窗口。

" + + "

七、状态栏

" + "

底部状态栏右侧显示 STT 模型加载状态:

" + "
    " + "
  • 模型已就绪 — 模型加载成功,可以正常使用
  • " + "
  • 模型路径未设置 — 请在配置页面设置模型路径
  • " + "
  • 模型加载失败 — 模型文件路径错误或文件损坏
  • " + "
" + + "

八、常见问题

" + "

Q: 语音输入没有反应?
" + "A: 请确认:① 模型已加载(状态栏显示模型已就绪);② 已设置语音快捷键;③ 麦克风正常工作。

" + "

Q: 识别文字没有输入到目标应用?
" + "A: 某些应用可能拦截模拟按键输入,请尝试在管理员权限下运行本程序。

" + "

Q: 识别速度慢?
" + "A: 在配置中增大 ONNX 线程数,或使用 GPU 版本的 ONNX Runtime。

"; + + QMessageBox msgBox(this); + msgBox.setWindowTitle("使用说明"); + msgBox.setTextFormat(Qt::RichText); + msgBox.setText(usageText); + msgBox.setIcon(QMessageBox::Information); + msgBox.exec(); +} + void MainWindow::updateModelStatus() { if (!sttEngine_ || !modelStatusLabel_) return; diff --git a/src/ui/main_window.h b/src/ui/main_window.h index 46e5ac7..f45d8ff 100644 --- a/src/ui/main_window.h +++ b/src/ui/main_window.h @@ -45,6 +45,8 @@ private: void onVoiceInputConfigChanged(); void updateModelStatus(); void doExit(); + void doRestart(); + void showUsage(); ConfigManager* configManager_; SenseVoiceEngine* sttEngine_;