Skip to content

Commit

Permalink
Rust APIのdoctestのボイラープレートをfixtureとして分離 (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip authored Nov 16, 2023
1 parent 68edcc9 commit 8126bbd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 101 deletions.
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/__internal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! VOICEVOX CORE内のラッパー向けの実装
pub mod doctest_fixtures;

// VOICEVOX CORE内のラッパー向けの実装
// FIXME: 要議論: https://github.com/VOICEVOX/voicevox_core/issues/595

pub fn to_zenkaku(surface: &str) -> String {
Expand Down
24 changes: 24 additions & 0 deletions crates/voicevox_core/src/__internal/doctest_fixtures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{path::Path, sync::Arc};

use crate::{AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel};

pub async fn synthesizer_with_sample_voice_model(
open_jtalk_dic_dir: impl AsRef<Path>,
) -> anyhow::Result<Synthesizer> {
let syntesizer = Synthesizer::new(
Arc::new(OpenJtalk::new(open_jtalk_dic_dir).unwrap()),
&InitializeOptions {
acceleration_mode: AccelerationMode::Cpu,
..Default::default()
},
)?;

let model = &VoiceModel::from_path(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../model/sample.vvm",
))
.await?;
syntesizer.load_voice_model(model).await?;

Ok(syntesizer)
}
120 changes: 20 additions & 100 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,15 @@ impl Synthesizer {
#[cfg_attr(not(windows), doc = "```")]
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # let syntesizer = {
/// # use std::sync::Arc;
/// #
/// # use test_util::OPEN_JTALK_DIC_DIR;
/// # use voicevox_core::{
/// # AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel,
/// # };
/// #
/// # let mut syntesizer = Synthesizer::new(
/// # Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap()),
/// # &InitializeOptions {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
/// # "/../../model/sample.vvm",
/// # ))
/// # let synthesizer =
/// # voicevox_core::__internal::doctest_fixtures::synthesizer_with_sample_voice_model(
/// # test_util::OPEN_JTALK_DIC_DIR,
/// # )
/// # .await?;
/// # syntesizer.load_voice_model(model).await?;
/// #
/// # syntesizer
/// # };
/// #
/// use voicevox_core::StyleId;
///
/// let accent_phrases = syntesizer
/// let accent_phrases = synthesizer
/// .create_accent_phrases_from_kana("コンニチワ'", StyleId::new(302))
/// .await?;
/// #
Expand All @@ -304,35 +284,15 @@ impl Synthesizer {
#[cfg_attr(not(windows), doc = "```")]
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # let syntesizer = {
/// # use std::sync::Arc;
/// #
/// # use test_util::OPEN_JTALK_DIC_DIR;
/// # use voicevox_core::{
/// # AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel,
/// # };
/// #
/// # let mut syntesizer = Synthesizer::new(
/// # Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap()),
/// # &InitializeOptions {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
/// # "/../../model/sample.vvm",
/// # ))
/// # let synthesizer =
/// # voicevox_core::__internal::doctest_fixtures::synthesizer_with_sample_voice_model(
/// # test_util::OPEN_JTALK_DIC_DIR,
/// # )
/// # .await?;
/// # syntesizer.load_voice_model(model).await?;
/// #
/// # syntesizer
/// # };
/// #
/// use voicevox_core::StyleId;
///
/// let accent_phrases = syntesizer
/// let accent_phrases = synthesizer
/// .create_accent_phrases("こんにちは", StyleId::new(302))
/// .await?;
/// #
Expand Down Expand Up @@ -393,35 +353,15 @@ impl Synthesizer {
#[cfg_attr(not(windows), doc = "```")]
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # let syntesizer = {
/// # use std::sync::Arc;
/// #
/// # use test_util::OPEN_JTALK_DIC_DIR;
/// # use voicevox_core::{
/// # AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel,
/// # };
/// #
/// # let mut syntesizer = Synthesizer::new(
/// # Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap()),
/// # &InitializeOptions {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
/// # "/../../model/sample.vvm",
/// # ))
/// # let synthesizer =
/// # voicevox_core::__internal::doctest_fixtures::synthesizer_with_sample_voice_model(
/// # test_util::OPEN_JTALK_DIC_DIR,
/// # )
/// # .await?;
/// # syntesizer.load_voice_model(model).await?;
/// #
/// # syntesizer
/// # };
/// #
/// use voicevox_core::StyleId;
///
/// let audio_query = syntesizer
/// let audio_query = synthesizer
/// .audio_query_from_kana("コンニチワ'", StyleId::new(302))
/// .await?;
/// #
Expand All @@ -447,35 +387,15 @@ impl Synthesizer {
#[cfg_attr(not(windows), doc = "```")]
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # let syntesizer = {
/// # use std::sync::Arc;
/// #
/// # use test_util::OPEN_JTALK_DIC_DIR;
/// # use voicevox_core::{
/// # AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel,
/// # };
/// #
/// # let mut syntesizer = Synthesizer::new(
/// # Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap()),
/// # &InitializeOptions {
/// # acceleration_mode: AccelerationMode::Cpu,
/// # ..Default::default()
/// # },
/// # )?;
/// #
/// # let model = &VoiceModel::from_path(concat!(
/// # env!("CARGO_MANIFEST_DIR"),
/// # "/../../model/sample.vvm",
/// # ))
/// # let synthesizer =
/// # voicevox_core::__internal::doctest_fixtures::synthesizer_with_sample_voice_model(
/// # test_util::OPEN_JTALK_DIC_DIR,
/// # )
/// # .await?;
/// # syntesizer.load_voice_model(model).await?;
/// #
/// # syntesizer
/// # };
/// #
/// use voicevox_core::StyleId;
///
/// let audio_query = syntesizer
/// let audio_query = synthesizer
/// .audio_query("こんにちは", StyleId::new(302))
/// .await?;
/// #
Expand Down

0 comments on commit 8126bbd

Please sign in to comment.