feat(M2.1): 设备端部署脚本 + whisper LD_LIBRARY_PATH + dog/cat 角色人设配置

This commit is contained in:
2026-07-04 15:44:48 +08:00
parent 4877d54a1c
commit 6810d1ca13
7 changed files with 138 additions and 3 deletions

View File

@@ -46,11 +46,22 @@ pub trait AiBackend: Send {
pub struct LocalCliBackend {
/// 工具目录(含 whisper-cli, llama-cli, piper 二进制)
tools_dir: PathBuf,
/// whisper-cli 依赖的库路径libggml*.so 所在)
whisper_lib_dir: Option<PathBuf>,
}
impl LocalCliBackend {
pub fn new(tools_dir: PathBuf) -> Self {
Self { tools_dir }
Self {
tools_dir,
whisper_lib_dir: None,
}
}
/// 设置 whisper-cli 依赖库路径(部署时由 deploy_ai.sh 标定)
pub fn with_whisper_lib_dir(mut self, lib_dir: PathBuf) -> Self {
self.whisper_lib_dir = Some(lib_dir);
self
}
fn whisper_cli(&self) -> PathBuf {
@@ -64,6 +75,13 @@ impl LocalCliBackend {
fn piper(&self) -> PathBuf {
self.tools_dir.join("piper")
}
/// 给命令设置 LD_LIBRARY_PATHwhisper-cli 依赖 libggml*.so
fn with_env(&self, cmd: &mut Command) {
if let Some(lib_dir) = &self.whisper_lib_dir {
cmd.env("LD_LIBRARY_PATH", lib_dir);
}
}
}
impl AiBackend for LocalCliBackend {
@@ -71,7 +89,9 @@ impl AiBackend for LocalCliBackend {
// whisper-cli -m <model> -f <audio> -l zh --no-timestamps -otxt -of <tmp>
// 输出到 <tmp>.txt读取后返回
let tmp_out = audio_path.with_extension("asr.txt");
let output = Command::new(self.whisper_cli())
let mut cmd = Command::new(self.whisper_cli());
self.with_env(&mut cmd);
let output = cmd
.arg("-m")
.arg(model_path)
.arg("-f")