From 3aade90d106f38b4912a8e33c95f36db59d1aba9 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 24 Jan 2025 03:28:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20`VoiceModelFile::close`=E5=BE=8C?= =?UTF-8?q?=E3=82=82`id`=E3=81=A8`metas`=E3=81=B8=E3=81=AE=E3=82=A2?= =?UTF-8?q?=E3=82=AF=E3=82=BB=E3=82=B9=E3=82=92=E4=BF=9D=E8=A8=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/voice_model.rs | 12 ++++++++++-- crates/voicevox_core_c_api/src/lib.rs | 17 +++++++++++++++-- .../voicevoxcore/blocking/VoiceModelFile.java | 12 ++++++++++-- .../python/voicevox_core/_rust/asyncio.pyi | 8 +++++++- .../python/voicevox_core/_rust/blocking.pyi | 8 +++++++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/crates/voicevox_core/src/voice_model.rs b/crates/voicevox_core/src/voice_model.rs index c17d49e8c..e2fdd4fba 100644 --- a/crates/voicevox_core/src/voice_model.rs +++ b/crates/voicevox_core/src/voice_model.rs @@ -611,6 +611,12 @@ pub(crate) mod blocking { Inner::open(path).block_on().map(Self) } + /// VVMファイルを閉じる。 + pub fn close(self) -> (VoiceModelId, VoiceModelMeta) { + let heads = self.0.into_heads(); + (*heads.header.manifest.id(), heads.header.metas.clone()) + } + pub(crate) fn inner(&self) -> &Inner { &self.0 } @@ -653,8 +659,10 @@ pub(crate) mod nonblocking { } /// VVMファイルを閉じる。 - pub async fn close(self) { - self.0.into_heads().zip.into_inner().close().await; + pub async fn close(self) -> (VoiceModelId, VoiceModelMeta) { + let heads = self.0.into_heads(); + heads.zip.into_inner().close().await; + (*heads.header.manifest.id(), heads.header.metas.clone()) } pub(crate) fn inner(&self) -> &Inner { diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 2a284a938..2e237cf2b 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -497,15 +497,28 @@ pub extern "C" fn voicevox_voice_model_file_create_metas_json( // TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える // SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない -/// ::VoicevoxVoiceModelFile を、所有しているファイルディスクリプタを閉じた上で破棄(_destruct_)する。 +/// ::VoicevoxVoiceModelFile が所有しているファイルディスクリプタを閉じる。 /// /// 破棄対象への他スレッドでのアクセスが存在する場合、それらがすべて終わるのを待ってから破棄する。 /// /// この関数の呼び出し後に破棄し終えた対象にアクセスすると、プロセスを異常終了する。 /// -/// @param [in] model 破棄対象 +/// @param [in] model 対象 #[no_mangle] pub extern "C" fn voicevox_voice_model_file_close(model: *mut VoicevoxVoiceModelFile) { + init_logger_once(); + todo!(); +} + +// TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える +// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない +/// ::VoicevoxVoiceModelFile を、所有しているファイルディスクリプタを閉じた上で破棄(_destruct_)する。 +/// +/// 破棄対象への他スレッドでのアクセスが存在する場合、それらがすべて終わるのを待ってから破棄する。 +/// +/// @param [in] model 破棄対象 +#[no_mangle] +pub extern "C" fn voicevox_voice_model_file_delete(model: *mut VoicevoxVoiceModelFile) { init_logger_once(); model.drop_body(); } diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java index 4c1c265b2..15410f7d6 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java @@ -15,10 +15,18 @@ public class VoiceModelFile implements Closeable { private long handle; - /** ID。 */ + /** + * ID。 + * + *

{@link #close}の後でも利用可能。 + */ @Nonnull public final UUID id; - /** メタ情報。 */ + /** + * メタ情報。 + * + *

{@link #close}の後でも利用可能。 + */ @Nonnull public final SpeakerMeta[] metas; public VoiceModelFile(String modelPath) { diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi index bdee4e1ee..7ae067119 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi @@ -39,7 +39,11 @@ class VoiceModelFile: ... @property def id(self) -> VoiceModelId: - """ID。""" + """ + ID。 + + :attr:`close` および :attr:`__aexit__` の後でも利用可能。 + """ ... @property def metas(self) -> list[SpeakerMeta]: @@ -47,6 +51,8 @@ class VoiceModelFile: メタ情報。 この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。 + + :attr:`close` および :attr:`__aexit__` の後でも利用可能。 """ ... async def __aenter__(self) -> "VoiceModelFile": ... diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi index 58851e40a..d2719e7d1 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi @@ -39,7 +39,11 @@ class VoiceModelFile: ... @property def id(self) -> VoiceModelId: - """ID。""" + """ + ID。 + + :attr:`close` および :attr:`__exit__` の後でも利用可能。 + """ ... @property def metas(self) -> list[SpeakerMeta]: @@ -47,6 +51,8 @@ class VoiceModelFile: メタ情報。 この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。 + + :attr:`close` および :attr:`__exit__` の後でも利用可能。 """ ... def __enter__(self) -> "VoiceModelFile": ...