From 993c0c1c7ec8546501933d62b8e8e9e78dbd1c36 Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Thu, 8 Feb 2024 08:20:13 +0900 Subject: [PATCH 01/32] add jlabel --- Cargo.lock | 58 +++++++++++++++++++-------------- Cargo.toml | 1 + crates/voicevox_core/Cargo.toml | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eaedb6a21..b077429c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1061,7 +1061,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -1072,7 +1072,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -1259,7 +1259,7 @@ checksum = "48c69b3965971f5d0ea6a6dd26b55cdd517ae0e1425dc8d94e482a5915bd7ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -1272,7 +1272,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -1499,7 +1499,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -2021,6 +2021,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +[[package]] +name = "jlabel" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f040b22c55628977296069dbf8635be49cc510999c048a1f1bdb56d00983148" +dependencies = [ + "thiserror", +] + [[package]] name = "jni" version = "0.21.1" @@ -2590,7 +2599,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -2666,7 +2675,7 @@ dependencies = [ "regex", "regex-syntax 0.7.5", "structmeta", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -2861,9 +2870,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2963,9 +2972,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3396,7 +3405,7 @@ checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -3478,7 +3487,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -3721,7 +3730,7 @@ dependencies = [ "proc-macro2", "quote", "structmeta-derive", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -3732,7 +3741,7 @@ checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -3799,9 +3808,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -3879,22 +3888,22 @@ checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 1.0.102", + "syn 2.0.48", ] [[package]] @@ -4012,7 +4021,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -4358,6 +4367,7 @@ dependencies = [ "humansize", "indexmap 2.0.0", "itertools 0.10.5", + "jlabel", "nanoid", "ndarray", "once_cell", @@ -4445,7 +4455,7 @@ dependencies = [ "indexmap 2.0.0", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index acaa1300b..9f5cccf85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ indexmap = "2.0.0" indicatif = "0.17.3" inventory = "0.3.4" itertools = "0.10.5" +jlabel = "0.1.2" jni = "0.21.1" libc = "0.2.134" libloading = "0.7.3" diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 8d7c70e7e..18d8f818a 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -22,6 +22,7 @@ fs-err = { workspace = true, features = ["tokio"] } futures.workspace = true indexmap = { workspace = true, features = ["serde"] } itertools.workspace = true +jlabel.workspace = true nanoid.workspace = true ndarray.workspace = true once_cell.workspace = true From 2edda55ab415b347795cb1a7ef16c549b28b1684 Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Thu, 8 Feb 2024 08:20:40 +0900 Subject: [PATCH 02/32] create convert less allocation less unwrap move to full_context_label proper error handling switch change order fix bugs --- .../src/engine/full_context_label.rs | 182 +++++++++++++++++- crates/voicevox_core/src/engine/mod.rs | 2 +- crates/voicevox_core/src/synthesizer.rs | 69 +------ 3 files changed, 183 insertions(+), 70 deletions(-) diff --git a/crates/voicevox_core/src/engine/full_context_label.rs b/crates/voicevox_core/src/engine/full_context_label.rs index 79928d246..c563c90db 100644 --- a/crates/voicevox_core/src/engine/full_context_label.rs +++ b/crates/voicevox_core/src/engine/full_context_label.rs @@ -1,8 +1,12 @@ -use std::collections::HashMap; +use std::{collections::HashMap, str::FromStr}; -use crate::engine::open_jtalk::FullcontextExtractor; +use crate::{ + engine::{self, open_jtalk::FullcontextExtractor, MoraModel}, + AccentPhraseModel, +}; use derive_getters::Getters; use derive_new::new; +use jlabel::Label; use once_cell::sync::Lazy; use regex::Regex; @@ -20,6 +24,9 @@ enum ErrorKind { #[display(fmt = "Open JTalkで解釈することができませんでした")] OpenJtalk, + #[display(fmt = "jlabelで解釈することができませんでした")] + Jlabel, + #[display(fmt = "label parse error label: {label}")] LabelParse { label: String }, @@ -127,12 +134,12 @@ pub struct AccentPhrase { } impl AccentPhrase { - fn from_phonemes(mut phonemes: Vec) -> std::result::Result { + fn from_phonemes(phonemes: Vec) -> std::result::Result { let mut moras = Vec::with_capacity(phonemes.len()); let mut mora_phonemes = Vec::with_capacity(phonemes.len()); for i in 0..phonemes.len() { { - let phoneme = phonemes.get_mut(i).unwrap(); + let phoneme = phonemes.get(i).unwrap(); if phoneme.contexts().get("a2").map(|s| s.as_str()) == Some("49") { break; } @@ -338,3 +345,170 @@ impl Utterance { }) } } + +pub(crate) fn extract_full_context_label( + open_jtalk: &impl FullcontextExtractor, + text: impl AsRef, +) -> Result> { + let labels = open_jtalk + .extract_fullcontext(text.as_ref()) + .map_err(|source| FullContextLabelError { + context: ErrorKind::OpenJtalk, + source: Some(source), + })?; + + let parsed_labels = labels + .into_iter() + .map(|s| Label::from_str(&s)) + .collect::, _>>() + .map_err(|source| FullContextLabelError { + context: ErrorKind::Jlabel, + source: Some(anyhow::anyhow!("{}", source)), + })?; + + convert_to_accentphrase_models(parsed_labels).map_err(|context| FullContextLabelError { + context, + source: None, + }) +} + +fn convert_to_accentphrase_models( + utterance: Vec