Skip to content

Commit

Permalink
Merge pull request #60 from tuna2134/label
Browse files Browse the repository at this point in the history
正規表現使うのやめた
  • Loading branch information
tuna2134 authored Sep 25, 2024
2 parents eb249aa + 886ab78 commit a99fd39
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SBV2-API

## 注意:本バージョンはアルファ版です。
安定版を利用したい場合は[こちら](https://github.com/tuna2134/sbv2-api/tree/v0.1.x)をご覧ください。

## プログラミングに詳しくない方向け

[こちら](https://github.com/tuna2134/sbv2-gui?tab=readme-ov-file)を参照してください。
Expand Down
2 changes: 1 addition & 1 deletion sbv2_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ fn main() {
if cfg!(feature = "coreml") {
println!("cargo:rustc-link-arg=-fapple-link-rtlib");
}
}
}
2 changes: 1 addition & 1 deletion sbv2_bindings/src/sbv2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use sbv2_core::tts::{TTSModelHolder, SynthesizeOptions};
use sbv2_core::tts::{SynthesizeOptions, TTSModelHolder};

use crate::style::StyleVector;

Expand Down
54 changes: 29 additions & 25 deletions sbv2_core/src/jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@ fn initialize_jtalk() -> Result<JPreprocessType> {
Ok(jpreprocess)
}

static JTALK_G2P_G_A1_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"/A:([0-9\-]+)\+").unwrap());
static JTALK_G2P_G_A2_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"\+(\d+)\+").unwrap());
static JTALK_G2P_G_A3_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"\+(\d+)/").unwrap());
static JTALK_G2P_G_E3_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"!(\d+)_").unwrap());
static JTALK_G2P_G_F1_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"/F:(\d+)_").unwrap());
static JTALK_G2P_G_P3_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"\-(.*?)\+").unwrap());

fn numeric_feature_by_regex(regex: &Regex, text: &str) -> i32 {
if let Some(mat) = regex.captures(text) {
mat[1].parse::<i32>().unwrap()
} else {
-50
}
}

macro_rules! hash_set {
($($elem:expr),* $(,)?) => {{
let mut set = HashSet::new();
Expand Down Expand Up @@ -351,7 +336,7 @@ impl JTalkProcess {

let mut phones: Vec<String> = Vec::new();
for (i, label) in labels.iter().enumerate() {
let mut p3 = label.phoneme.c;
let mut p3 = label.phoneme.c.clone().unwrap();
if "AIUEO".contains(&p3) {
// 文字をlowerする
p3 = p3.to_lowercase();
Expand All @@ -361,10 +346,10 @@ impl JTalkProcess {
if i == 0 {
phones.push("^".to_string());
} else if i == labels.len() - 1 {
let e3 = numeric_feature_by_regex(&JTALK_G2P_G_E3_PATTERN, &label.to_string());
if e3 == 0 {
let e3 = label.accent_phrase_prev.clone().unwrap().is_interrogative;
if e3 {
phones.push("$".to_string());
} else if e3 == 1 {
} else {
phones.push("?".to_string());
}
}
Expand All @@ -376,14 +361,33 @@ impl JTalkProcess {
phones.push(p3.clone());
}

let a1 = numeric_feature_by_regex(&JTALK_G2P_G_A1_PATTERN, &label.to_string());
let a2 = numeric_feature_by_regex(&JTALK_G2P_G_A2_PATTERN, &label.to_string());
let a3 = numeric_feature_by_regex(&JTALK_G2P_G_A3_PATTERN, &label.to_string());
let a1 = if let Some(mora) = &label.mora {
mora.relative_accent_position as i32
} else {
-50
};
let a2 = if let Some(mora) = &label.mora {
mora.position_forward as i32
} else {
-50
};
let a3 = if let Some(mora) = &label.mora {
mora.position_backward as i32
} else {
-50
};

let f1 = numeric_feature_by_regex(&JTALK_G2P_G_F1_PATTERN, &label.to_string());
let f1 = if let Some(accent_phrase) = &label.accent_phrase_curr {
accent_phrase.mora_count as i32
} else {
-50
};

let a2_next =
numeric_feature_by_regex(&JTALK_G2P_G_A2_PATTERN, &labels[i + 1].to_string());
let a2_next = if let Some(mora) = &labels[i + 1].mora {
mora.position_forward as i32
} else {
-50
};

if a3 == 1 && a2_next == 1 && "aeiouAEIOUNcl".contains(&p3) {
phones.push("#".to_string());
Expand Down

0 comments on commit a99fd39

Please sign in to comment.