refactor: split core/ui/apps targets and add unit tests

Move all business logic into liblivecaption_core (no Qt dependency) and
the widgets into liblivecaption_ui, leaving two executables: the caption
window and the CLI, which no longer links Qt Widgets. Abstract the ASR
backend behind IAsr so the streaming policy and the live pipeline can be
tested with a scripted fake backend instead of a real model.

把全部业务逻辑下沉到不依赖 Qt 的 liblivecaption_core,界面独立成
liblivecaption_ui,拆出悬浮窗与命令行两个可执行程序(CLI 不再链接 Qt
Widgets);并用 IAsr 抽象推理后端,使流式策略与实时管线可脱离真模型
用假实现做单元测试。测试还抓到一个真 bug:段恰好结束在 chunk 边界时
只提交了稳定部分,最后几个词被丢掉,已修。
This commit is contained in:
blumia committed 2026-10-12 13:43:50 +08:00
1 parent 4ed4e23282
commit 736ec14d5b
32 files changed
+1502 -655

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include <cstddef>
#include <functional>
#include <string>
#include <vector>
namespace lc {
// 读取 WAV(PCM 16/24/32 位或 float32),降混为单声道并重采样到 targetRate。
bool readWavMono(const std::string & path, int targetRate,
std::vector<float> & out, std::string * error);
// 采集默认输出设备的 monitor(即"系统正在播放的声音"),
// 输出 targetRate 单声道 float32。回调在 PulseAudio 线程上调用,必须快速返回。
class MonitorCapture {
public:
using ChunkCallback = std::function<void(const float * mono, size_t nSamples)>;
MonitorCapture();
~MonitorCapture();
MonitorCapture(const MonitorCapture &) = delete;
MonitorCapture & operator=(const MonitorCapture &) = delete;
bool start(int targetRate, ChunkCallback callback, std::string * error);
void stop();
// 实际采集的 monitor 源名(start 成功后有效)
std::string deviceName() const;
// 前向声明(定义在 .cpp)。公开仅为让文件内的 C 回调能引用该类型,
// 头文件里它始终是不完整类型。
struct Impl;
private:
Impl * d = nullptr;
};
} // namespace lc