Compare commits

...

23 Commits

Author SHA1 Message Date
tuna2134
84e9118d99 Merge pull request #237 from neodyland/dependabot/cargo/ureq-3.1.0
build(deps): bump ureq from 3.0.12 to 3.1.0
2025-08-18 22:58:45 +09:00
tuna2134
3050cc1e99 Merge pull request #238 from neodyland/dependabot/cargo/thiserror-2.0.15
build(deps): bump thiserror from 2.0.12 to 2.0.15
2025-08-18 22:58:16 +09:00
tuna2134
d5fcacd799 Merge pull request #239 from neodyland/dependabot/cargo/ort-d269461
build(deps): bump ort from `f4ab181` to `d269461`
2025-08-18 22:58:01 +09:00
tuna2134
25ca89e341 Merge pull request #240 from neodyland/dependabot/cargo/anyhow-1.0.99
build(deps): bump anyhow from 1.0.98 to 1.0.99
2025-08-18 22:57:45 +09:00
dependabot[bot]
0c2a397775 build(deps): bump anyhow from 1.0.98 to 1.0.99
Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.98 to 1.0.99.
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](https://github.com/dtolnay/anyhow/compare/1.0.98...1.0.99)

---
updated-dependencies:
- dependency-name: anyhow
  dependency-version: 1.0.99
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 11:08:26 +00:00
dependabot[bot]
470a0348fe build(deps): bump ort from f4ab181 to d269461
Bumps [ort](https://github.com/pykeio/ort) from `f4ab181` to `d269461`.
- [Release notes](https://github.com/pykeio/ort/releases)
- [Commits](f4ab181702...d269461e21)

---
updated-dependencies:
- dependency-name: ort
  dependency-version: d269461e2130b407589feff404025df25faeb3bb
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 11:06:31 +00:00
dependabot[bot]
9a99b88b00 build(deps): bump thiserror from 2.0.12 to 2.0.15
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 2.0.12 to 2.0.15.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/2.0.12...2.0.15)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-version: 2.0.15
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 10:49:47 +00:00
dependabot[bot]
29f39f0795 build(deps): bump ureq from 3.0.12 to 3.1.0
Bumps [ureq](https://github.com/algesten/ureq) from 3.0.12 to 3.1.0.
- [Changelog](https://github.com/algesten/ureq/blob/main/CHANGELOG.md)
- [Commits](https://github.com/algesten/ureq/compare/3.0.12...3.1.0)

---
updated-dependencies:
- dependency-name: ureq
  dependency-version: 3.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 10:49:32 +00:00
tuna2134
9f22694df0 Merge pull request #236 from neodyland/dependabot/cargo/ort-f4ab181 2025-08-12 07:48:08 +09:00
tuna2134
62ba2c802f Merge pull request #235 from kono-dada/fix/inplace-model-load 2025-08-11 23:46:42 +09:00
dependabot[bot]
4f5b936f6f build(deps): bump ort from 5f96a2d to f4ab181
Bumps [ort](https://github.com/pykeio/ort) from `5f96a2d` to `f4ab181`.
- [Release notes](https://github.com/pykeio/ort/releases)
- [Commits](5f96a2d585...f4ab181702)

---
updated-dependencies:
- dependency-name: ort
  dependency-version: f4ab181702495bff99a488322d3a8de0d7050349
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-11 12:22:23 +00:00
kono-dada
3c8efc716c Fix: Load model in-place and safely evict sessions without removing entries
- Avoid removing and re-inserting model entries during load
- Preserve metadata (bytes, style_vectors) when evicting
- Ensure eviction targets a different loaded model, not always the first
- Reduce unnecessary memory allocations and keep list order stable
2025-08-11 16:31:57 +08:00
tuna2134
e9ced32b70 fix: streamline tone value handling in JTalkProcess 2025-08-11 17:30:46 +09:00
tuna2134
e7a1575cbc Merge pull request #233 from kono-dada/feature/stereo-output
feat: add stereo synthesis option via SBV2_FORCE_STEREO env var
2025-08-11 17:13:19 +09:00
kono-dada
873bbb77b6 feat: add stereo synthesis option via SBV2_FORCE_STEREO env var
Previously, synthesis output was fixed to mono (channels=1).
Now, setting the environment variable SBV2_FORCE_STEREO=1 forces stereo (2-channel) output.

This allows generating stereo audio without changing the code, useful for users needing dual-channel output.
2025-08-11 11:38:32 +08:00
tuna2134
1725863fca Merge pull request #228 from neodyland/dependabot/cargo/serde_json-1.0.142
build(deps): bump serde_json from 1.0.141 to 1.0.142
2025-08-04 22:12:36 +09:00
tuna2134
55f05580e4 Merge pull request #229 from neodyland/dependabot/cargo/tokenizers-0.21.4
build(deps): bump tokenizers from 0.21.2 to 0.21.4
2025-08-04 22:12:24 +09:00
tuna2134
320664eae2 Merge pull request #231 from neodyland/dependabot/cargo/tokio-1.47.1
build(deps): bump tokio from 1.47.0 to 1.47.1
2025-08-04 22:12:07 +09:00
tuna2134
87903827fa Merge pull request #230 from neodyland/dependabot/cargo/ort-5f96a2d
build(deps): bump ort from `d28c835` to `5f96a2d`
2025-08-04 22:11:55 +09:00
dependabot[bot]
9b8e9dc39d build(deps): bump tokio from 1.47.0 to 1.47.1
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.47.0 to 1.47.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.47.0...tokio-1.47.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-version: 1.47.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 11:10:28 +00:00
dependabot[bot]
bbc38081b6 build(deps): bump ort from d28c835 to 5f96a2d
Bumps [ort](https://github.com/pykeio/ort) from `d28c835` to `5f96a2d`.
- [Release notes](https://github.com/pykeio/ort/releases)
- [Commits](d28c835c3c...5f96a2d585)

---
updated-dependencies:
- dependency-name: ort
  dependency-version: 5f96a2d5857c3fe9f06282dbf4bdcddbca6c5fe6
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 10:24:07 +00:00
dependabot[bot]
0b822f704a build(deps): bump tokenizers from 0.21.2 to 0.21.4
Bumps [tokenizers](https://github.com/huggingface/tokenizers) from 0.21.2 to 0.21.4.
- [Release notes](https://github.com/huggingface/tokenizers/releases)
- [Changelog](https://github.com/huggingface/tokenizers/blob/main/RELEASE.md)
- [Commits](https://github.com/huggingface/tokenizers/compare/v0.21.2...v0.21.4)

---
updated-dependencies:
- dependency-name: tokenizers
  dependency-version: 0.21.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 10:18:59 +00:00
dependabot[bot]
132eb6386d build(deps): bump serde_json from 1.0.141 to 1.0.142
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.141 to 1.0.142.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.141...v1.0.142)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-version: 1.0.142
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 10:18:20 +00:00
7 changed files with 87 additions and 86 deletions

70
Cargo.lock generated
View File

@@ -92,9 +92,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.98" version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
[[package]] [[package]]
name = "atomic-waker" name = "atomic-waker"
@@ -1412,7 +1412,7 @@ dependencies = [
"reqwest", "reqwest",
"serde", "serde",
"tar", "tar",
"thiserror 2.0.12", "thiserror 2.0.15",
"yada", "yada",
] ]
@@ -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#d269461e2130b407589feff404025df25faeb3bb"
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#d269461e2130b407589feff404025df25faeb3bb"
dependencies = [ dependencies = [
"flate2", "flate2",
"pkg-config", "pkg-config",
@@ -1812,7 +1812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6"
dependencies = [ dependencies = [
"memchr", "memchr",
"thiserror 2.0.12", "thiserror 2.0.15",
"ucd-trie", "ucd-trie",
] ]
@@ -2141,7 +2141,7 @@ checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
dependencies = [ dependencies = [
"getrandom 0.2.16", "getrandom 0.2.16",
"libredox", "libredox",
"thiserror 2.0.12", "thiserror 2.0.15",
] ]
[[package]] [[package]]
@@ -2352,7 +2352,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"tar", "tar",
"thiserror 2.0.12", "thiserror 2.0.15",
"tokenizers", "tokenizers",
"ureq", "ureq",
"zstd", "zstd",
@@ -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",
@@ -2710,11 +2710,11 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.12" version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" checksum = "80d76d3f064b981389ecb4b6b7f45a0bf9fdac1d5b9204c7bd6714fecc302850"
dependencies = [ dependencies = [
"thiserror-impl 2.0.12", "thiserror-impl 2.0.15",
] ]
[[package]] [[package]]
@@ -2730,9 +2730,9 @@ dependencies = [
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.12" version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" checksum = "44d29feb33e986b6ea906bd9c3559a856983f92371b3eaa5e83782a351623de0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -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",
@@ -2793,7 +2793,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"spm_precompiled", "spm_precompiled",
"thiserror 2.0.12", "thiserror 2.0.15",
"unicode-normalization-alignments", "unicode-normalization-alignments",
"unicode-segmentation", "unicode-segmentation",
"unicode_categories", "unicode_categories",
@@ -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",
@@ -2997,9 +2997,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "ureq" name = "ureq"
version = "3.0.12" version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f0fde9bc91026e381155f8c67cb354bcd35260b2f4a29bcc84639f762760c39" checksum = "00432f493971db5d8e47a65aeb3b02f8226b9b11f1450ff86bb772776ebadd70"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"der", "der",
@@ -3013,15 +3013,15 @@ dependencies = [
"socks", "socks",
"ureq-proto", "ureq-proto",
"utf-8", "utf-8",
"webpki-root-certs 0.26.11", "webpki-root-certs",
"webpki-roots 0.26.11", "webpki-roots",
] ]
[[package]] [[package]]
name = "ureq-proto" name = "ureq-proto"
version = "0.4.2" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59db78ad1923f2b1be62b6da81fe80b173605ca0d57f85da2e005382adf693f7" checksum = "c5b6cabebbecc4c45189ab06b52f956206cea7d8c8a20851c35a85cb169224cc"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"http", "http",
@@ -3221,15 +3221,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "webpki-root-certs"
version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c7f0ef91146ebfb530314f5f1d24528d7f0767efbfd31dce919275413e393e"
dependencies = [
"webpki-root-certs 1.0.0",
]
[[package]] [[package]]
name = "webpki-root-certs" name = "webpki-root-certs"
version = "1.0.0" version = "1.0.0"
@@ -3239,15 +3230,6 @@ dependencies = [
"rustls-pki-types", "rustls-pki-types",
] ]
[[package]]
name = "webpki-roots"
version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
dependencies = [
"webpki-roots 1.0.0",
]
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "1.0.0" version = "1.0.0"

View File

@@ -12,7 +12,7 @@ repository = "https://github.com/neodyland/sbv2-api"
documentation = "https://docs.rs/sbv2_core" documentation = "https://docs.rs/sbv2_core"
[workspace.dependencies] [workspace.dependencies]
anyhow = "1.0.96" anyhow = "1.0.99"
dotenvy = "0.15.7" dotenvy = "0.15.7"
env_logger = "0.11.6" env_logger = "0.11.6"
ndarray = "0.16.1" ndarray = "0.16.1"

View File

@@ -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"] }

View File

@@ -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.15"
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]
@@ -44,4 +44,4 @@ base64 = ["dep:base64"]
[build-dependencies] [build-dependencies]
dirs = "6.0.0" dirs = "6.0.0"
ureq = "3.0.12" ureq = "3.1.0"

View File

@@ -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()))
} }
} }

View File

@@ -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
.iter()
.find(|m| m.ident == ident)
.ok_or(Error::ModelNotFoundError(ident.to_string()))?;
if model.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)?;
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
.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);
} }
Err(Error::ModelNotFoundError(ident.to_string()))
// 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 {
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()
.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;
}
}
}
// 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

View File

@@ -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,8 +190,16 @@ 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();
for sample in output { if force_stereo {
writer.write_sample(sample)?; 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()?; writer.finalize()?;