-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
現在の`VoiceModel`は、コンストラクトされるときに`id`, `manifest`, `metas`の情報だけ取得してそれらと`path`だけ保持し、モデル本体は要求され てから`path`を開いて読むという形になっている。このような責務になっている ことをユーザーが今のAPIのシグネチャから察するのは困難である。このことか ら、次の変更を行う。 1. `VoiceModel` → `VoiceModelFile`にリネーム * C APIの`voicevox_voice_model_…`は`voicevox_voice_model_file_…`に 2. `VoiceModel::from_path` → `VoiceModelFile::open`にリネーム * C APIも同様 3. Python APIには`__{,a}{enter,exit}__`、Java APIには`Closable`の実装 * `id`と`metas`はクローズ後にもgetできるようにする * Rust APIの`blocking`のものを除き、`.close()`で閉じられるように * C APIの`delete`は`close`にリネーム Python APIとJava APIで`Synthesizer::load_voice_model`中に `VoiceModelFile::close`を行うときの挙動としては、`load_voice_model`がす べて終わるのを待ってからクローズ処理を行う。実装には`RwLock`を用いる。 ```py async with await VoiceModelFile.open(vvm_path) as model: _ = synthesizer.load_voice_model(model) # awaitしない ``` ```console [WARNING] voicevox_core_python_api: The `VoiceModelFile` is still in use. Waiting before closing [DEBUG] voicevox_core_python_api: Closing a VoiceModelFile # `load_voice_model`が無事完了している ``` ただしC APIでは`load_voice_model`中の`close`は現行のままUBとする。 `RwLock`でロックすることで安全なAPIにすることはfuture workとする。 実装の都合上、Python APIの`voicevox_core.asyncio.Synthesizer`も `__{enter,exit}__`ではなく`__a{enter,exit}__`を持つようして、 `VoiceModelFile`同様に`RwLock`でロック管理を行うようにする。 Resolves #829.
- Loading branch information
Showing
52 changed files
with
943 additions
and
372 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::{marker::PhantomData, ops::Deref}; | ||
|
||
use ouroboros::self_referencing; | ||
|
||
pub enum MaybeClosed<T> { | ||
Open(T), | ||
Closed, | ||
} | ||
|
||
// [`mapped_lock_guards`]のようなことをやるためのユーティリティ。 | ||
// | ||
// [`mapped_lock_guards`]: https://github.com/rust-lang/rust/issues/117108 | ||
pub fn try_map_guard<'lock, G, F, T, E>(guard: G, f: F) -> Result<impl Deref<Target = T> + 'lock, E> | ||
where | ||
G: 'lock, | ||
F: FnOnce(&G) -> Result<&T, E>, | ||
T: 'lock, | ||
{ | ||
return MappedLockTryBuilder { | ||
guard, | ||
target_builder: f, | ||
marker: PhantomData, | ||
} | ||
.try_build(); | ||
|
||
#[self_referencing] | ||
struct MappedLock<'lock, G: 'lock, T> { | ||
guard: G, | ||
|
||
#[borrows(guard)] | ||
target: &'this T, | ||
|
||
marker: PhantomData<&'lock T>, | ||
} | ||
|
||
impl<'lock, G: 'lock, T: 'lock> Deref for MappedLock<'lock, G, T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.borrow_target() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.