mirror of
https://github.com/neodyland/sbv2-api.git
synced 2025-12-23 07:59:56 +00:00
Compare commits
134 Commits
commit-973
...
commit-2cb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
767bfadf8f | ||
|
|
d6471ad9ad | ||
|
|
75c445530f | ||
|
|
2cb661fc76 | ||
|
|
f8a86fd6fc | ||
|
|
0d7d6ee960 | ||
|
|
5a6712c943 | ||
|
|
f3649921ed | ||
|
|
82c9f13ce4 | ||
|
|
dd3ee380e5 | ||
|
|
7034c1aad6 | ||
|
|
f00ce04032 | ||
|
|
a7e6fadf6d | ||
|
|
951551822a | ||
|
|
205cc2ae51 | ||
|
|
3519664fcd | ||
|
|
7d32db19b9 | ||
|
|
2cb43aaf6f | ||
|
|
d5a0f16bb0 | ||
|
|
6aac94e731 | ||
|
|
36f031bfcc | ||
|
|
f587a2c735 | ||
|
|
ca5887e864 | ||
|
|
9fbe75796c | ||
|
|
c6349d18bf | ||
|
|
87bec1b8c2 | ||
|
|
d928962b07 | ||
|
|
e3c9c5b19b | ||
|
|
47f2af1413 | ||
|
|
d6bc99caa3 | ||
|
|
b9e2c0fec1 | ||
|
|
8d97d4228a | ||
|
|
0651b49226 | ||
|
|
56e663c395 | ||
|
|
40cfda707e | ||
|
|
be7c48a12a | ||
|
|
e76b963dfb | ||
|
|
26dfe6dcdb | ||
|
|
8e031387ba | ||
|
|
51c0bf8521 | ||
|
|
33d6f1ccf0 | ||
|
|
404fa0f733 | ||
|
|
0e0e60e04b | ||
|
|
ac2f5a2b42 | ||
|
|
1b78865246 | ||
|
|
3054ab94e0 | ||
|
|
f98c6b8226 | ||
|
|
043f380c75 | ||
|
|
703035cc47 | ||
|
|
fcfff9395b | ||
|
|
0cbb6783cf | ||
|
|
37477c1e30 | ||
|
|
93c121da95 | ||
|
|
69d2857d11 | ||
|
|
5cb4480ac7 | ||
|
|
3553d01a7f | ||
|
|
91ac2fad78 | ||
|
|
ebcb6f9081 | ||
|
|
e47f57ade5 | ||
|
|
605ea12450 | ||
|
|
ef8b2d829c | ||
|
|
2aa43e0e3d | ||
|
|
ef071f2b55 | ||
|
|
dc5fa88432 | ||
|
|
a5f45cd2ef | ||
|
|
84e9118d99 | ||
|
|
3050cc1e99 | ||
|
|
d5fcacd799 | ||
|
|
25ca89e341 | ||
|
|
0c2a397775 | ||
|
|
470a0348fe | ||
|
|
9a99b88b00 | ||
|
|
29f39f0795 | ||
|
|
9f22694df0 | ||
|
|
62ba2c802f | ||
|
|
4f5b936f6f | ||
|
|
3c8efc716c | ||
|
|
e9ced32b70 | ||
|
|
e7a1575cbc | ||
|
|
873bbb77b6 | ||
|
|
1725863fca | ||
|
|
55f05580e4 | ||
|
|
320664eae2 | ||
|
|
87903827fa | ||
|
|
9b8e9dc39d | ||
|
|
bbc38081b6 | ||
|
|
0b822f704a | ||
|
|
132eb6386d | ||
|
|
ee56e9591d | ||
|
|
3194e599b2 | ||
|
|
00f4787f6e | ||
|
|
4b6c72aa51 | ||
|
|
7db6bb67a4 | ||
|
|
b3c75f973e | ||
|
|
e9529be559 | ||
|
|
a6694b5d81 | ||
|
|
096859de66 | ||
|
|
dabdc6712f | ||
|
|
45c3255a91 | ||
|
|
bf39890b3d | ||
|
|
120bc608d7 | ||
|
|
2fc547e38b | ||
|
|
98ddaa3c58 | ||
|
|
656e405cd7 | ||
|
|
9d6aa46fdf | ||
|
|
2fe90c6ede | ||
|
|
7faba2447b | ||
|
|
02ac0885e0 | ||
|
|
1f96b09f3b | ||
|
|
d583c1ca1c | ||
|
|
c135aac852 | ||
|
|
f31fa1d4f9 | ||
|
|
efec7cce14 | ||
|
|
61914129dc | ||
|
|
97c63a2e23 | ||
|
|
3475f47305 | ||
|
|
5493b91a84 | ||
|
|
bca6d04e7b | ||
|
|
d44ebe873e | ||
|
|
96b53d42cd | ||
|
|
9765ef51d2 | ||
|
|
655be55605 | ||
|
|
e68f58d698 | ||
|
|
2124fe4650 | ||
|
|
0217c0a4d5 | ||
|
|
1de09597f5 | ||
|
|
38d86c9249 | ||
|
|
ddc132b27b | ||
|
|
558cd24677 | ||
|
|
6657b06786 | ||
|
|
2a8c9bafde | ||
|
|
d7065ac6eb | ||
|
|
0b1dbe4991 | ||
|
|
1ad588bfcf |
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "cargo" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
448
Cargo.lock
generated
448
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ resolver = "3"
|
||||
members = ["./crates/sbv2_api", "./crates/sbv2_core", "./crates/sbv2_bindings", "./crates/sbv2_wasm"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.2.0-alpha6"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
description = "Style-Bert-VITSの推論ライブラリ"
|
||||
license = "MIT"
|
||||
@@ -12,7 +12,7 @@ repository = "https://github.com/neodyland/sbv2-api"
|
||||
documentation = "https://docs.rs/sbv2_core"
|
||||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1.0.96"
|
||||
anyhow = "1.0.100"
|
||||
dotenvy = "0.15.7"
|
||||
env_logger = "0.11.6"
|
||||
ndarray = "0.16.1"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tuna2134
|
||||
Copyright (c) 2021- neodyland
|
||||
Copyright (c) 2025- 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
|
||||
@@ -10,14 +10,14 @@ license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
axum = "0.8.0"
|
||||
axum = "0.8.6"
|
||||
dotenvy.workspace = true
|
||||
env_logger.workspace = true
|
||||
log = "0.4.22"
|
||||
log = "0.4.28"
|
||||
sbv2_core = { version = "0.2.0-alpha6", path = "../sbv2_core", features = ["aivmx"] }
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
tokio = { version = "1.40.0", features = ["full"] }
|
||||
utoipa = { version = "5.0.0", features = ["axum_extras"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
utoipa = { version = "5.4.0", features = ["axum_extras"] }
|
||||
utoipa-scalar = { version = "0.3.0", features = ["axum"] }
|
||||
|
||||
[features]
|
||||
|
||||
@@ -16,7 +16,7 @@ crate-type = ["cdylib"]
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
ndarray.workspace = true
|
||||
pyo3 = { version = "0.24.0", features = ["anyhow"] }
|
||||
pyo3 = { version = "0.27.1", features = ["anyhow"] }
|
||||
sbv2_core = { path = "../sbv2_core", features = ["std"], default-features = false }
|
||||
|
||||
[features]
|
||||
|
||||
@@ -16,16 +16,16 @@ env_logger.workspace = true
|
||||
hound = "3.5.1"
|
||||
jpreprocess = { version = "0.12.0", features = ["naist-jdic"] }
|
||||
ndarray.workspace = true
|
||||
npyz = { version = "0.8.3", optional = true }
|
||||
num_cpus = "1.16.0"
|
||||
npyz = { version = "0.8.4", optional = true }
|
||||
num_cpus = "1.17.0"
|
||||
once_cell.workspace = true
|
||||
ort = { git = "https://github.com/pykeio/ort.git", version = "2.0.0-rc.9", optional = true }
|
||||
regex = "1.10.6"
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
serde_json = "1.0.128"
|
||||
regex = "1.12.2"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.145"
|
||||
tar = "0.4.41"
|
||||
thiserror = "2.0.11"
|
||||
tokenizers = { version = "0.21.0", default-features = false }
|
||||
thiserror = "2.0.17"
|
||||
tokenizers = { version = "0.22.1", default-features = false }
|
||||
zstd = "0.13.2"
|
||||
|
||||
[features]
|
||||
@@ -44,4 +44,4 @@ base64 = ["dep:base64"]
|
||||
|
||||
[build-dependencies]
|
||||
dirs = "6.0.0"
|
||||
ureq = "3.0.6"
|
||||
ureq = "3.1.2"
|
||||
|
||||
@@ -1,3 +1,175 @@
|
||||
/*
|
||||
このファイルのコードは
|
||||
https://github.com/litagin02/Style-Bert-VITS2/blob/master/style_bert_vits2/nlp/japanese/g2p.py
|
||||
を参考にRustに書き換えています。
|
||||
|
||||
以下はライセンスです。
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
*/
|
||||
use crate::error::{Error, Result};
|
||||
use crate::mora::{CONSONANTS, MORA_KATA_TO_MORA_PHONEMES, MORA_PHONEMES_TO_MORA_KATA, VOWELS};
|
||||
use crate::norm::{replace_punctuation, PUNCTUATIONS};
|
||||
@@ -123,24 +295,24 @@ impl JTalkProcess {
|
||||
.map(|(_letter, tone)| *tone)
|
||||
.collect();
|
||||
if tone_values.len() == 1 {
|
||||
assert!(tone_values == hash_set![0], "{:?}", tone_values);
|
||||
assert!(tone_values == hash_set![0], "{tone_values:?}");
|
||||
Ok(phone_tone_list)
|
||||
} else if tone_values.len() == 2 {
|
||||
if tone_values == hash_set![0, 1] {
|
||||
return Ok(phone_tone_list);
|
||||
Ok(phone_tone_list)
|
||||
} else if tone_values == hash_set![-1, 0] {
|
||||
return Ok(phone_tone_list
|
||||
Ok(phone_tone_list
|
||||
.iter()
|
||||
.map(|x| {
|
||||
let new_tone = if x.1 == -1 { 0 } else { 1 };
|
||||
(x.0.clone(), new_tone)
|
||||
})
|
||||
.collect());
|
||||
.collect())
|
||||
} else {
|
||||
return Err(Error::ValueError("Invalid tone values 0".to_string()));
|
||||
Err(Error::ValueError("Invalid tone values 0".to_string()))
|
||||
}
|
||||
} else {
|
||||
return Err(Error::ValueError("Invalid tone values 1".to_string()));
|
||||
Err(Error::ValueError("Invalid tone values 1".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +398,12 @@ impl JTalkProcess {
|
||||
} else if PUNCTUATIONS.contains(&phone.as_str()) {
|
||||
result.push((phone, 0));
|
||||
} else {
|
||||
println!("phones {:?}", phone_with_punct);
|
||||
println!("phone_tone_list: {:?}", phone_tone_list);
|
||||
println!("result: {:?}", result);
|
||||
println!("tone_index: {:?}", tone_index);
|
||||
println!("phone: {:?}", phone);
|
||||
return Err(Error::ValueError(format!("Mismatched phoneme: {}", phone)));
|
||||
println!("phones {phone_with_punct:?}");
|
||||
println!("phone_tone_list: {phone_tone_list:?}");
|
||||
println!("result: {result:?}");
|
||||
println!("tone_index: {tone_index:?}");
|
||||
println!("phone: {phone:?}");
|
||||
return Err(Error::ValueError(format!("Mismatched phoneme: {phone}")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,8 +448,7 @@ impl JTalkProcess {
|
||||
}
|
||||
if !KATAKANA_PATTERN.is_match(&text) {
|
||||
return Err(Error::ValueError(format!(
|
||||
"Input must be katakana only: {}",
|
||||
text
|
||||
"Input must be katakana only: {text}"
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -285,7 +456,7 @@ impl JTalkProcess {
|
||||
let mora = mora.to_string();
|
||||
let (consonant, vowel) = MORA_KATA_TO_MORA_PHONEMES.get(&mora).unwrap();
|
||||
if consonant.is_none() {
|
||||
text = text.replace(&mora, &format!(" {}", vowel));
|
||||
text = text.replace(&mora, &format!(" {vowel}"));
|
||||
} else {
|
||||
text = text.replace(
|
||||
&mora,
|
||||
@@ -319,7 +490,7 @@ impl JTalkProcess {
|
||||
let (string, pron) = self.parse_to_string_and_pron(parts.clone());
|
||||
let mut yomi = pron.replace('’', "");
|
||||
let word = replace_punctuation(string);
|
||||
assert!(!yomi.is_empty(), "Empty yomi: {}", word);
|
||||
assert!(!yomi.is_empty(), "Empty yomi: {word}");
|
||||
if yomi == "、" {
|
||||
if !word
|
||||
.chars()
|
||||
@@ -330,7 +501,7 @@ impl JTalkProcess {
|
||||
yomi = word.clone();
|
||||
}
|
||||
} else if yomi == "?" {
|
||||
assert!(word == "?", "yomi `?` comes from: {}", word);
|
||||
assert!(word == "?", "yomi `?` comes from: {word}");
|
||||
yomi = "?".to_string();
|
||||
}
|
||||
seq_text.push(word);
|
||||
|
||||
@@ -91,7 +91,7 @@ impl TTSModelHolder {
|
||||
}
|
||||
let model = model::load_model(&aivmx_bytes, false)?;
|
||||
let metadata = model.metadata()?;
|
||||
if let Some(aivm_style_vectors) = metadata.custom("aivm_style_vectors")? {
|
||||
if let Some(aivm_style_vectors) = metadata.custom("aivm_style_vectors") {
|
||||
let aivm_style_vectors = BASE64_STANDARD.decode(aivm_style_vectors)?;
|
||||
let style_vectors = Cursor::new(&aivm_style_vectors);
|
||||
let reader = npyz::NpyFile::new(style_vectors)?;
|
||||
@@ -240,39 +240,43 @@ impl TTSModelHolder {
|
||||
}
|
||||
fn find_and_load_model<I: Into<TTSIdent>>(&mut self, ident: I) -> Result<bool> {
|
||||
let ident = ident.into();
|
||||
let (bytes, style_vectors) = {
|
||||
let model = self
|
||||
// Locate target model entry
|
||||
let target_index = self
|
||||
.models
|
||||
.iter()
|
||||
.find(|m| m.ident == ident)
|
||||
.position(|m| m.ident == ident)
|
||||
.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);
|
||||
}
|
||||
(model.bytes.clone().unwrap(), model.style_vectors.clone())
|
||||
};
|
||||
self.unload(ident.clone());
|
||||
let s = model::load_model(&bytes, false)?;
|
||||
|
||||
// Get bytes to build a Session
|
||||
let bytes = self.models[target_index]
|
||||
.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 self.models.iter().filter(|x| x.vits2.is_some()).count() >= max {
|
||||
self.unload(self.models.first().unwrap().ident.clone());
|
||||
}
|
||||
}
|
||||
self.models.push(TTSModel {
|
||||
bytes: Some(bytes.to_vec()),
|
||||
vits2: Some(s),
|
||||
style_vectors,
|
||||
ident: ident.clone(),
|
||||
});
|
||||
let model = self
|
||||
let loaded_count = self.models.iter().filter(|m| m.vits2.is_some()).count();
|
||||
if loaded_count >= max {
|
||||
if let Some(evict_index) = self
|
||||
.models
|
||||
.iter()
|
||||
.find(|m| m.ident == ident)
|
||||
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
|
||||
if model.vits2.is_some() {
|
||||
return Ok(true);
|
||||
.position(|m| m.vits2.is_some() && m.ident != ident)
|
||||
{
|
||||
// Drop only the session to free memory; keep bytes/style for future reload
|
||||
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
|
||||
|
||||
@@ -173,8 +173,15 @@ pub fn parse_text_blocking(
|
||||
}
|
||||
|
||||
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 {
|
||||
channels: 1,
|
||||
channels,
|
||||
sample_rate: 44100,
|
||||
bits_per_sample: 32,
|
||||
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)?;
|
||||
for i in 0..audio_array.shape()[0] {
|
||||
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 {
|
||||
writer.write_sample(sample)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.finalize()?;
|
||||
Ok(cursor.into_inner())
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ sbv2_core = { path = "../sbv2_core", default-features = false, features = ["no_s
|
||||
once_cell.workspace = true
|
||||
js-sys = "0.3.70"
|
||||
ndarray.workspace = true
|
||||
wasm-bindgen-futures = "0.4.43"
|
||||
wasm-bindgen-futures = "0.4.54"
|
||||
|
||||
@@ -13,5 +13,5 @@ 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
|
||||
COPY --from=upx /work/*.so /work
|
||||
CMD ["/work/main"]
|
||||
|
||||
@@ -12,6 +12,6 @@ RUN find /work -maxdepth 1 -name "*.so" -exec strip --strip-unneeded {} +
|
||||
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
|
||||
COPY --from=upx /work/*.so /work
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/work
|
||||
CMD ["/work/main"]
|
||||
|
||||
Reference in New Issue
Block a user