Add sample config and the option to speak repeated lines at a faster rate
This commit is contained in:
+17
-2
@@ -37,6 +37,7 @@ struct SpeechRequest<'a> {
|
||||
voice: &'a str,
|
||||
model: &'static str,
|
||||
response_format: &'static str,
|
||||
speed: f32,
|
||||
stream: bool,
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ impl KokoroClient {
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn synthesize_wav(&self, text: &str, voice: &str) -> Result<Vec<u8>> {
|
||||
pub async fn synthesize_wav(&self, text: &str, voice: &str, speed: f32) -> Result<Vec<u8>> {
|
||||
let response = self
|
||||
.client
|
||||
.post(self.endpoint("v1/audio/speech")?)
|
||||
@@ -91,6 +92,7 @@ impl KokoroClient {
|
||||
voice,
|
||||
model: "kokoro",
|
||||
response_format: "wav",
|
||||
speed,
|
||||
stream: false,
|
||||
})
|
||||
.send()
|
||||
@@ -156,12 +158,25 @@ mod tests {
|
||||
let url = serve_once("200 OK", "audio/wav", b"RIFFmock");
|
||||
let wav = KokoroClient::new(&url)
|
||||
.unwrap()
|
||||
.synthesize_wav("hello", "af_heart")
|
||||
.synthesize_wav("hello", "af_heart", 1.0)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(wav, b"RIFFmock");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn speech_request_includes_speed() {
|
||||
let request = SpeechRequest {
|
||||
input: "hello",
|
||||
voice: "af_heart",
|
||||
model: "kokoro",
|
||||
response_format: "wav",
|
||||
speed: 1.5,
|
||||
stream: false,
|
||||
};
|
||||
assert_eq!(serde_json::to_value(request).unwrap()["speed"], 1.5);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn treats_non_success_as_failure() {
|
||||
let url = serve_once("503 Service Unavailable", "application/json", b"{}");
|
||||
|
||||
Reference in New Issue
Block a user