mirror of
https://github.com/mii443/rust.git
synced 2025-08-22 16:25:37 +00:00
fix: iroiro
This commit is contained in:
@ -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
18
README.md
Normal 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
12
examples/basic.rs
Normal 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);
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
16
src/lib.rs
16
src/lib.rs
@ -4,19 +4,3 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -1,19 +1,43 @@
|
||||
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")]
|
||||
|
Reference in New Issue
Block a user