Files
live-caption/experiments/phase0/bench.sh
T
blumia 18dbc9c8d3 feat: add real-time caption CLI prototype with Qwen3-ASR
Add a C++/Qt6/CMake CLI prototype that captures the default sink
monitor through libpulse and transcribes it in-process with Qwen3-ASR
via libllama/libmtmd. Add phase 0/1 verification docs.

新增实时字幕命令行原型:libpulse 采集默认输出 monitor,进程内用
libllama/libmtmd 跑 Qwen3-ASR 推理。附阶段 0/1 验证文档。
2026-10-12 11:40:59 +08:00

40 lines
1.8 KiB
Bash
Executable File
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.
#!/usr/bin/env bash
# Phase 0 验证脚本:用 llama.cpp + Qwen3-ASR 转写一段音频并测 RTF
#
# 依赖(本机验证环境:Deepin 25 / Qt 6.8 / x86_64):
# libllama0, libllama-dev, libggml0, libggml-dev, libmtmd (系统自带 9951+dfsg-1deepin1)
# llama.cpp-tools 的二进制(本脚本从 deb 解包到 LLAMA_TOOLS,不需要 root 安装)
#
# 用法: ./bench.sh <audio.wav> [prompt] # prompt 默认 <__media__>
# 可选环境变量: THREADS / MODEL / MMPROJ / LLAMA_TOOLS / LLAMA_LIBDIR / TMO
set -uo pipefail
LLAMA_TOOLS="${LLAMA_TOOLS:-/tmp/opencode/llama-tools}"
LLAMA_LIBDIR="${LLAMA_LIBDIR:-/usr/lib/x86_64-linux-gnu/llama}"
MODEL="${MODEL:-/tmp/opencode/models/Qwen3-ASR-0.6B-Q8_0.gguf}"
MMPROJ="${MMPROJ:-/tmp/opencode/models/mmproj-Qwen3-ASR-0.6B-Q8_0.gguf}"
AUDIO="${1:?usage: bench.sh <audio> [prompt]}"
PROMPT="${2:-<__media__>}"
THREADS="${THREADS:-8}"
CLI="$LLAMA_TOOLS/usr/bin/llama-cli"
export LD_LIBRARY_PATH="$LLAMA_LIBDIR:$LLAMA_TOOLS/usr/lib/x86_64-linux-gnu/llama"
dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$AUDIO")
printf '音频: %s (%ss) 模型: %s 线程: %s\n' "$AUDIO" "$dur" "$(basename "$MODEL")" "$THREADS"
# 关键: stdin 必须接 /dev/null 并在外层套 timeout
# 否则 llama-cli 生成完会回到 stdin 读取循环而挂住
t0=$(date +%s.%N)
timeout "${TMO:-300}" "$CLI" -m "$MODEL" --mmproj "$MMPROJ" --audio "$AUDIO" \
-p "$PROMPT" -n 256 --temp 0 -t "$THREADS" -st --simple-io \
</dev/null >/tmp/lc_out.log 2>/tmp/lc_err.log
rc=$?
t1=$(date +%s.%N)
[ "$rc" = 124 ] && echo "(警告: 被 timeout 杀掉)"
echo "---- 转写结果 ----"
cat /tmp/lc_out.log
echo "---- 计时 ----"
python3 -c "print(f'墙钟总耗时: {$t1-$t0:.2f}s 音频: $dur s → RTF(含加载) ≈ {($t1-$t0)/$dur:.3f}')"