Add sample config and the option to speak repeated lines at a faster rate
CI / macos-latest (push) Has been cancelled
CI / ubuntu-latest (push) Has been cancelled
CI / windows-latest (push) Has been cancelled

This commit is contained in:
pleb
2026-07-21 09:33:47 -07:00
parent 54fa53222e
commit 456893415d
6 changed files with 147 additions and 18 deletions
+17 -2
View File
@@ -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"{}");