mirror of
https://github.com/neodyland/sbv2-api.git
synced 2025-12-22 15:39:58 +00:00
fix: lot of
This commit is contained in:
737
Cargo.lock
generated
737
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
members = ["./crates/sbv2_api", "./crates/sbv2_core", "./crates/sbv2_bindings", "./crates/sbv2_wasm"]
|
||||
|
||||
[workspace.package]
|
||||
@@ -8,7 +8,7 @@ edition = "2021"
|
||||
description = "Style-Bert-VITSの推論ライブラリ"
|
||||
license = "MIT"
|
||||
readme = "./README.md"
|
||||
repository = "https://github.com/tuna2134/sbv2-api"
|
||||
repository = "https://github.com/neodyland/sbv2-api"
|
||||
documentation = "https://docs.rs/sbv2_core"
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
1
LICENSE
1
LICENSE
@@ -1,6 +1,7 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tuna2134
|
||||
Copyright (c) 2021- neodyland
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
## プログラミングに詳しくない方向け
|
||||
|
||||
[こちら](https://github.com/tuna2134/sbv2-gui?tab=readme-ov-file)を参照してください。
|
||||
[こちら](https://github.com/tuna2134/sbv2-gui)を参照してください。
|
||||
|
||||
コマンドやpythonの知識なしで簡単に使えるバージョンです。(できることはほぼ同じ)
|
||||
|
||||
@@ -75,7 +75,7 @@ CPUの場合は
|
||||
```sh
|
||||
docker run -it --rm -p 3000:3000 --name sbv2 \
|
||||
-v ./models:/work/models --env-file .env \
|
||||
ghcr.io/tuna2134/sbv2-api:cpu
|
||||
ghcr.io/neodyland/sbv2-api:cpu
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -90,7 +90,7 @@ CPUの場合は
|
||||
```bash
|
||||
docker run --platform linux/amd64 -it --rm -p 3000:3000 --name sbv2 \
|
||||
-v ./models:/work/models --env-file .env \
|
||||
ghcr.io/tuna2134/sbv2-api:cpu
|
||||
ghcr.io/neodyland/sbv2-api:cpu
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -99,7 +99,7 @@ CUDAの場合は
|
||||
docker run -it --rm -p 3000:3000 --name sbv2 \
|
||||
-v ./models:/work/models --env-file .env \
|
||||
--gpus all \
|
||||
ghcr.io/tuna2134/sbv2-api:cuda
|
||||
ghcr.io/neodyland/sbv2-api:cuda
|
||||
```
|
||||
|
||||
### 起動確認
|
||||
|
||||
@@ -53,12 +53,16 @@ struct SynthesizeRequest {
|
||||
text: String,
|
||||
ident: String,
|
||||
#[serde(default = "sdp_default")]
|
||||
#[schema(example = 0.0_f32)]
|
||||
sdp_ratio: f32,
|
||||
#[serde(default = "length_default")]
|
||||
#[schema(example = 1.0_f32)]
|
||||
length_scale: f32,
|
||||
#[serde(default = "style_id_default")]
|
||||
#[schema(example = 0_i32)]
|
||||
style_id: i32,
|
||||
#[serde(default = "speaker_id_default")]
|
||||
#[schema(example = 0_i64)]
|
||||
speaker_id: i64,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,21 +5,27 @@ use std::io::copy;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let static_path = home_dir().unwrap().join(".cache/sbv2/all.bin");
|
||||
let static_dir = home_dir().unwrap().join(".cache/sbv2");
|
||||
let static_path = static_dir.join("all.bin");
|
||||
let out_path = PathBuf::from(&env::var("OUT_DIR").unwrap()).join("all.bin");
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
if static_path.exists() {
|
||||
if fs::hard_link(&static_path, &out_path).is_err() {
|
||||
fs::copy(static_path, out_path).unwrap();
|
||||
};
|
||||
println!("cargo:info=Dictionary file already exists, skipping download.");
|
||||
} else {
|
||||
println!("cargo:warning=Downloading dictionary file...");
|
||||
let mut response =
|
||||
ureq::get("https://huggingface.co/neody/sbv2-api-assets/resolve/main/dic/all.bin")
|
||||
.call()?;
|
||||
let mut response = response.body_mut().as_reader();
|
||||
let mut file = fs::File::create(&out_path)?;
|
||||
if !static_dir.exists() {
|
||||
fs::create_dir_all(static_dir)?;
|
||||
}
|
||||
let mut file = fs::File::create(&static_path)?;
|
||||
copy(&mut response, &mut file)?;
|
||||
}
|
||||
if !out_path.exists() && fs::hard_link(&static_path, &out_path).is_err() {
|
||||
println!("cargo:warning=Failed to create hard link, copying instead.");
|
||||
fs::copy(static_path, out_path)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -14,11 +14,9 @@ pub fn predict(
|
||||
"attention_mask" => TensorRef::from_array_view((vec![1, attention_masks.len() as i64], attention_masks.as_slice()))?,
|
||||
}
|
||||
)?;
|
||||
|
||||
let output = outputs["output"]
|
||||
.try_extract_tensor::<f32>()?
|
||||
.try_extract_array::<f32>()?
|
||||
.into_dimensionality::<Ix2>()?
|
||||
.to_owned();
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ pub enum Error {
|
||||
Base64Error(#[from] base64::DecodeError),
|
||||
#[error("other")]
|
||||
OtherError(String),
|
||||
#[error("Style error: {0}")]
|
||||
StyleError(String),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -81,7 +81,7 @@ fn phone_tone_to_kana(phones: Vec<String>, tones: Vec<i32>) -> Vec<(String, i32)
|
||||
let tones = &tones[1..];
|
||||
let mut results = Vec::new();
|
||||
let mut current_mora = String::new();
|
||||
for ((phone, next_phone), (&tone, &next_tone)) in phones
|
||||
for ((phone, _next_phone), (&tone, &next_tone)) in phones
|
||||
.iter()
|
||||
.zip(phones.iter().skip(1))
|
||||
.zip(tones.iter().zip(tones.iter().skip(1)))
|
||||
|
||||
@@ -101,11 +101,9 @@ pub fn synthesize(
|
||||
"noise_scale" => noise_scale,
|
||||
"noise_scale_w" => noise_scale_w,
|
||||
})?;
|
||||
|
||||
let audio_array = outputs["output"]
|
||||
.try_extract_tensor::<f32>()?
|
||||
.try_extract_array::<f32>()?
|
||||
.into_dimensionality::<Ix3>()?
|
||||
.to_owned();
|
||||
|
||||
Ok(audio_array)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::error::Result;
|
||||
use crate::error::{Error, Result};
|
||||
use ndarray::{s, Array1, Array2};
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -21,6 +21,18 @@ pub fn get_style_vector(
|
||||
style_id: i32,
|
||||
weight: f32,
|
||||
) -> Result<Array1<f32>> {
|
||||
if style_vectors.shape().len() != 2 {
|
||||
return Err(Error::StyleError(
|
||||
"Invalid shape for style vectors".to_string(),
|
||||
));
|
||||
}
|
||||
if style_id < 0 || style_id >= style_vectors.shape()[0] as i32 {
|
||||
return Err(Error::StyleError(format!(
|
||||
"Invalid style ID: {}. Max ID: {}",
|
||||
style_id,
|
||||
style_vectors.shape()[0] - 1
|
||||
)));
|
||||
}
|
||||
let mean = style_vectors.slice(s![0, ..]).to_owned();
|
||||
let style_vector = style_vectors.slice(s![style_id as usize, ..]).to_owned();
|
||||
let diff = (style_vector - &mean) * weight;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
# StyleBertVITS2 wasm
|
||||
refer to https://github.com/tuna2134/sbv2-api
|
||||
refer to https://github.com/neodyland/sbv2-api
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "tuna2134",
|
||||
"contributes": ["neodyland"],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^1.9.4",
|
||||
|
||||
1
scripts/convert/.python-version
Normal file
1
scripts/convert/.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.11
|
||||
@@ -1,5 +1,6 @@
|
||||
style-bert-vits2
|
||||
git+https://github.com/neodyland/style-bert-vits2-ref
|
||||
onnxsim
|
||||
numpy<2
|
||||
zstandard
|
||||
onnxruntime
|
||||
cmake<4
|
||||
@@ -2,8 +2,16 @@ FROM rust AS builder
|
||||
WORKDIR /work
|
||||
COPY . .
|
||||
RUN cargo build -r --bin sbv2_api
|
||||
FROM gcr.io/distroless/cc-debian12
|
||||
FROM ubuntu AS upx
|
||||
WORKDIR /work
|
||||
RUN apt update && apt-get install -y upx binutils
|
||||
COPY --from=builder /work/target/release/sbv2_api /work/main
|
||||
COPY --from=builder /work/target/release/*.so /work
|
||||
CMD ["/work/main"]
|
||||
RUN upx --best --lzma /work/main
|
||||
RUN find /work -maxdepth 1 -name "*.so" -exec strip --strip-unneeded {} +
|
||||
RUN find /work -maxdepth 1 -name "*.so" -exec upx --best --lzma {} +
|
||||
FROM gcr.io/distroless/cc-debian12
|
||||
WORKDIR /work
|
||||
COPY --from=upx /work/main /work/main
|
||||
COPY --from=builder /work/*.so /work
|
||||
CMD ["/work/main"]
|
||||
|
||||
@@ -2,9 +2,17 @@ FROM rust AS builder
|
||||
WORKDIR /work
|
||||
COPY . .
|
||||
RUN cargo build -r --bin sbv2_api -F cuda,cuda_tf32
|
||||
FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04
|
||||
FROM ubuntu AS upx
|
||||
WORKDIR /work
|
||||
RUN apt update && apt-get install -y upx
|
||||
COPY --from=builder /work/target/release/sbv2_api /work/main
|
||||
COPY --from=builder /work/target/release/*.so /work
|
||||
RUN upx --best --lzma /work/main
|
||||
RUN find /work -maxdepth 1 -name "*.so" -exec strip --strip-unneeded {} +
|
||||
RUN find /work -maxdepth 1 -name "*.so" -exec upx --best --lzma {} +
|
||||
FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04
|
||||
WORKDIR /work
|
||||
COPY --from=upx /work/main /work/main
|
||||
COPY --from=builder /work/*.so /work
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/work
|
||||
CMD ["/work/main"]
|
||||
CMD ["/work/main"]
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
docker run -it --rm -p 3000:3000 --name sbv2 \
|
||||
-v ./models:/work/models --env-file .env \
|
||||
ghcr.io/tuna2134/sbv2-api:cpu
|
||||
ghcr.io/neodyland/sbv2-api:cpu
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
docker run -it --rm -p 3000:3000 --name sbv2 \
|
||||
-v ./models:/work/models --env-file .env \
|
||||
--gpus all \
|
||||
ghcr.io/tuna2134/sbv2-api:cuda
|
||||
ghcr.io/neodyland/sbv2-api:cuda
|
||||
|
||||
Reference in New Issue
Block a user