diff --git a/Cargo.toml b/Cargo.toml index cf6ff60..7f6d6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,9 @@ edition = "2021" [dependencies] bytes = "1.4.0" -reqwest = { version = "0.11.16", features = ["json"] } +reqwest = { version = "0.11.16", default-features = false, features = ["json", "rustls"] } serde = { version = "1.0.159", features = ["derive"] } +serde_json = "1.0.95" + +[dev-dependencies] +tokio = { version = "1.27.0", features = ["full"] } diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce93d93 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Rust + +## Example +```rust +use voicevox_client::Client; + + +#[tokio::main] +async fn main() { + let client = Client::new("http://localhost:50021".to_string()); + let audio_query = client.create_audio_query("hello", 1) + .await + .unwrap(); + let bytes = audio_query.synthesis(1) + .await + .unwrap(); +} +``` \ No newline at end of file diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..607eea3 --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,12 @@ +use voicevox_client::Client; + +#[tokio::main] +async fn main() { + let client = Client::new("http://localhost:50021".to_string()); + let audio_query = client + .create_audio_query("こんにちは", 1, None) + .await + .unwrap(); + let audio = audio_query.synthesis(1).await.unwrap(); + println!("audio: {:?}", audio); +} \ No newline at end of file diff --git a/src/audio_query.rs b/src/audio_query.rs index 0f43b7e..2cfb42b 100644 --- a/src/audio_query.rs +++ b/src/audio_query.rs @@ -16,7 +16,10 @@ impl AudioQuery { } pub async fn synthesis(&self, speaker: i32) -> Result { - let data = self.restapi.synthesis(&self.audio_query, speaker.to_string().as_str()).await?; + let data = self + .restapi + .synthesis(&self.audio_query, speaker.to_string().as_str()) + .await?; Ok(data) } } diff --git a/src/client.rs b/src/client.rs index 2f805fd..fcdc918 100644 --- a/src/client.rs +++ b/src/client.rs @@ -14,10 +14,14 @@ impl Client { pub async fn create_audio_query( &self, - text: &str, speaker: i32, + text: &str, + speaker: i32, core_version: Option<&str>, ) -> Result { - let data: AudioQueryType = self.restapi.create_audio_query(text, speaker, core_version).await?; + let data: AudioQueryType = self + .restapi + .create_audio_query(text, speaker.to_string().as_str(), core_version) + .await?; let audio_query = AudioQuery::new(self.restapi.clone(), data); Ok(audio_query) } diff --git a/src/lib.rs b/src/lib.rs index c0e78cf..beb0d0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,20 +3,4 @@ mod client; mod restapi; mod types; -pub use client::Client; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let client = Client::new("http://localhost:50021"); - let audio_query = client.create_audio_query("こんにちは", 1) - .await - .unwrap(); - audio_query.synthesis(1) - .await - .unwrap(); - } -} +pub use client::Client; \ No newline at end of file diff --git a/src/restapi.rs b/src/restapi.rs index b003567..0cb3335 100644 --- a/src/restapi.rs +++ b/src/restapi.rs @@ -25,7 +25,8 @@ impl RestAPI { pub async fn create_audio_query( &self, - text: &str, speaker: &str, + text: &str, + speaker: &str, core_version: Option<&str>, ) -> Result { let mut params = vec![("text", text), ("speaker", speaker)]; @@ -42,7 +43,7 @@ impl RestAPI { Ok(data) } - pub async fn synthesis(&self, audio_query: &AudioQueryType, speaker: i32) -> Result { + pub async fn synthesis(&self, audio_query: &AudioQueryType, speaker: &str) -> Result { let data = self .request("POST", "/synthesis") .json(audio_query) diff --git a/src/types/audio_query.rs b/src/types/audio_query.rs index 954303d..ae62869 100644 --- a/src/types/audio_query.rs +++ b/src/types/audio_query.rs @@ -1,22 +1,46 @@ use serde::{Deserialize, Serialize}; +#[derive(Serialize, Deserialize, Debug)] +pub struct Mora { + text: String, + #[serde(default)] + consonant: String, + #[serde(default)] + consonant_length: f32, + vowel: String, + vowel_length: f32, + pitch: f32, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct AccentPhrase { + // moras: Vec, + accent: i32, + // pause_mora: Mora, + /* + #[serde(default)] + is_interrogative: bool, + */ +} + #[derive(Serialize, Deserialize, Debug)] pub struct AudioQueryType { + accent_phrases: Vec, #[serde(rename = "speedScale")] - speed_scale: i32, + speed_scale: f32, #[serde(rename = "pitchScale")] - pitch_scale: i32, + pitch_scale: f32, #[serde(rename = "intonationScale")] - intonation_scale: i32, + intonation_scale: f32, #[serde(rename = "volumeScale")] - volume_scale: i32, + volume_scale: f32, #[serde(rename = "prePhonemeLength")] - pre_phoneme_length: i32, + pre_phoneme_length: f32, #[serde(rename = "postPhonemeLength")] - post_phoneme_length: i32, + post_phoneme_length: f32, #[serde(rename = "outputSamplingRate")] output_sampling_rate: i32, #[serde(rename = "outputStereo")] output_stereo: bool, kana: String, -} +} \ No newline at end of file