基于 ONNX 的实时语音转文本输入法,C++ 跨平台实现。 核心组件: - Qt 6 跨平台 GUI(实时识别 / 文件转写 / 配置页面) - ONNX Runtime 推理引擎(异步模型加载) - PortAudio 音频采集 - dr_libs 音频文件解码 - JSON 配置管理(线程安全,自动持久化) - 日志系统(控制台 + 文件输出) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#include "app/application.h"
|
|
#include "ui/main_window.h"
|
|
#include "app/config_manager.h"
|
|
#include "utils/logger.h"
|
|
|
|
#include <QFile>
|
|
#include <QDir>
|
|
#include <QStandardPaths>
|
|
#include <QCommandLineParser>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
impress::Application app(argc, argv);
|
|
app.setApplicationName("Impress Voice Input");
|
|
app.setApplicationVersion("0.1.0");
|
|
app.setOrganizationName("Impress");
|
|
|
|
// 初始化日志文件
|
|
QString logDir = QStandardPaths::writableLocation(
|
|
QStandardPaths::AppDataLocation);
|
|
QDir().mkpath(logDir);
|
|
QString logFilePath = logDir + "/app.log";
|
|
impress::Logger::init(logFilePath);
|
|
|
|
LOG_INFO("Main", QString("应用启动,日志文件: %1").arg(logFilePath));
|
|
|
|
// 命令行参数
|
|
QCommandLineParser parser;
|
|
parser.setApplicationDescription("基于 ONNX 的实时语音转文本输入法");
|
|
parser.addHelpOption();
|
|
parser.addVersionOption();
|
|
parser.addOptions({
|
|
{{"c", "config"}, "指定配置文件路径", "path"},
|
|
{{"m", "model"}, "指定模型路径", "path"},
|
|
});
|
|
parser.process(app);
|
|
|
|
// 加载用户配置
|
|
auto* configManager = app.configManager();
|
|
QString configPath = parser.value("config");
|
|
if (configPath.isEmpty()) {
|
|
// 使用默认配置目录
|
|
configPath = logDir + "/config.json";
|
|
}
|
|
|
|
if (QFile::exists(configPath)) {
|
|
configManager->load(configPath);
|
|
LOG_INFO("Main", QString("已加载配置: %1").arg(configPath));
|
|
} else {
|
|
LOG_INFO("Main", "使用默认配置");
|
|
}
|
|
|
|
// 命令行覆盖模型路径
|
|
QString modelPath = parser.value("model");
|
|
if (!modelPath.isEmpty()) {
|
|
configManager->set("stt.model_path", modelPath);
|
|
}
|
|
|
|
// 创建并显示主窗口
|
|
impress::MainWindow mainWindow(configManager);
|
|
mainWindow.show();
|
|
|
|
return app.exec();
|
|
}
|