From d7ddce2c8ff83881eabd2e709c2a62cea3dab387 Mon Sep 17 00:00:00 2001 From: qwerty2501 <939468+qwerty2501@users.noreply.github.com> Date: Tue, 24 Jan 2023 02:32:05 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9E=8B=E3=82=92=E5=88=86=E9=9B=A2=E3=81=97?= =?UTF-8?q?=E3=81=A6=E5=AE=9A=E7=BE=A9=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/devices.rs | 49 +++++++++++ crates/voicevox_core/src/lib.rs | 10 +++ crates/voicevox_core/src/manifest.rs | 15 ++++ crates/voicevox_core/src/metas.rs | 38 +++++++++ crates/voicevox_core/src/publish.rs | 81 +------------------ crates/voicevox_core/src/status.rs | 41 ---------- crates/voicevox_core/src/voice_model.rs | 20 +++++ crates/voicevox_core/src/voice_synthesizer.rs | 23 ++++++ 8 files changed, 156 insertions(+), 121 deletions(-) create mode 100644 crates/voicevox_core/src/devices.rs create mode 100644 crates/voicevox_core/src/manifest.rs create mode 100644 crates/voicevox_core/src/metas.rs create mode 100644 crates/voicevox_core/src/voice_model.rs create mode 100644 crates/voicevox_core/src/voice_synthesizer.rs diff --git a/crates/voicevox_core/src/devices.rs b/crates/voicevox_core/src/devices.rs new file mode 100644 index 000000000..b2e36b568 --- /dev/null +++ b/crates/voicevox_core/src/devices.rs @@ -0,0 +1,49 @@ +use serde::{Deserialize, Serialize}; + +use super::*; + +#[derive(Getters, Debug, Serialize, Deserialize)] +pub struct SupportedDevices { + cpu: bool, + cuda: bool, + dml: bool, +} + +impl SupportedDevices { + /// サポートされているデバイス情報を取得する + pub fn get_supported_devices() -> Result { + let mut cuda_support = false; + let mut dml_support = false; + for provider in onnxruntime::session::get_available_providers() + .map_err(|e| Error::GetSupportedDevices(e.into()))? + .iter() + { + match provider.as_str() { + "CUDAExecutionProvider" => cuda_support = true, + "DmlExecutionProvider" => dml_support = true, + _ => {} + } + } + + Ok(SupportedDevices { + cpu: true, + cuda: cuda_support, + dml: dml_support, + }) + } + + pub fn to_json(&self) -> serde_json::Value { + serde_json::to_value(self).expect("should not fail") + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[rstest] + fn supported_devices_get_supported_devices_works() { + let result = SupportedDevices::get_supported_devices(); + // 環境によって結果が変わるので、関数呼び出しが成功するかどうかの確認のみ行う + assert!(result.is_ok(), "{:?}", result); + } +} diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index 89bd05e52..25c453918 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -1,13 +1,18 @@ #![deny(unsafe_code)] +mod devices; /// cbindgen:ignore mod engine; mod error; +mod manifest; +mod metas; mod numerics; mod publish; mod result; pub mod result_code; mod status; +mod voice_model; +mod voice_synthesizer; pub use self::publish::*; @@ -19,7 +24,12 @@ use self::test_util::*; pub use self::engine::AudioQueryModel; pub use self::error::*; +pub use self::metas::*; pub use self::result::*; +pub use self::voice_model::*; +pub use devices::*; +pub use manifest::*; +pub use voice_synthesizer::*; use derive_getters::*; use derive_new::new; diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs new file mode 100644 index 000000000..5ecf26e02 --- /dev/null +++ b/crates/voicevox_core/src/manifest.rs @@ -0,0 +1,15 @@ +use derive_getters::Getters; +use serde::Deserialize; +use std::path::PathBuf; + +pub type RawManifestVersion = String; +#[derive(Deserialize)] +pub struct ManifestVersion(RawManifestVersion); + +#[derive(Deserialize, Getters)] +pub struct Manifest { + manifest_version: ManifestVersion, + decode_file_path: PathBuf, + predict_duration_file_path: PathBuf, + predict_intonation_file_path: PathBuf, +} diff --git a/crates/voicevox_core/src/metas.rs b/crates/voicevox_core/src/metas.rs new file mode 100644 index 000000000..1ccc8602d --- /dev/null +++ b/crates/voicevox_core/src/metas.rs @@ -0,0 +1,38 @@ +use derive_getters::Getters; +use serde::Deserialize; + +/// スタイルIdの実体 +pub type RawStyleId = usize; +/// スタイルId +#[derive(Deserialize)] +pub struct StyleId(RawStyleId); + +/// スピーカーIdの実体 +pub type RawSpeakerId = usize; + +/// スピーカーId +#[derive(Deserialize)] +pub struct SpeakerId(RawSpeakerId); + +/// 音声合成モデルのメタ情報 +#[derive(Deserialize, Getters)] +pub struct VoiceModelMeta { + speakers: Vec, +} + +/// スピーカーのメタ情報 +#[derive(Deserialize, Getters)] +pub struct SpeakerMeta { + id: SpeakerId, + name: String, + styles: Vec, + version: String, + uuid: String, +} + +/// スタイルのメタ情報 +#[derive(Deserialize, Getters)] +pub struct StyleMeta { + id: StyleId, + name: String, +} diff --git a/crates/voicevox_core/src/publish.rs b/crates/voicevox_core/src/publish.rs index 6d9107d9d..081c7626a 100644 --- a/crates/voicevox_core/src/publish.rs +++ b/crates/voicevox_core/src/publish.rs @@ -7,91 +7,12 @@ use onnxruntime::{ ndarray, session::{AnyArray, NdArray}, }; +use std::ffi::{CStr, CString}; use std::path::PathBuf; use std::sync::Mutex; -use std::{ - ffi::{CStr, CString}, - path::Path, -}; const PHONEME_LENGTH_MINIMAL: f32 = 0.01; -/// 音声合成モデルIdの実体 -pub type RawVoiceModelId = usize; - -/// 音声合成モデルId (型を強く分けるためにこうしている) -pub struct VoiceModelId(RawVoiceModelId); - -/// 音声合成モデル -pub struct VoiceModel {} - -/// 音声合成モデルのメタ情報 -pub struct VoiceModelMeta { - id: VoiceModelId, - speakers: Vec, -} - -/// スピーカーのメタ情報 -pub struct SpeakerMeta { - id: SpeakerId, - name: String, - styles: Vec, - version: String, - uuid: String, -} - -pub struct StyleMeta { - id: StyleId, - name: String, -} - -impl VoiceModel { - /// 与えられたパスからモデルを取得する - pub fn from_path(path: impl AsRef) -> Result {} - /// ランダムに発行されたこのモデルのIdを返す - pub fn id(&self) -> &VoiceModelId {} - /// このモデルのメタ情報を返す - pub fn metas(&self) -> &VoiceModelMeta {} -} - -/// スタイルIdの実体 -pub type RawStyleId = usize; -/// スタイルId -pub struct StyleId(RawStyleId); - -/// スピーカーIdの実体 -pub type RawSpeakerId = usize; - -/// スピーカーId -pub struct SpeakerId(RawSpeakerId); - -/// 音声シンセサイザ -pub struct VoiceSynthesizer {} -impl VoiceSynthesizer { - /// コンストラクタ兼初期化 - pub fn new_with_initialize(options: InitializeOptions) -> Self {} - - /// 音声合成モデルを読み込む - pub fn load_model(&mut self, model: VoiceModel) -> Result<()> {} - - /// 指定したモデルIdの音声合成モデルを開放する - pub fn unload_model(&mut self, model_id: VoiceModelId) -> Result<()> {} - - /// 指定したモデルIdの音声合成モデルが読み込まれているか判定する - pub fn is_loaded_model(&self, model_id: VoiceModelId) -> bool {} - - /// 今読み込んでいる音声合成モデルのメタ情報を返す - pub fn metas(&self) -> &VoiceModelMeta {} - - /// 音声合成を行う - pub fn synthesis(&self, style_id: &StyleId) -> Result> {} -} - -pub struct Device {} - -/// サポートされているデバイス情報を取得する -pub fn get_supported_devices() -> Result {} - pub struct VoicevoxCore { synthesis_engine: SynthesisEngine, use_gpu: bool, diff --git a/crates/voicevox_core/src/status.rs b/crates/voicevox_core/src/status.rs index 16a717904..ef5d098e4 100644 --- a/crates/voicevox_core/src/status.rs +++ b/crates/voicevox_core/src/status.rs @@ -165,40 +165,6 @@ static ENVIRONMENT: Lazy = Lazy::new(|| { .unwrap() }); -#[derive(Getters, Debug, Serialize, Deserialize)] -pub struct SupportedDevices { - cpu: bool, - cuda: bool, - dml: bool, -} - -impl SupportedDevices { - pub fn get_supported_devices() -> Result { - let mut cuda_support = false; - let mut dml_support = false; - for provider in onnxruntime::session::get_available_providers() - .map_err(|e| Error::GetSupportedDevices(e.into()))? - .iter() - { - match provider.as_str() { - "CUDAExecutionProvider" => cuda_support = true, - "DmlExecutionProvider" => dml_support = true, - _ => {} - } - } - - Ok(SupportedDevices { - cpu: true, - cuda: cuda_support, - dml: dml_support, - }) - } - - pub fn to_json(&self) -> serde_json::Value { - serde_json::to_value(self).expect("should not fail") - } -} - #[allow(unsafe_code)] unsafe impl Send for Status {} @@ -396,13 +362,6 @@ mod tests { assert_eq!(expected, status.supported_styles); } - #[rstest] - fn supported_devices_get_supported_devices_works() { - let result = SupportedDevices::get_supported_devices(); - // 環境によって結果が変わるので、関数呼び出しが成功するかどうかの確認のみ行う - assert!(result.is_ok(), "{:?}", result); - } - #[rstest] fn status_load_model_works() { let mut status = Status::new(false, 0); diff --git a/crates/voicevox_core/src/voice_model.rs b/crates/voicevox_core/src/voice_model.rs new file mode 100644 index 000000000..aa17d798a --- /dev/null +++ b/crates/voicevox_core/src/voice_model.rs @@ -0,0 +1,20 @@ +use super::*; +use std::path::Path; + +/// 音声合成モデルIdの実体 +pub type RawVoiceModelId = usize; + +/// 音声合成モデルId (型を強く分けるためにこうしている) +pub struct VoiceModelId(RawVoiceModelId); + +/// 音声合成モデル +pub struct VoiceModel {} + +impl VoiceModel { + /// 与えられたパスからモデルを取得する + pub fn from_path(path: impl AsRef) -> Result {} + /// ランダムに発行されたこのモデルのIdを返す + pub fn id(&self) -> &VoiceModelId {} + /// このモデルのメタ情報を返す + pub fn metas(&self) -> &VoiceModelMeta {} +} diff --git a/crates/voicevox_core/src/voice_synthesizer.rs b/crates/voicevox_core/src/voice_synthesizer.rs new file mode 100644 index 000000000..068c5abd2 --- /dev/null +++ b/crates/voicevox_core/src/voice_synthesizer.rs @@ -0,0 +1,23 @@ +use super::*; + +/// 音声シンセサイザ +pub struct VoiceSynthesizer {} +impl VoiceSynthesizer { + /// コンストラクタ兼初期化 + pub fn new_with_initialize(options: InitializeOptions) -> Self {} + + /// 音声合成モデルを読み込む + pub fn load_model(&mut self, model: VoiceModel) -> Result<()> {} + + /// 指定したモデルIdの音声合成モデルを開放する + pub fn unload_model(&mut self, model_id: VoiceModelId) -> Result<()> {} + + /// 指定したモデルIdの音声合成モデルが読み込まれているか判定する + pub fn is_loaded_model(&self, model_id: VoiceModelId) -> bool {} + + /// 今読み込んでいる音声合成モデルのメタ情報を返す + pub fn metas(&self) -> &VoiceModelMeta {} + + /// 音声合成を行う + pub fn synthesis(&self, style_id: &StyleId) -> Result> {} +}