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:
1 parent
4ed4e23282
commit
736ec14d5b
32 files changed
+1502
-655
No files matched your search
+48
-21
@@ -4,10 +4,13 @@ project(live-caption LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
option(LC_BUILD_TESTS "构建单元测试" ON)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# llama.cpp / libmtmd 的搜索路径
|
||||
#
|
||||
@@ -29,8 +32,6 @@ find_package(Qt6 REQUIRED COMPONENTS Core Widgets)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
pkg_check_modules(SAMPLERATE REQUIRED IMPORTED_TARGET samplerate)
|
||||
pkg_check_modules(PULSE REQUIRED IMPORTED_TARGET libpulse)
|
||||
|
||||
@@ -47,37 +48,32 @@ else()
|
||||
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
|
||||
GIT_TAG b9951
|
||||
FIND_PACKAGE_ARGS NAMES llama CONFIG)
|
||||
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
|
||||
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
|
||||
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(llama)
|
||||
set(LC_LLAMA_TARGET llama)
|
||||
endif()
|
||||
|
||||
# --- mtmd:llama.pc 里没有,单独找 ---
|
||||
find_library(LC_MTMD_LIB NAMES mtmd
|
||||
HINTS /usr/lib/x86_64-linux-gnu/llama)
|
||||
find_library(LC_MTMD_LIB NAMES mtmd HINTS /usr/lib/x86_64-linux-gnu/llama)
|
||||
if(NOT LC_MTMD_LIB)
|
||||
message(FATAL_ERROR "找不到 libmtmd(应随 libllama0 一起安装)")
|
||||
endif()
|
||||
message(STATUS "mtmd: ${LC_MTMD_LIB}")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
add_executable(live-caption-cli
|
||||
src/main.cpp
|
||||
src/transcript.cpp
|
||||
src/qwen3asr.cpp
|
||||
src/streamingasr.cpp
|
||||
src/audio.cpp
|
||||
src/livetranscriber.cpp
|
||||
src/captionwindow.cpp
|
||||
# core:全部业务逻辑,刻意不依赖 Qt(方便测试与复用)
|
||||
# ---------------------------------------------------------------------------
|
||||
add_library(livecaption_core STATIC
|
||||
src/core/transcript.cpp
|
||||
src/core/audio.cpp
|
||||
src/core/qwen3asr.cpp
|
||||
src/core/streamingasr.cpp
|
||||
src/core/livepipeline.cpp
|
||||
)
|
||||
|
||||
target_include_directories(live-caption-cli PRIVATE src)
|
||||
|
||||
target_link_libraries(live-caption-cli PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Widgets
|
||||
target_include_directories(livecaption_core PUBLIC src/core)
|
||||
target_link_libraries(livecaption_core PUBLIC
|
||||
Threads::Threads
|
||||
PkgConfig::SAMPLERATE
|
||||
PkgConfig::PULSE
|
||||
@@ -85,6 +81,37 @@ target_link_libraries(live-caption-cli PRIVATE
|
||||
${LC_MTMD_LIB}
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ui:悬浮窗与 Qt 适配层
|
||||
# ---------------------------------------------------------------------------
|
||||
add_library(livecaption_ui STATIC
|
||||
src/ui/captionwindow.cpp
|
||||
src/ui/livetranscriber.cpp
|
||||
)
|
||||
target_include_directories(livecaption_ui PUBLIC src/ui)
|
||||
target_link_libraries(livecaption_ui PUBLIC livecaption_core Qt6::Widgets)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 可执行程序
|
||||
# ---------------------------------------------------------------------------
|
||||
# GUI:悬浮字幕窗
|
||||
add_executable(live-caption apps/gui/main.cpp)
|
||||
target_include_directories(live-caption PRIVATE apps/common)
|
||||
target_link_libraries(live-caption PRIVATE livecaption_ui)
|
||||
|
||||
# CLI:文件 / 流式文件 / 命令行实时;不链接 Qt Widgets
|
||||
add_executable(live-caption-cli apps/cli/main.cpp)
|
||||
target_include_directories(live-caption-cli PRIVATE apps/common)
|
||||
target_link_libraries(live-caption-cli PRIVATE livecaption_core Qt6::Core)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(live-caption-cli PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
foreach(_t livecaption_core livecaption_ui live-caption live-caption-cli)
|
||||
target_compile_options(${_t} PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
if(LC_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
Reference in new issue
Block a user