#pragma once #include #include #include #include #include #include #include #include "audio.h" #include "streamingasr.h" namespace lc { class Qwen3Asr; // 实时字幕:采集默认输出 → 流式转写 → 用信号把文本推给 UI。 // 分段由静音检测驱动:句子之间的自然停顿就收束一段、清空上下文, // 这样解码器的上下文不会无限增长(见 docs/phase2-streaming.md)。 class LiveTranscriber : public QObject { Q_OBJECT public: explicit LiveTranscriber(Qwen3Asr & asr, QObject * parent = nullptr); ~LiveTranscriber() override; bool start(const StreamOptions & opts, QString * error = nullptr); void stop(); QString deviceName() const; Q_SIGNALS: // committed = 已稳定文本;tail = 不稳定尾部(UI 用暗色显示) void caption(const QString & committed, const QString & tail, const QString & language); void failed(const QString & message); private: void workerLoop(); Qwen3Asr & asr_; MonitorCapture capture_; StreamOptions opts_; std::thread worker_; std::mutex mutex_; std::condition_variable cv_; std::vector pending_; bool quit_ = false; }; } // namespace lc