mirror of
https://github.com/neodyland/sbv2-api.git
synced 2025-12-23 15:59:57 +00:00
Compare commits
15 Commits
commit-ee5
...
commit-9f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f22694df0 | ||
|
|
62ba2c802f | ||
|
|
4f5b936f6f | ||
|
|
3c8efc716c | ||
|
|
e9ced32b70 | ||
|
|
e7a1575cbc | ||
|
|
873bbb77b6 | ||
|
|
1725863fca | ||
|
|
55f05580e4 | ||
|
|
320664eae2 | ||
|
|
87903827fa | ||
|
|
9b8e9dc39d | ||
|
|
bbc38081b6 | ||
|
|
0b822f704a | ||
|
|
132eb6386d |
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -1740,7 +1740,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ort"
|
name = "ort"
|
||||||
version = "2.0.0-rc.10"
|
version = "2.0.0-rc.10"
|
||||||
source = "git+https://github.com/pykeio/ort.git#d28c835c3cc98bcbefc208dc26c8618ccbadec3f"
|
source = "git+https://github.com/pykeio/ort.git#f4ab181702495bff99a488322d3a8de0d7050349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libloading",
|
"libloading",
|
||||||
"ndarray",
|
"ndarray",
|
||||||
@@ -1752,7 +1752,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ort-sys"
|
name = "ort-sys"
|
||||||
version = "2.0.0-rc.10"
|
version = "2.0.0-rc.10"
|
||||||
source = "git+https://github.com/pykeio/ort.git#d28c835c3cc98bcbefc208dc26c8618ccbadec3f"
|
source = "git+https://github.com/pykeio/ort.git#f4ab181702495bff99a488322d3a8de0d7050349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
@@ -2430,9 +2430,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.141"
|
version = "1.0.142"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
|
checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -2766,9 +2766,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokenizers"
|
name = "tokenizers"
|
||||||
version = "0.21.2"
|
version = "0.21.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4c3846d8588abed0daba25a0e47edd58ea15e450a6088b2575f5116fdb0b27ca"
|
checksum = "a620b996116a59e184c2fa2dfd8251ea34a36d0a514758c6f966386bd2e03476"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
@@ -2801,9 +2801,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.47.0"
|
version = "1.47.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35"
|
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ env_logger.workspace = true
|
|||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
sbv2_core = { version = "0.2.0-alpha6", path = "../sbv2_core", features = ["aivmx"] }
|
sbv2_core = { version = "0.2.0-alpha6", path = "../sbv2_core", features = ["aivmx"] }
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
tokio = { version = "1.47.0", features = ["full"] }
|
tokio = { version = "1.47.1", features = ["full"] }
|
||||||
utoipa = { version = "5.4.0", features = ["axum_extras"] }
|
utoipa = { version = "5.4.0", features = ["axum_extras"] }
|
||||||
utoipa-scalar = { version = "0.3.0", features = ["axum"] }
|
utoipa-scalar = { version = "0.3.0", features = ["axum"] }
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ once_cell.workspace = true
|
|||||||
ort = { git = "https://github.com/pykeio/ort.git", version = "2.0.0-rc.9", optional = true }
|
ort = { git = "https://github.com/pykeio/ort.git", version = "2.0.0-rc.9", optional = true }
|
||||||
regex = "1.10.6"
|
regex = "1.10.6"
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
serde_json = "1.0.141"
|
serde_json = "1.0.142"
|
||||||
tar = "0.4.41"
|
tar = "0.4.41"
|
||||||
thiserror = "2.0.11"
|
thiserror = "2.0.11"
|
||||||
tokenizers = { version = "0.21.2", default-features = false }
|
tokenizers = { version = "0.21.4", default-features = false }
|
||||||
zstd = "0.13.2"
|
zstd = "0.13.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -127,20 +127,20 @@ impl JTalkProcess {
|
|||||||
Ok(phone_tone_list)
|
Ok(phone_tone_list)
|
||||||
} else if tone_values.len() == 2 {
|
} else if tone_values.len() == 2 {
|
||||||
if tone_values == hash_set![0, 1] {
|
if tone_values == hash_set![0, 1] {
|
||||||
return Ok(phone_tone_list);
|
Ok(phone_tone_list)
|
||||||
} else if tone_values == hash_set![-1, 0] {
|
} else if tone_values == hash_set![-1, 0] {
|
||||||
return Ok(phone_tone_list
|
Ok(phone_tone_list
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
let new_tone = if x.1 == -1 { 0 } else { 1 };
|
let new_tone = if x.1 == -1 { 0 } else { 1 };
|
||||||
(x.0.clone(), new_tone)
|
(x.0.clone(), new_tone)
|
||||||
})
|
})
|
||||||
.collect());
|
.collect())
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::ValueError("Invalid tone values 0".to_string()));
|
Err(Error::ValueError("Invalid tone values 0".to_string()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::ValueError("Invalid tone values 1".to_string()));
|
Err(Error::ValueError("Invalid tone values 1".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,39 +240,43 @@ impl TTSModelHolder {
|
|||||||
}
|
}
|
||||||
fn find_and_load_model<I: Into<TTSIdent>>(&mut self, ident: I) -> Result<bool> {
|
fn find_and_load_model<I: Into<TTSIdent>>(&mut self, ident: I) -> Result<bool> {
|
||||||
let ident = ident.into();
|
let ident = ident.into();
|
||||||
let (bytes, style_vectors) = {
|
// Locate target model entry
|
||||||
let model = self
|
let target_index = self
|
||||||
.models
|
.models
|
||||||
.iter()
|
.iter()
|
||||||
.find(|m| m.ident == ident)
|
.position(|m| m.ident == ident)
|
||||||
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
|
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
|
||||||
if model.vits2.is_some() {
|
|
||||||
|
// Already loaded
|
||||||
|
if self.models[target_index].vits2.is_some() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
(model.bytes.clone().unwrap(), model.style_vectors.clone())
|
|
||||||
};
|
// Get bytes to build a Session
|
||||||
self.unload(ident.clone());
|
let bytes = self.models[target_index]
|
||||||
let s = model::load_model(&bytes, false)?;
|
.bytes
|
||||||
|
.clone()
|
||||||
|
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
|
||||||
|
|
||||||
|
// Enforce max loaded models by evicting a different loaded model's session, not removing the entry
|
||||||
if let Some(max) = self.max_loaded_models {
|
if let Some(max) = self.max_loaded_models {
|
||||||
if self.models.iter().filter(|x| x.vits2.is_some()).count() >= max {
|
let loaded_count = self.models.iter().filter(|m| m.vits2.is_some()).count();
|
||||||
self.unload(self.models.first().unwrap().ident.clone());
|
if loaded_count >= max {
|
||||||
}
|
if let Some(evict_index) = self
|
||||||
}
|
|
||||||
self.models.push(TTSModel {
|
|
||||||
bytes: Some(bytes.to_vec()),
|
|
||||||
vits2: Some(s),
|
|
||||||
style_vectors,
|
|
||||||
ident: ident.clone(),
|
|
||||||
});
|
|
||||||
let model = self
|
|
||||||
.models
|
.models
|
||||||
.iter()
|
.iter()
|
||||||
.find(|m| m.ident == ident)
|
.position(|m| m.vits2.is_some() && m.ident != ident)
|
||||||
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
|
{
|
||||||
if model.vits2.is_some() {
|
// Drop only the session to free memory; keep bytes/style for future reload
|
||||||
return Ok(true);
|
self.models[evict_index].vits2 = None;
|
||||||
}
|
}
|
||||||
Err(Error::ModelNotFoundError(ident.to_string()))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build and set session in-place for the target model
|
||||||
|
let s = model::load_model(&bytes, false)?;
|
||||||
|
self.models[target_index].vits2 = Some(s);
|
||||||
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get style vector by style id and weight
|
/// Get style vector by style id and weight
|
||||||
|
|||||||
@@ -173,8 +173,15 @@ pub fn parse_text_blocking(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_to_vec(audio_array: Array3<f32>) -> Result<Vec<u8>> {
|
pub fn array_to_vec(audio_array: Array3<f32>) -> Result<Vec<u8>> {
|
||||||
|
// If SBV2_FORCE_STEREO is set ("1"/"true"), duplicate mono to stereo
|
||||||
|
let force_stereo = std::env::var("SBV2_FORCE_STEREO")
|
||||||
|
.ok()
|
||||||
|
.map(|v| matches!(v.as_str(), "1" | "true" | "TRUE" | "True"))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
let channels: u16 = if force_stereo { 2 } else { 1 };
|
||||||
let spec = WavSpec {
|
let spec = WavSpec {
|
||||||
channels: 1,
|
channels,
|
||||||
sample_rate: 44100,
|
sample_rate: 44100,
|
||||||
bits_per_sample: 32,
|
bits_per_sample: 32,
|
||||||
sample_format: SampleFormat::Float,
|
sample_format: SampleFormat::Float,
|
||||||
@@ -183,10 +190,18 @@ pub fn array_to_vec(audio_array: Array3<f32>) -> Result<Vec<u8>> {
|
|||||||
let mut writer = WavWriter::new(&mut cursor, spec)?;
|
let mut writer = WavWriter::new(&mut cursor, spec)?;
|
||||||
for i in 0..audio_array.shape()[0] {
|
for i in 0..audio_array.shape()[0] {
|
||||||
let output = audio_array.slice(s![i, 0, ..]).to_vec();
|
let output = audio_array.slice(s![i, 0, ..]).to_vec();
|
||||||
|
if force_stereo {
|
||||||
|
for sample in output {
|
||||||
|
// Write to Left and Right channels
|
||||||
|
writer.write_sample(sample)?;
|
||||||
|
writer.write_sample(sample)?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for sample in output {
|
for sample in output {
|
||||||
writer.write_sample(sample)?;
|
writer.write_sample(sample)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
writer.finalize()?;
|
writer.finalize()?;
|
||||||
Ok(cursor.into_inner())
|
Ok(cursor.into_inner())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user