Skip to content

Commit

Permalink
[project-vvm-async-api] いくつかのC関数を定数にする (#503)
Browse files Browse the repository at this point in the history
* `voicevox_get_version()` → `voicevox_version`

* indocを外す

* コメントを更新

* テスト`global_info`を追加

* `make_default_`系を定数に

* Minor refactor

* diffを減らすためにquoteをダウングレード

* Minor refactor

* Minor refactor

* `SupportedDevices`の中身も確認する

* Minor refactor

* `version!()` → `VERSION`

* `Default`のimplはマクロ側に寄せる

* `voicevox_create_supported_devices_json`のシグネチャを直す
  • Loading branch information
qryxip authored Jun 7, 2023
1 parent 38549d3 commit f4b502a
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 176 deletions.
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ publish = false
[workspace.dependencies]
anyhow = "1.0.65"
clap = { version = "4.0.10", features = ["derive"] }
const-default = { version = "1.0.0", features = ["derive"] }
easy-ext = "1.0.1"
fs-err = { version = "2.9.0", features = ["tokio"] }
once_cell = "1.15.0"
Expand All @@ -24,6 +25,7 @@ process_path = { git = "https://github.com/VOICEVOX/process_path.git", rev = "de
regex = "1.6.0"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = { version = "1.0.85", features = ["preserve_order"] }
strum = { version = "0.24.1", features = ["derive"] }
test_util = { path = "crates/test_util" }
thiserror = "1.0.37"
tracing = { version = "0.1.37", features = ["log"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ once_cell.workspace = true
platforms = "3.0.2"
rayon = "1.6.1"
reqwest = { version = "0.11.13", default-features = false, features = ["rustls-tls", "stream"] }
strum = { version = "0.24.1", features = ["derive"] }
strum.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ directml = ["onnxruntime/directml"]
[dependencies]
anyhow.workspace = true
cfg-if = "1.0.0"
const-default.workspace = true
derive-getters.workspace = true
derive-new = "0.5.9"
duplicate = "1.0.0"
easy-ext.workspace = true
fs-err.workspace = true
once_cell.workspace = true
onnxruntime = { git = "https://github.com/VOICEVOX/onnxruntime-rs.git", rev="ebb9dcb9b26ee681889b52b6db3b4f642b04a250" }
process_path.workspace = true
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
thiserror.workspace = true
tracing.workspace = true
open_jtalk = { git = "https://github.com/VOICEVOX/open_jtalk-rs.git", rev="d766a52bad4ccafe18597e57bd6842f59dca881e" }
Expand Down
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/result_code.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use strum::EnumIter;

/// 処理結果を示す結果コード
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
#[allow(non_camel_case_types)]
pub enum VoicevoxResultCode {
// C でのenum定義に合わせて大文字で定義している
Expand Down
10 changes: 6 additions & 4 deletions crates/voicevox_core/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pub const fn get_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
/// 本クレートの`package.version`。
///
/// C APIやPython API側からこの値が使われるべきではない。
/// 現在はまだRust APIを外部提供していないため、この定数はどこからも参照されていないはずである。
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(test)]
mod tests {
use super::*;
use crate::*;
#[rstest]
fn get_version_works() {
assert_eq!("0.0.0", get_version());
assert_eq!("0.0.0", VERSION);
}
}
42 changes: 30 additions & 12 deletions crates/voicevox_core/src/voice_synthesizer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::sync::Arc;

use const_default::ConstDefault;
use duplicate::duplicate_item;

use crate::engine::{create_kana, parse_kana, AccentPhraseModel, OpenJtalk, SynthesisEngine};

use super::*;
Expand All @@ -22,12 +25,12 @@ impl From<&TtsOptions> for SynthesisOptions {
}
}

#[derive(Default)]
#[derive(ConstDefault)]
pub struct AccentPhrasesOptions {
pub kana: bool,
}

#[derive(Default)]
#[derive(ConstDefault)]
pub struct AudioQueryOptions {
pub kana: bool,
}
Expand All @@ -49,30 +52,45 @@ impl AsRef<TtsOptions> for TtsOptions {
}
}

impl Default for TtsOptions {
fn default() -> Self {
Self {
enable_interrogative_upspeak: true,
kana: Default::default(),
}
}
impl ConstDefault for TtsOptions {
const DEFAULT: Self = Self {
enable_interrogative_upspeak: true,
kana: ConstDefault::DEFAULT,
};
}

#[derive(Default, Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub enum AccelerationMode {
#[default]
Auto,
Cpu,
Gpu,
}

#[derive(Default)]
impl ConstDefault for AccelerationMode {
const DEFAULT: Self = Self::Auto;
}

#[derive(ConstDefault)]
pub struct InitializeOptions {
pub acceleration_mode: AccelerationMode,
pub cpu_num_threads: u16,
pub load_all_models: bool,
}

#[duplicate_item(
T;
[ AccentPhrasesOptions ];
[ AudioQueryOptions ];
[ TtsOptions ];
[ AccelerationMode ];
[ InitializeOptions ];
)]
impl Default for T {
fn default() -> Self {
Self::DEFAULT
}
}

/// 音声シンセサイザ
pub struct Synthesizer {
synthesis_engine: SynthesisEngine,
Expand Down
2 changes: 2 additions & 0 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ directml = ["voicevox_core/directml"]
[dependencies]
voicevox_core.workspace = true
chrono = { version = "0.4.23", default-features = false, features = ["clock"] } # https://github.com/chronotope/chrono/issues/602
const-default.workspace = true
is-terminal = "0.4.2"
libc = "0.2.134"
once_cell.workspace = true
Expand All @@ -42,6 +43,7 @@ ndarray-stats = "0.5.1"
process_path.workspace = true
regex.workspace = true
serde.workspace = true
strum.workspace = true
test_util.workspace = true
toml = "0.7.2"
typetag = "0.2.5"
Expand Down
Loading

0 comments on commit f4b502a

Please sign in to comment.