diff --git a/.chat_req.json b/.chat_req.json new file mode 100644 index 0000000..cf01bb2 --- /dev/null +++ b/.chat_req.json @@ -0,0 +1 @@ +{"text":"hello","session_id":"e2e"} diff --git a/configs/cat_state_machine.json b/configs/cat_state_machine.json index 7d34b70..0463a75 100644 --- a/configs/cat_state_machine.json +++ b/configs/cat_state_machine.json @@ -1167,6 +1167,8 @@ }, "ai": { "backend": "local", - "whisper_lib_dir": "/home/showen/ai_spike/whisper.cpp/build/bin" + "whisper_lib_dir": "/home/showen/ai_spike/whisper.cpp/build/bin", + "piper_lib_dir": "/home/showen/ai_spike/piper", + "piper_config": "/home/showen/ai_spike/piper/zh_CN-huayan-medium.onnx.json" } } \ No newline at end of file diff --git a/configs/dog_state_machine.json b/configs/dog_state_machine.json index 27f2acc..db6a501 100644 --- a/configs/dog_state_machine.json +++ b/configs/dog_state_machine.json @@ -1179,6 +1179,8 @@ }, "ai": { "backend": "local", - "whisper_lib_dir": "/home/showen/ai_spike/whisper.cpp/build/bin" + "whisper_lib_dir": "/home/showen/ai_spike/whisper.cpp/build/bin", + "piper_lib_dir": "/home/showen/ai_spike/piper", + "piper_config": "/home/showen/ai_spike/piper/zh_CN-huayan-medium.onnx.json" } } \ No newline at end of file diff --git a/src/core/config.rs b/src/core/config.rs index aab268d..ef46e37 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -384,6 +384,12 @@ pub struct AiConfig { /// whisper-cli 依赖库路径 (libggml*.so 所在,部署时标定) #[serde(default)] pub whisper_lib_dir: Option, + /// piper 依赖库路径 (libespeak-ng.so / libpiper_phonemize.so 所在) + #[serde(default)] + pub piper_lib_dir: Option, + /// piper 模型 config json 路径 (.onnx.json) + #[serde(default)] + pub piper_config: Option, /// 临时文件目录 #[serde(default = "default_tmp_dir")] pub tmp_dir: PathBuf, diff --git a/src/main.rs b/src/main.rs index 5118a82..cbb14b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,8 @@ fn main() -> Result<()> { let ai_model_store = config.ai.model_store.clone(); let ai_tools_dir = config.ai.tools_dir.clone(); let ai_whisper_lib_dir = config.ai.whisper_lib_dir.clone(); + let ai_piper_lib_dir = config.ai.piper_lib_dir.clone(); + let ai_piper_config = config.ai.piper_config.clone(); let ai_tmp_dir = config.ai.tmp_dir.clone(); let ai_context_window = config.ai.context_window; @@ -81,6 +83,8 @@ fn main() -> Result<()> { ai_model_store, ai_tools_dir, ai_whisper_lib_dir, + ai_piper_lib_dir, + ai_piper_config, ai_tmp_dir, ai_context_window, ); diff --git a/src/plugins/ai/backend.rs b/src/plugins/ai/backend.rs index 7d2109a..c5ae1cb 100644 --- a/src/plugins/ai/backend.rs +++ b/src/plugins/ai/backend.rs @@ -48,6 +48,10 @@ pub struct LocalCliBackend { tools_dir: PathBuf, /// whisper-cli 依赖的库路径(libggml*.so 所在) whisper_lib_dir: Option, + /// piper 依赖的库路径(libespeak-ng.so / libpiper_phonemize.so 所在) + piper_lib_dir: Option, + /// piper 模型 config json 路径(.onnx.json) + piper_config: Option, } impl LocalCliBackend { @@ -55,6 +59,8 @@ impl LocalCliBackend { Self { tools_dir, whisper_lib_dir: None, + piper_lib_dir: None, + piper_config: None, } } @@ -64,6 +70,13 @@ impl LocalCliBackend { self } + /// 设置 piper 依赖库路径和 config(部署时由 deploy_ai.sh 标定) + pub fn with_piper_deps(mut self, lib_dir: PathBuf, config: PathBuf) -> Self { + self.piper_lib_dir = Some(lib_dir); + self.piper_config = Some(config); + self + } + fn whisper_cli(&self) -> PathBuf { self.tools_dir.join("whisper-cli") } @@ -76,21 +89,26 @@ impl LocalCliBackend { self.tools_dir.join("piper") } - /// 给命令设置 LD_LIBRARY_PATH(whisper-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); - } + /// 给命令设置 LD_LIBRARY_PATH(合并所有库路径) + fn with_lib_path(&self, cmd: &mut Command, lib_dir: &Path) { + let existing = std::env::var("LD_LIBRARY_PATH").unwrap_or_default(); + let new_path = if existing.is_empty() { + lib_dir.to_string_lossy().into_owned() + } else { + format!("{}:{}", lib_dir.to_string_lossy(), existing) + }; + cmd.env("LD_LIBRARY_PATH", new_path); } } impl AiBackend for LocalCliBackend { fn asr(&self, audio_path: &Path, model_path: &Path) -> Result { // whisper-cli -m -f