Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[project-vvm-async-api] いくつかのC関数を定数にする #503

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 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
8 changes: 8 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 All @@ -41,3 +44,8 @@ test_util.workspace = true
[target."cfg(windows)".dependencies]
humansize = "2.1.2"
windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] }

[build-dependencies]
anyhow.workspace = true
fs-err.workspace = true
quote = { version = "1.0.28", default-features = false }
26 changes: 24 additions & 2 deletions crates/voicevox_core/build.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
// OUT_DIR環境変数はbuild.rsがないと定義されないらしく内部で参照してるOUT_DIRのために残している
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
fn main() {}
use std::{env, path::Path};

use quote::quote;

fn main() -> anyhow::Result<()> {
let out_dir = &env::var("OUT_DIR").unwrap();

fs_err::write(Path::new(out_dir).join("version_macro.rs"), version_macro())?;
Ok(())
}

fn version_macro() -> String {
return quote! {
#[macro_export]
macro_rules! version {
() => {
#VERSION
};
}
}
.to_string();

const VERSION: &str = env!("CARGO_PKG_VERSION");
}
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)]
qryxip marked this conversation as resolved.
Show resolved Hide resolved
#[allow(non_camel_case_types)]
pub enum VoicevoxResultCode {
// C でのenum定義に合わせて大文字で定義している
Expand Down
7 changes: 2 additions & 5 deletions crates/voicevox_core/src/version.rs
qryxip marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
pub const fn get_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
include!(concat!(env!("OUT_DIR"), "/version_macro.rs"));
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

qryxip marked this conversation as resolved.
Show resolved Hide resolved
#[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!());
}
}
39 changes: 27 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(Default, ConstDefault)]
pub struct AccentPhrasesOptions {
pub kana: bool,
}

#[derive(Default)]
#[derive(Default, ConstDefault)]
pub struct AudioQueryOptions {
pub kana: bool,
}
Expand All @@ -49,30 +52,42 @@ 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(Default, ConstDefault)]
pub struct InitializeOptions {
pub acceleration_mode: AccelerationMode,
pub cpu_num_threads: u16,
pub load_all_models: bool,
}

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

Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
/// 音声シンセサイザ
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