Skip to content

Commit

Permalink
Merge branch 'VOICEVOX:main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna2134 authored Nov 13, 2023
2 parents e3a6a01 + 4c4b767 commit 88d3565
Show file tree
Hide file tree
Showing 29 changed files with 845 additions and 79 deletions.
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/engine/synthesis_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ mod tests {
#[rstest]
#[tokio::test]
async fn is_openjtalk_dict_loaded_works() {
let core = InferenceCore::new(false, 0).await.unwrap();
let core = InferenceCore::new(false, 0).unwrap();
let synthesis_engine =
SynthesisEngine::new(core, OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap().into());

Expand All @@ -662,7 +662,7 @@ mod tests {
#[rstest]
#[tokio::test]
async fn create_accent_phrases_works() {
let core = InferenceCore::new(false, 0).await.unwrap();
let core = InferenceCore::new(false, 0).unwrap();

let model = &VoiceModel::sample().await.unwrap();
core.load_model(model).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/inference_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct InferenceCore {
}

impl InferenceCore {
pub(crate) async fn new(use_gpu: bool, cpu_num_threads: u16) -> Result<Self> {
pub(crate) fn new(use_gpu: bool, cpu_num_threads: u16) -> Result<Self> {
if !use_gpu || Self::can_support_gpu_feature()? {
let status = Status::new(use_gpu, cpu_num_threads);
Ok(Self { status })
Expand Down
33 changes: 8 additions & 25 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ impl Synthesizer {
///
#[cfg_attr(windows, doc = "```no_run")] // https://github.com/VOICEVOX/voicevox_core/issues/537
#[cfg_attr(not(windows), doc = "```")]
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # fn main() -> anyhow::Result<()> {
/// # use test_util::OPEN_JTALK_DIC_DIR;
/// #
/// # const ACCELERATION_MODE: AccelerationMode = AccelerationMode::Cpu;
Expand All @@ -96,13 +95,12 @@ impl Synthesizer {
/// acceleration_mode: ACCELERATION_MODE,
/// ..Default::default()
/// },
/// )
/// .await?;
/// )?;
/// #
/// # Ok(())
/// # }
/// ```
pub async fn new(open_jtalk: Arc<OpenJtalk>, options: &InitializeOptions) -> Result<Self> {
pub fn new(open_jtalk: Arc<OpenJtalk>, options: &InitializeOptions) -> Result<Self> {
#[cfg(windows)]
list_windows_video_cards();
let use_gpu = match options.acceleration_mode {
Expand All @@ -124,7 +122,7 @@ impl Synthesizer {

Ok(Self {
synthesis_engine: SynthesisEngine::new(
InferenceCore::new(use_gpu, options.cpu_num_threads).await?,
InferenceCore::new(use_gpu, options.cpu_num_threads)?,
open_jtalk,
),
use_gpu,
Expand Down Expand Up @@ -259,8 +257,7 @@ impl Synthesizer {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )
/// # .await?;
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
Expand Down Expand Up @@ -313,8 +310,7 @@ impl Synthesizer {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )
/// # .await?;
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
Expand Down Expand Up @@ -403,8 +399,7 @@ impl Synthesizer {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )
/// # .await?;
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
Expand Down Expand Up @@ -458,8 +453,7 @@ impl Synthesizer {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )
/// # .await?;
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
Expand Down Expand Up @@ -586,7 +580,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let result = syntesizer
Expand All @@ -610,7 +603,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();
assert!(!syntesizer.is_gpu_mode());
}
Expand All @@ -627,7 +619,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();
assert!(
!syntesizer.is_loaded_model_by_style_id(style_id),
Expand Down Expand Up @@ -656,7 +647,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

syntesizer
Expand Down Expand Up @@ -688,7 +678,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();
syntesizer
.load_voice_model(&open_default_vvm_file().await)
Expand Down Expand Up @@ -730,7 +719,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();
syntesizer
.load_voice_model(&open_default_vvm_file().await)
Expand Down Expand Up @@ -823,7 +811,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let model = &VoiceModel::sample().await.unwrap();
Expand Down Expand Up @@ -892,7 +879,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let model = &VoiceModel::sample().await.unwrap();
Expand Down Expand Up @@ -958,7 +944,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let model = &VoiceModel::sample().await.unwrap();
Expand Down Expand Up @@ -995,7 +980,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let model = &VoiceModel::sample().await.unwrap();
Expand Down Expand Up @@ -1028,7 +1012,6 @@ mod tests {
..Default::default()
},
)
.await
.unwrap();

let model = &VoiceModel::sample().await.unwrap();
Expand Down
8 changes: 6 additions & 2 deletions crates/voicevox_core_c_api/src/c_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ impl OpenJtalkRc {
}

impl VoicevoxSynthesizer {
pub(crate) async fn new(open_jtalk: &OpenJtalkRc, options: &InitializeOptions) -> Result<Self> {
let synthesizer = Synthesizer::new(open_jtalk.open_jtalk.clone(), options).await?;
pub(crate) fn new(open_jtalk: &OpenJtalkRc, options: &InitializeOptions) -> Result<Self> {
// ロガーを起動
// FIXME: `into_result_code_with_error`を`run`とかに改名し、`init_logger`をその中に移動
let _ = *crate::RUNTIME;

let synthesizer = Synthesizer::new(open_jtalk.open_jtalk.clone(), options)?;
Ok(Self { synthesizer })
}

Expand Down
3 changes: 1 addition & 2 deletions crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ pub extern "C" fn initialize(use_gpu: bool, cpu_num_threads: c_int, load_all_mod
},
cpu_num_threads: cpu_num_threads as u16,
},
)
.await?;
)?;

if load_all_models {
for model in &voice_model_set().all_vvms {
Expand Down
4 changes: 1 addition & 3 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_new(
into_result_code_with_error((|| {
let options = options.into();

let synthesizer = RUNTIME
.block_on(VoicevoxSynthesizer::new(open_jtalk, &options))?
.into();
let synthesizer = VoicevoxSynthesizer::new(open_jtalk, &options)?.into();
out_synthesizer.as_ptr().write_unaligned(synthesizer);
Ok(())
})())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package jp.hiroshiba.voicevoxcore;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import jakarta.annotation.Nonnull;

/** VOICEVOX CORE自体の情報。 */
public class GlobalInfo extends Dll {
/**
* ライブラリのバージョン。
*
* @return ライブラリのバージョン。
*/
@Nonnull
public static String getVersion() {
return rsGetVersion();
}

/**
* このライブラリで利用可能なデバイスの情報を取得する。
*
* @return {@link SupportedDevices}。
*/
@Nonnull
public static SupportedDevices getSupportedDevices() {
Gson gson = new Gson();
String supportedDevicesJson = rsGetSupportedDevicesJson();
SupportedDevices supportedDevices = gson.fromJson(supportedDevicesJson, SupportedDevices.class);
if (supportedDevices == null) {
throw new NullPointerException("supported_devices");
}
return supportedDevices;
}

@Nonnull
private static native String rsGetVersion();

@Nonnull
private static native String rsGetSupportedDevicesJson();

/**
* このライブラリで利用可能なデバイスの情報。
*
* <p>あくまで本ライブラリが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったとしても {@link #cuda} や {@link #dml} は {@code
* true} を示しうる。
*/
public static class SupportedDevices {
/**
* CPUが利用可能。
*
* <p>常に <code>true</code> 。
*/
@SerializedName("cpu")
@Expose
@Nonnull
public final boolean cpu;

/**
* CUDAが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html"
* target="_blank">CUDAExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("cuda")
@Expose
@Nonnull
public final boolean cuda;

/**
* DirectMLが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html"
* target="_blank">DmlExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("dml")
@Expose
@Nonnull
public final boolean dml;

private SupportedDevices() {
this.cpu = false;
this.cuda = false;
this.dml = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.hiroshiba.voicevoxcore;

/** テキスト解析機としてのOpen JTalk。 */
public class OpenJtalk extends Dll {
private long handle;

Expand Down
Loading

0 comments on commit 88d3565

Please sign in to comment.