From b9aa8d1b7c7513a6cd3053e0f824271041fbf262 Mon Sep 17 00:00:00 2001 From: Googlefan Date: Sat, 22 Feb 2025 08:56:10 +0000 Subject: [PATCH] fix --- Cargo.lock | 21 +++++++++++++++++---- Cargo.toml | 9 +++++++++ crates/sbv2_api/Cargo.toml | 8 ++++++-- crates/sbv2_bindings/Cargo.toml | 8 ++++++-- crates/sbv2_core/Cargo.toml | 18 ++++++++++-------- crates/sbv2_core/build.rs | 19 +++++++++++++++++++ crates/sbv2_core/src/jtalk.rs | 2 +- crates/sbv2_core/src/main.rs | 10 ++++++++-- crates/sbv2_wasm/Cargo.toml | 8 ++++++-- 9 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 crates/sbv2_core/build.rs diff --git a/Cargo.lock b/Cargo.lock index 6c8898e..0e2937d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,6 +697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -705,6 +706,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + [[package]] name = "futures-sink" version = "0.3.31" @@ -724,9 +731,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", + "futures-io", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -2101,6 +2112,7 @@ dependencies = [ "base64 0.22.1", "bytes", "encoding_rs", + "futures-channel", "futures-core", "futures-util", "h2", @@ -2222,7 +2234,7 @@ checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" [[package]] name = "sbv2_api" -version = "0.2.0-alpha4" +version = "0.2.0-alpha6" dependencies = [ "anyhow", "axum", @@ -2238,7 +2250,7 @@ dependencies = [ [[package]] name = "sbv2_bindings" -version = "0.2.0-alpha4" +version = "0.2.0-alpha6" dependencies = [ "anyhow", "ndarray", @@ -2248,7 +2260,7 @@ dependencies = [ [[package]] name = "sbv2_core" -version = "0.2.0-alpha4" +version = "0.2.0-alpha6" dependencies = [ "anyhow", "base64 0.22.1", @@ -2262,6 +2274,7 @@ dependencies = [ "once_cell", "ort", "regex", + "reqwest", "serde", "serde_json", "tar", @@ -2272,7 +2285,7 @@ dependencies = [ [[package]] name = "sbv2_wasm" -version = "0.1.0" +version = "0.2.0-alpha6" dependencies = [ "js-sys", "ndarray", diff --git a/Cargo.toml b/Cargo.toml index 02c265f..240b6e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,15 @@ resolver = "2" members = ["./crates/sbv2_api", "./crates/sbv2_core", "./crates/sbv2_bindings", "./crates/sbv2_wasm"] +[workspace.package] +version = "0.2.0-alpha6" +edition = "2021" +description = "Style-Bert-VITSの推論ライブラリ" +license = "MIT" +readme = "./README.md" +repository = "https://github.com/tuna2134/sbv2-api" +documentation = "https://docs.rs/sbv2_core" + [workspace.dependencies] anyhow = "1.0.96" dotenvy = "0.15.7" diff --git a/crates/sbv2_api/Cargo.toml b/crates/sbv2_api/Cargo.toml index 491759b..44f5b29 100644 --- a/crates/sbv2_api/Cargo.toml +++ b/crates/sbv2_api/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "sbv2_api" -version = "0.2.0-alpha4" -edition = "2021" +version.workspace = true +edition.workspace = true +description.workspace = true +readme.workspace = true +repository.workspace = true +documentation.workspace = true [dependencies] anyhow.workspace = true diff --git a/crates/sbv2_bindings/Cargo.toml b/crates/sbv2_bindings/Cargo.toml index 154382e..65a345e 100644 --- a/crates/sbv2_bindings/Cargo.toml +++ b/crates/sbv2_bindings/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "sbv2_bindings" -version = "0.2.0-alpha4" -edition = "2021" +version.workspace = true +edition.workspace = true +description.workspace = true +readme.workspace = true +repository.workspace = true +documentation.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] diff --git a/crates/sbv2_core/Cargo.toml b/crates/sbv2_core/Cargo.toml index 4ed91d2..3522ac2 100644 --- a/crates/sbv2_core/Cargo.toml +++ b/crates/sbv2_core/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "sbv2_core" -description = "Style-Bert-VITSの推論ライブラリ" -version = "0.2.0-alpha4" -edition = "2021" -license = "MIT" -readme = "../README.md" -repository = "https://github.com/tuna2134/sbv2-api" -documentation = "https://docs.rs/sbv2_core" +version.workspace = true +edition.workspace = true +description.workspace = true +readme.workspace = true +repository.workspace = true +documentation.workspace = true [dependencies] anyhow.workspace = true @@ -39,4 +38,7 @@ coreml = ["ort/coreml", "std"] default = ["std"] no_std = ["tokenizers/unstable_wasm"] aivmx = ["npyz", "base64"] -base64 = ["dep:base64"] \ No newline at end of file +base64 = ["dep:base64"] + +[build-dependencies] +reqwest = { version = "0.12.12", features = ["blocking"] } diff --git a/crates/sbv2_core/build.rs b/crates/sbv2_core/build.rs new file mode 100644 index 0000000..1f17d3c --- /dev/null +++ b/crates/sbv2_core/build.rs @@ -0,0 +1,19 @@ +use std::env; +use std::fs; +use std::io::copy; +use std::path::Path; + +fn main() -> Result<(), Box> { + let out_dir = env::var("OUT_DIR")?; + let out_path = Path::new(&out_dir).join("all.bin"); + if !out_path.exists() { + println!("cargo:warning=Downloading dictionary file..."); + let mut response = reqwest::blocking::get( + "https://huggingface.co/neody/sbv2-api-assets/resolve/main/dic/all.bin", + )?; + let mut file = fs::File::create(&out_path)?; + copy(&mut response, &mut file)?; + } + println!("cargo:rerun-if-changed=build.rs"); + Ok(()) +} diff --git a/crates/sbv2_core/src/jtalk.rs b/crates/sbv2_core/src/jtalk.rs index 5b57d5b..c837269 100644 --- a/crates/sbv2_core/src/jtalk.rs +++ b/crates/sbv2_core/src/jtalk.rs @@ -13,7 +13,7 @@ type JPreprocessType = JPreprocess; fn initialize_jtalk() -> Result { let sdic = SystemDictionaryConfig::Bundled(kind::JPreprocessDictionaryKind::NaistJdic).load()?; - let u = UserDictionary::load(include_bytes!("./dic/all.dic/all.bin")) + let u = UserDictionary::load(include_bytes!(concat!(env!("OUT_DIR"), "/all.bin"))) .map_err(|e| Error::LinderaError(e.to_string()))?; let jpreprocess = JPreprocess::with_dictionaries(sdic, Some(u)); Ok(jpreprocess) diff --git a/crates/sbv2_core/src/main.rs b/crates/sbv2_core/src/main.rs index bdfbb74..07d9843 100644 --- a/crates/sbv2_core/src/main.rs +++ b/crates/sbv2_core/src/main.rs @@ -15,13 +15,19 @@ fn main_inner() -> anyhow::Result<()> { .ok() .and_then(|x| x.parse().ok()), )?; + let mp = env::var("MODEL_PATH")?; + let b = fs::read(&mp)?; #[cfg(not(feature = "aivmx"))] { - tts_holder.load_sbv2file(ident, fs::read(env::var("MODEL_PATH")?)?)?; + tts_holder.load_sbv2file(ident, b)?; } #[cfg(feature = "aivmx")] { - tts_holder.load_aivmx(ident, fs::read(env::var("MODEL_PATH")?)?)?; + if mp.ends_with(".sbv2") { + tts_holder.load_sbv2file(ident, b)?; + } else { + tts_holder.load_aivmx(ident, b)?; + } } let audio = diff --git a/crates/sbv2_wasm/Cargo.toml b/crates/sbv2_wasm/Cargo.toml index ab7ae70..2424681 100644 --- a/crates/sbv2_wasm/Cargo.toml +++ b/crates/sbv2_wasm/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "sbv2_wasm" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true +description.workspace = true +readme.workspace = true +repository.workspace = true +documentation.workspace = true [lib] crate-type = ["cdylib", "rlib"]