From fe8358b82bed55d7247a10f727736b6061c8ea22 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 31 Mar 2024 17:05:49 +0900 Subject: [PATCH] =?UTF-8?q?[release-0.15]=20.onnx/.bin=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AE=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=81=BF?= =?UTF-8?q?=E3=82=92=E9=81=85=E5=BB=B6=E3=81=95=E3=81=9B=E3=82=8B=20(#768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/status.rs | 56 ++++++++++++------------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/crates/voicevox_core/src/status.rs b/crates/voicevox_core/src/status.rs index 012d69973..b76dad06d 100644 --- a/crates/voicevox_core/src/status.rs +++ b/crates/voicevox_core/src/status.rs @@ -100,9 +100,9 @@ impl ModelFileSet { predict_intonation_model, decode_model, }| { - let predict_duration_model = ModelFile::new(&path(predict_duration_model))?; - let predict_intonation_model = ModelFile::new(&path(predict_intonation_model))?; - let decode_model = ModelFile::new(&path(decode_model))?; + let predict_duration_model = path(predict_duration_model); + let predict_intonation_model = path(predict_intonation_model); + let decode_model = path(decode_model); Ok(TalkModel { predict_duration_model, predict_intonation_model, @@ -121,10 +121,9 @@ impl ModelFileSet { predict_sing_volume_model, }| { let predict_sing_consonant_length_model = - ModelFile::new(&path(predict_sing_consonant_length_model))?; - let predict_sing_f0_model = ModelFile::new(&path(predict_sing_f0_model))?; - let predict_sing_volume_model = - ModelFile::new(&path(predict_sing_volume_model))?; + path(predict_sing_consonant_length_model); + let predict_sing_f0_model = path(predict_sing_f0_model); + let predict_sing_volume_model = path(predict_sing_volume_model); Ok(SingTeacherModel { predict_sing_consonant_length_model, predict_sing_f0_model, @@ -137,7 +136,7 @@ impl ModelFileSet { let sf_decode_models = model_file::SF_DECODE_MODEL_FILE_NAMES .iter() .map(|&SfDecodeModelFileNames { sf_decode_model }| { - let sf_decode_model = ModelFile::new(&path(sf_decode_model))?; + let sf_decode_model = path(sf_decode_model); Ok(SfDecodeModel { sf_decode_model }) }) .collect::>()?; @@ -195,34 +194,19 @@ struct SfDecodeModelFileNames { struct DecryptModelError; struct TalkModel { - predict_duration_model: ModelFile, - predict_intonation_model: ModelFile, - decode_model: ModelFile, + predict_duration_model: PathBuf, + predict_intonation_model: PathBuf, + decode_model: PathBuf, } struct SingTeacherModel { - predict_sing_consonant_length_model: ModelFile, - predict_sing_f0_model: ModelFile, - predict_sing_volume_model: ModelFile, + predict_sing_consonant_length_model: PathBuf, + predict_sing_f0_model: PathBuf, + predict_sing_volume_model: PathBuf, } struct SfDecodeModel { - sf_decode_model: ModelFile, -} - -struct ModelFile { - path: PathBuf, - content: Vec, -} - -impl ModelFile { - fn new(path: &Path) -> anyhow::Result { - let content = fs_err::read(path)?; - Ok(Self { - path: path.to_owned(), - content, - }) - } + sf_decode_model: PathBuf, } #[derive(Deserialize, Getters)] @@ -421,12 +405,18 @@ impl Status { fn new_session( &self, - model_file: &ModelFile, + model_file: &Path, session_options: &SessionOptions, ) -> Result> { - self.new_session_from_bytes(|| model_file::decrypt(&model_file.content), session_options) + let model_bytes = &match fs_err::read(model_file) { + Ok(model_bytes) => model_bytes, + Err(err) => { + panic!("ファイルを読み込めなかったためクラッシュします: {err}"); + } + }; + self.new_session_from_bytes(|| model_file::decrypt(model_bytes), session_options) .map_err(|source| Error::LoadModel { - path: model_file.path.clone(), + path: model_file.to_owned(), source, }) }