Skip to content

Commit

Permalink
"join"しない
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Sep 10, 2024
1 parent 125ae3b commit e84fed7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 50 deletions.
9 changes: 0 additions & 9 deletions crates/voicevox_core/src/infer/domains.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod talk;

use std::future::Future;

use educe::Educe;
use serde::{Deserialize, Deserializer};

Expand Down Expand Up @@ -40,13 +38,6 @@ impl<T, E> InferenceDomainMap<(Result<T, E>,)> {
}
}

impl<T: Future> InferenceDomainMap<(T,)> {
pub(crate) async fn join_all(self) -> InferenceDomainMap<(T::Output,)> {
let talk = self.talk.await;
InferenceDomainMap { talk }
}
}

impl<'de, V: InferenceDomainMapValues + ?Sized> Deserialize<'de> for InferenceDomainMap<V>
where
V::Talk: Deserialize<'de>,
Expand Down
73 changes: 32 additions & 41 deletions crates/voicevox_core/src/voice_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use easy_ext::ext;
use enum_map::enum_map;
use enum_map::EnumMap;
use futures_io::{AsyncBufRead, AsyncSeek};
use futures_util::future::{FutureExt as _, OptionFuture, TryFutureExt as _};
use futures_util::future::{OptionFuture, TryFutureExt as _};
use itertools::Itertools as _;
use ouroboros::self_referencing;
use serde::Deserialize;
Expand Down Expand Up @@ -208,47 +208,39 @@ impl<A: Async> Inner<A> {
}};
}

self.with_inference_model_entries(|inference_model_entries| {
inference_model_entries
.each_ref()
.map(InferenceDomainMap {
let InferenceDomainMap { talk } =
self.with_inference_model_entries(|inference_model_entries| {
inference_model_entries.each_ref().map(InferenceDomainMap {
talk: |talk| {
let talk =
talk.as_ref()
.map(|InferenceModelEntry { indices, manifest }| {
(
indices.map(|op, i| (i, manifest[op].clone())),
manifest.style_id_to_inner_voice_id.clone(),
)
});
async {
OptionFuture::from(talk.map(
|(entries, style_id_to_inner_voice_id)| async {
let [predict_duration, predict_intonation, decode] =
entries.into_array();

let predict_duration = read_file!(predict_duration);
let predict_intonation = read_file!(predict_intonation);
let decode = read_file!(decode);

let model_bytes = EnumMap::from_array([
predict_duration,
predict_intonation,
decode,
]);

Ok((style_id_to_inner_voice_id, model_bytes))
},
))
.await
.transpose()
}
talk.as_ref()
.map(|InferenceModelEntry { indices, manifest }| {
(
indices.map(|op, i| (i, manifest[op].clone())),
manifest.style_id_to_inner_voice_id.clone(),
)
})
},
})
.join_all()
.map(InferenceDomainMap::collect)
})
});

let talk = OptionFuture::from(talk.map(
|(entries, style_id_to_inner_voice_id)| async move {
let [predict_duration, predict_intonation, decode] = entries.into_array();

let predict_duration = read_file!(predict_duration);
let predict_intonation = read_file!(predict_intonation);
let decode = read_file!(decode);

let model_bytes =
EnumMap::from_array([predict_duration, predict_intonation, decode]);

Ok((style_id_to_inner_voice_id, model_bytes))
},
))
.await
.transpose()?;

Ok(InferenceDomainMap { talk })
}
}

Expand All @@ -264,9 +256,8 @@ struct InferenceModelEntry<D: InferenceDomain, M> {
impl<A: Async> A {
async fn open_zip(
path: &Path,
) -> anyhow::Result<
async_zip::base::read::seek::ZipFileReader<impl AsyncBufRead + AsyncSeek + '_>,
> {
) -> anyhow::Result<async_zip::base::read::seek::ZipFileReader<impl AsyncBufRead + AsyncSeek>>
{
let zip = Self::open_file(path).await.with_context(|| {
// fs-errのと同じにする
format!("failed to open file `{}`", path.display())
Expand Down

0 comments on commit e84fed7

Please sign in to comment.