impress_voice_input/src/app/application.h
impressionyang ef97b962c3 refactor: 全局共享 STT 模型,避免重复加载
将 SenseVoiceEngine 提升为 Application 级别的全局单例,应用启动时
异步加载一次模型,实时语音识别、文件转写和快捷键语音输入共享同一实例。

- Application 创建并管理全局 SenseVoiceEngine,启动时加载模型
- STTTestPage、FileTranscribePage、VoiceInputService 不再各自
  创建引擎,改为接收全局实例
- 移除各模块中冗余的 loadModel/loadModelAsync/unloadModel 调用
- 模型未加载时提供友好的等待提示,而非加载失败的错误弹窗

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-13 14:10:31 +08:00

48 lines
1.0 KiB
C++
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.

#pragma once
#include <QApplication>
#include <memory>
namespace impress {
class ConfigManager;
class SenseVoiceEngine;
/**
* @brief 应用入口封装
*
* 管理全局共享组件配置管理器、STT 引擎。
* STT 引擎在启动时异步加载模型,所有页面和服务共享同一实例。
*/
class Application : public QApplication {
Q_OBJECT
public:
Application(int& argc, char** argv);
~Application() override;
/** @brief 获取全局配置管理器 */
ConfigManager* configManager() const;
/** @brief 获取全局 STT 引擎(共享实例) */
SenseVoiceEngine* sttEngine() const;
/** @brief 获取全局 STT 引擎加载状态 */
bool isModelLoaded() const;
signals:
/** @brief 模型加载完成 */
void modelLoaded();
/** @brief 模型加载失败 */
void modelLoadError(const QString& error);
private:
void loadGlobalModel();
std::unique_ptr<ConfigManager> configManager_;
SenseVoiceEngine* sttEngine_ = nullptr;
bool modelLoaded_ = false;
};
} // namespace impress