fix: iroiro

This commit is contained in:
tuna2134
2023-04-08 16:15:48 +09:00
parent ac61e29c3a
commit afc781e8c4
8 changed files with 80 additions and 30 deletions

View File

@ -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"] }

18
README.md Normal file
View File

@ -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();
}
```

12
examples/basic.rs Normal file
View File

@ -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);
}

View File

@ -16,7 +16,10 @@ impl AudioQuery {
}
pub async fn synthesis(&self, speaker: i32) -> Result<Bytes> {
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)
}
}

View File

@ -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<AudioQuery> {
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)
}

View File

@ -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;

View File

@ -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<AudioQueryType> {
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<Bytes> {
pub async fn synthesis(&self, audio_query: &AudioQueryType, speaker: &str) -> Result<Bytes> {
let data = self
.request("POST", "/synthesis")
.json(audio_query)

View File

@ -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<Mora>,
accent: i32,
// pause_mora: Mora,
/*
#[serde(default)]
is_interrogative: bool,
*/
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AudioQueryType {
accent_phrases: Vec<AccentPhrase>,
#[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,
}
}