fix: piper 加 ESPEAK_DATA_PATH 环境变量 (espeak-ng-data 目录)

This commit is contained in:
2026-07-04 17:10:23 +08:00
parent dc20fd3502
commit a3052ad6db
6 changed files with 23 additions and 6 deletions

View File

@@ -390,6 +390,9 @@ pub struct AiConfig {
/// piper 模型 config json 路径 (.onnx.json)
#[serde(default)]
pub piper_config: Option<PathBuf>,
/// piper espeak-ng-data 目录路径
#[serde(default)]
pub espeak_data_dir: Option<PathBuf>,
/// 临时文件目录
#[serde(default = "default_tmp_dir")]
pub tmp_dir: PathBuf,

View File

@@ -52,6 +52,7 @@ fn main() -> Result<()> {
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_espeak_data_dir = config.ai.espeak_data_dir.clone();
let ai_tmp_dir = config.ai.tmp_dir.clone();
let ai_context_window = config.ai.context_window;
@@ -85,6 +86,7 @@ fn main() -> Result<()> {
ai_whisper_lib_dir,
ai_piper_lib_dir,
ai_piper_config,
ai_espeak_data_dir,
ai_tmp_dir,
ai_context_window,
);

View File

@@ -52,6 +52,8 @@ pub struct LocalCliBackend {
piper_lib_dir: Option<PathBuf>,
/// piper 模型 config json 路径(.onnx.json
piper_config: Option<PathBuf>,
/// piper espeak-ng-data 目录路径
espeak_data_dir: Option<PathBuf>,
}
impl LocalCliBackend {
@@ -61,6 +63,7 @@ impl LocalCliBackend {
whisper_lib_dir: None,
piper_lib_dir: None,
piper_config: None,
espeak_data_dir: None,
}
}
@@ -70,10 +73,11 @@ impl LocalCliBackend {
self
}
/// 设置 piper 依赖库路径config(部署时由 deploy_ai.sh 标定
pub fn with_piper_deps(mut self, lib_dir: PathBuf, config: PathBuf) -> Self {
/// 设置 piper 依赖库路径config、espeak-ng-data 目录
pub fn with_piper_deps(mut self, lib_dir: PathBuf, config: PathBuf, espeak_data: PathBuf) -> Self {
self.piper_lib_dir = Some(lib_dir);
self.piper_config = Some(config);
self.espeak_data_dir = Some(espeak_data);
self
}
@@ -198,10 +202,14 @@ impl AiBackend for LocalCliBackend {
fn tts(&self, text: &str, model_path: &Path, output_path: &Path) -> Result<()> {
// echo <text> | piper -m <model> [-c <config>] -f <output> --output_format wav
// piper 依赖 libespeak-ng.so / libpiper_phonemize.so需设 LD_LIBRARY_PATH
// piper 需要 ESPEAK_DATA_PATH 指向 espeak-ng-data 目录
let mut cmd = Command::new(self.piper());
if let Some(lib_dir) = &self.piper_lib_dir {
self.with_lib_path(&mut cmd, lib_dir);
}
if let Some(espeak_data) = &self.espeak_data_dir {
cmd.env("ESPEAK_DATA_PATH", espeak_data);
}
cmd.arg("-m")
.arg(model_path)
.arg("-f")

View File

@@ -50,6 +50,7 @@ impl AiPlugin {
whisper_lib_dir: Option<PathBuf>,
piper_lib_dir: Option<PathBuf>,
piper_config: Option<PathBuf>,
espeak_data_dir: Option<PathBuf>,
tmp_dir: PathBuf,
context_window: usize,
) -> Self {
@@ -57,8 +58,9 @@ impl AiPlugin {
if let Some(lib_dir) = whisper_lib_dir {
backend_builder = backend_builder.with_whisper_lib_dir(lib_dir);
}
if let (Some(lib_dir), Some(config)) = (piper_lib_dir, piper_config) {
backend_builder = backend_builder.with_piper_deps(lib_dir, config);
// piper 三个依赖必须同时设置
if let (Some(lib_dir), Some(config), Some(espeak_data)) = (piper_lib_dir, piper_config, espeak_data_dir) {
backend_builder = backend_builder.with_piper_deps(lib_dir, config, espeak_data);
}
let backend = Box::new(backend_builder);
let models = model_manager::ModelManager::new(model_store);