Skip to content

Commit

Permalink
Merge branch 'main' into change-liberate-voicevox-core
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Sep 19, 2024
2 parents c5db7b8 + c7c8cf1 commit d5bce52
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 89 deletions.
3 changes: 0 additions & 3 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,5 @@ humansize.workspace = true
windows = { workspace = true, features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] }

[lints.rust]
# FIXME: `unsafe impl Send`のもあるが、以下2つのマージにより消える予定
# * https://github.com/VOICEVOX/voicevox_core/pull/725
# * https://github.com/VOICEVOX/voicevox_core/pull/772
unsafe_code = "allow" # WindowsのGPU情報表示に、Win32を利用
rust_2018_idioms = "warn"
12 changes: 4 additions & 8 deletions crates/voicevox_core/src/engine/acoustic_feature_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ static PHONEME_MAP: LazyLock<HashMap<&str, i64>> = LazyLock::new(|| {
#[derive(Debug, Clone, PartialEq, new, Default, Getters)]
pub(crate) struct OjtPhoneme {
phoneme: String,
// FIXME: derive-getters(多分)が警告を覆い隠しているが、以下の二つは使っていないはず
start: f32,
end: f32,
}

impl OjtPhoneme {
Expand Down Expand Up @@ -113,8 +110,8 @@ mod tests {
fn base_hello_hiho() -> Vec<OjtPhoneme> {
STR_HELLO_HIHO
.split_whitespace()
.enumerate()
.map(|(i, s)| OjtPhoneme::new(s.into(), i as f32, (i + 1) as f32))
.map(ToOwned::to_owned)
.map(OjtPhoneme::new)
.collect()
}

Expand Down Expand Up @@ -154,9 +151,8 @@ mod tests {
}

#[rstest]
#[case(ojt_hello_hiho(), 9, OjtPhoneme::new("a".into(), 9., 10.), true)]
#[case(ojt_hello_hiho(), 9, OjtPhoneme::new("k".into(), 9., 10.), false)]
#[case(ojt_hello_hiho(), 9, OjtPhoneme::new("a".into(), 10., 11.), false)]
#[case(ojt_hello_hiho(), 9, OjtPhoneme::new("a".into()), true)]
#[case(ojt_hello_hiho(), 9, OjtPhoneme::new("k".into()), false)]
fn test_ojt_phoneme_equality(
#[case] ojt_phonemes: Vec<OjtPhoneme>,
#[case] index: usize,
Expand Down
37 changes: 17 additions & 20 deletions crates/voicevox_core/src/engine/open_jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,23 @@ pub(crate) mod blocking {
pub fn new(open_jtalk_dict_dir: impl AsRef<Utf8Path>) -> crate::result::Result<Self> {
let dict_dir = open_jtalk_dict_dir.as_ref().to_owned();

// FIXME: この`{}`はGitのdiffを抑えるためだけに存在
{
let mut resources = Resources {
mecab: ManagedResource::initialize(),
njd: ManagedResource::initialize(),
jpcommon: ManagedResource::initialize(),
};

// FIXME: 「システム辞書を読もうとしたけど読めなかった」というエラーをちゃんと用意する
resources
.mecab
.load(&*dict_dir)
.inspect_err(|e| tracing::error!("{e:?}"))
.map_err(|_| ErrorRepr::NotLoadedOpenjtalkDict)?;

Ok(Self(Arc::new(Inner {
resources: Mutex::new(resources),
dict_dir,
})))
}
let mut resources = Resources {
mecab: ManagedResource::initialize(),
njd: ManagedResource::initialize(),
jpcommon: ManagedResource::initialize(),
};

// FIXME: 「システム辞書を読もうとしたけど読めなかった」というエラーをちゃんと用意する
resources
.mecab
.load(&*dict_dir)
.inspect_err(|e| tracing::error!("{e:?}"))
.map_err(|_| ErrorRepr::NotLoadedOpenjtalkDict)?;

Ok(Self(Arc::new(Inner {
resources: Mutex::new(resources),
dict_dir,
})))
}

/// ユーザー辞書を設定する。
Expand Down
4 changes: 0 additions & 4 deletions crates/voicevox_core/src/infer/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,3 @@ pub(crate) trait InferenceDomainMapValues {
impl<T> InferenceDomainMapValues for (T,) {
type Talk = T;
}

impl<A> InferenceDomainMapValues for [A] {
type Talk = A;
}
5 changes: 3 additions & 2 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,9 @@ pub(crate) mod blocking {
OjtPhoneme::convert(
phoneme_str_list
.iter()
.enumerate()
.map(|(i, s)| OjtPhoneme::new(s.as_ref().to_string(), i as f32, i as f32 + 1.))
.map(AsRef::as_ref)
.map(ToOwned::to_owned)
.map(OjtPhoneme::new)
.collect::<Vec<OjtPhoneme>>()
.as_slice(),
)
Expand Down
22 changes: 1 addition & 21 deletions crates/voicevox_core/src/voice_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ pub(crate) mod nonblocking {

#[cfg(test)]
mod tests {
use rstest::{fixture, rstest};
use rstest::rstest;
use serde_json::json;

use crate::{
Expand Down Expand Up @@ -573,26 +573,6 @@ mod tests {
assert_eq!(expected, actual);
}

// FIXME: これ使ってないのでは?
#[fixture]
fn talk_speaker() -> SpeakerMeta {
serde_json::from_value(json!({
"name": "dummy",
"styles": [
{
"id": 0,
"name": "style1",
"type": "talk",
"order": 0
}
],
"version": "0.0.1",
"speaker_uuid": "574bc678-8370-44be-b941-08e46e7b47d7",
"order": 0
}))
.unwrap()
}

fn speaker(style_types: &'static [StyleType]) -> SpeakerMeta {
let styles = style_types
.iter()
Expand Down
3 changes: 2 additions & 1 deletion crates/voicevox_core_c_api/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO: voicevox_onnxruntimeになったらやめる
// TODO: #802 の時点でiOS以外不要になっているはずなので、このbuild.rsは丸ごと消す
// (iOSのためにbuild_util/make_ios_xcframework.bashの修正は必要)
fn main() {
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
Expand Down
22 changes: 8 additions & 14 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ fn init_logger_once() {
&& anstyle_query::windows::enable_ansi_colors().unwrap_or(true)
};

// FIXME: `try_init` → `init` (subscriberは他に存在しないはずなので)
let _ = tracing_subscriber::fmt()
tracing_subscriber::fmt()
.with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() {
EnvFilter::from_default_env()
} else {
Expand All @@ -69,7 +68,7 @@ fn init_logger_once() {
.with_timer(local_time as fn(&mut Writer<'_>) -> _)
.with_ansi(ansi)
.with_writer(out)
.try_init();
.init();
});

fn local_time(wtr: &mut Writer<'_>) -> fmt::Result {
Expand All @@ -83,13 +82,6 @@ fn init_logger_once() {
}
}

/*
* Cの関数として公開するための型や関数を定義するこれらの実装はvoicevox_core/publish.rsに定義してある対応する関数にある
* この関数ではvoicevox_core/publish.rsにある対応する関数の呼び出しと、その戻り値をCの形式に変換する処理のみとする
* これはC文脈の処理と実装をわけるためと、内部実装の変更がAPIに影響を与えにくくするためである
* voicevox_core/publish.rsにある対応する関数とはこのファイルに定義してある公開関数からvoicevoxプレフィックスを取り除いた名前の関数である
*/

// TODO: https://github.com/mozilla/cbindgen/issues/927
//#[cfg(feature = "load-onnxruntime")]
//pub const VOICEVOX_ONNXRUNTIME_LIB_NAME: &CStr = ..;
Expand Down Expand Up @@ -392,10 +384,12 @@ pub extern "C" fn voicevox_get_version() -> *const c_char {
init_logger_once();
return C_STRING_DROP_CHECKER.blacklist(VERSION).as_ptr();

// FIXME: 実行時チェックにすることでこの`unsafe`は削れるはず
const VERSION: &CStr = unsafe {
// SAFETY: The package version is a SemVer, so it should not contain '\0'
CStr::from_bytes_with_nul_unchecked(concat!(env!("CARGO_PKG_VERSION"), '\0').as_bytes())
const VERSION: &CStr = if let Ok(version) =
CStr::from_bytes_with_nul(concat!(env!("CARGO_PKG_VERSION"), '\0').as_bytes())
{
version
} else {
panic!("`$CARGO_PKG_VERSION` should be a SemVer, so it should not contain `\\0`");
};
}

Expand Down
5 changes: 2 additions & 3 deletions crates/voicevox_core_c_api/tests/e2e/snapshots.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ result_messages.22 = "ユーザー辞書に単語が見つかりませんでし
result_messages.23 = "OpenJTalkのユーザー辞書の設定に失敗しました"
result_messages.24 = "ユーザー辞書の単語のバリデーションに失敗しました"
result_messages.25 = "UUIDの変換に失敗しました"
# FIXME: 26, 27, 28が抜けている
result_messages.28 = "モデルの形式が不正です"
result_messages.29 = "推論ライブラリのロードまたは初期化ができませんでした"
stderr = ''

Expand Down Expand Up @@ -174,8 +174,7 @@ stderr.unix = '''
{timestamp} INFO voicevox_core::synthesizer::blocking: CPUを利用します
'''

# FIXME: "user_dict_load"のはず
[user_dict]
[user_dict_load]
stderr.windows = '''
{windows-video-cards}
{timestamp} INFO voicevox_core::synthesizer::blocking: CPUを利用します
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl assert_cdylib::TestCase for TestCase {
}
}

static SNAPSHOTS: LazyLock<Snapshots> = snapshots::section!(user_dict);
static SNAPSHOTS: LazyLock<Snapshots> = snapshots::section!(user_dict_load);

#[derive(Deserialize)]
struct Snapshots {
Expand Down
5 changes: 2 additions & 3 deletions crates/voicevox_core_java_api/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_Dll_00024LoggerInitializer_ini
};
use tracing_subscriber::{fmt::format::Writer, EnvFilter};

// FIXME: `try_init` → `init` (subscriberは他に存在しないはずなので)
let _ = tracing_subscriber::fmt()
tracing_subscriber::fmt()
.with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() {
EnvFilter::from_default_env()
} else {
Expand All @@ -36,7 +35,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_Dll_00024LoggerInitializer_ini
.with_timer(local_time as fn(&mut Writer<'_>) -> _)
.with_ansi(out().is_terminal() && env_allows_ansi())
.with_writer(out)
.try_init();
.init();

fn local_time(wtr: &mut Writer<'_>) -> fmt::Result {
// ローカル時刻で表示はするが、そのフォーマットはtracing-subscriber本来のものに近いようにする。
Expand Down
8 changes: 0 additions & 8 deletions crates/voicevox_core_python_api/python/test/test_nop.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# TODO: voicevox_onnxruntimeになったらやめる
# TODO: ここは #803 の時点でさほど必要性が無くなっているはずなので、(ドキュメントでの案内
# はした上で)やめる
import glob
import platform
from ctypes import CDLL
Expand Down

0 comments on commit d5bce52

Please sign in to comment.