diff --git a/sbv2_bindings/examples/basic.py b/sbv2_bindings/examples/basic.py index 8d9b8dd..389ae0d 100644 --- a/sbv2_bindings/examples/basic.py +++ b/sbv2_bindings/examples/basic.py @@ -11,9 +11,7 @@ def main(): style_vector = model.get_style_vector("amitaro", 0, 1.0) with open("output.wav", "wb") as f: - data = model.synthesize("こんにちは", "amitaro", style_vector, 0.0, 0.5) - print(data) - f.write(data) + f.write(model.synthesize("おはようございます。", "amitaro", style_vector, 0.0, 0.5)) if __name__ == "__main__": diff --git a/sbv2_bindings/src/lib.rs b/sbv2_bindings/src/lib.rs index cd0bd9a..59dace9 100644 --- a/sbv2_bindings/src/lib.rs +++ b/sbv2_bindings/src/lib.rs @@ -2,16 +2,10 @@ use pyo3::prelude::*; mod sbv2; pub mod style; -/// Formats the sum of two numbers as string. -#[pyfunction] -fn sum_as_string(a: usize, b: usize) -> PyResult { - Ok((a + b).to_string()) -} - -/// A Python module implemented in Rust. +/// sbv2 bindings module #[pymodule] fn sbv2_bindings(m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; m.add_class::()?; + m.add_class::()?; Ok(()) } diff --git a/sbv2_bindings/src/sbv2.rs b/sbv2_bindings/src/sbv2.rs index b8d47c5..be670e6 100644 --- a/sbv2_bindings/src/sbv2.rs +++ b/sbv2_bindings/src/sbv2.rs @@ -6,6 +6,16 @@ use crate::style::StyleVector; use std::fs; +/// TTSModel class +/// +/// 音声合成するために使うクラス +/// +/// Parameters +/// ---------- +/// bert_model_bytes : bytes +/// BERTモデルのバイナリデータ +/// tokenizer_bytes : bytes +/// トークナイザーのバイナリデータ #[pyclass] pub struct TTSModel { pub model: TTSModelHolder, @@ -20,26 +30,66 @@ impl TTSModel { }) } + /// パスからTTSModelインスタンスを生成する + /// + /// Parameters + /// ---------- + /// bert_model_path : str + /// BERTモデルのパス + /// tokenizer_path : str + /// トークナイザーのパス #[staticmethod] fn from_path(bert_model_path: String, tokenizer_path: String) -> anyhow::Result { Ok(Self { - model: TTSModelHolder::new( - fs::read(bert_model_path)?, - fs::read(tokenizer_path)?, - )?, + model: TTSModelHolder::new(fs::read(bert_model_path)?, fs::read(tokenizer_path)?)?, }) } + /// SBV2ファイルを読み込む + /// + /// Parameters + /// ---------- + /// ident : str + /// 識別子 + /// sbv2file_bytes : bytes + /// SBV2ファイルのバイナリデータ fn load_sbv2file(&mut self, ident: String, sbv2file_bytes: Vec) -> anyhow::Result<()> { self.model.load_sbv2file(ident, sbv2file_bytes)?; Ok(()) } - fn load_sbv2file_from_path(&mut self, ident: String, sbv2file_path: String) -> anyhow::Result<()> { + /// パスからSBV2ファイルを読み込む + /// + /// Parameters + /// ---------- + /// ident : str + /// 識別子 + /// sbv2file_path : str + /// SBV2ファイルのパス + fn load_sbv2file_from_path( + &mut self, + ident: String, + sbv2file_path: String, + ) -> anyhow::Result<()> { self.model.load_sbv2file(ident, fs::read(sbv2file_path)?)?; Ok(()) } + /// スタイルベクトルを取得する + /// + /// Parameters + /// ---------- + /// ident : str + /// 識別子 + /// style_id : int + /// スタイルID + /// weight : float + /// 重み + /// + /// Returns + /// ------- + /// style_vector : StyleVector + /// スタイルベクトル fn get_style_vector( &self, ident: String, @@ -51,6 +101,25 @@ impl TTSModel { )) } + /// テキストから音声を合成する + /// + /// Parameters + /// ---------- + /// text : str + /// テキスト + /// ident : str + /// 識別子 + /// style_vector : StyleVector + /// スタイルベクトル + /// sdp_ratio : float + /// SDP比率 + /// length_scale : float + /// 音声の長さのスケール + /// + /// Returns + /// ------- + /// voice_data : bytes + /// 音声データ fn synthesize<'p>( &'p self, py: Python<'p>, diff --git a/sbv2_bindings/src/style.rs b/sbv2_bindings/src/style.rs index 56a8256..3360133 100644 --- a/sbv2_bindings/src/style.rs +++ b/sbv2_bindings/src/style.rs @@ -1,6 +1,9 @@ use ndarray::Array1; use pyo3::prelude::*; +/// StyleVector class +/// +/// スタイルベクトルを表すクラス #[pyclass] #[derive(Clone)] pub struct StyleVector(Array1);