#[allow(dead_code)]
use super::*;
const SOUND_GENERATION_PATH: &str = "/v1/sound-generation";
#[derive(Clone, Debug)]
pub struct SoundGeneration(SoundGenerationBody);
#[derive(Debug, Clone, Serialize)]
pub struct SoundGenerationBody {
text: String,
generation_settings: GenerationSettings,
}
#[derive(Debug, Clone, Serialize)]
pub struct GenerationSettings {
use_auto_duration: bool,
duration_seconds: f64,
prompt_influence: f64,
}
impl SoundGeneration {
pub fn new(text: &str, generation_settings: GenerationSettings) -> Self {
SoundGeneration(SoundGenerationBody {
text: text.to_string(),
generation_settings,
})
}
}
impl GenerationSettings {
pub fn new(use_auto_duration: bool, duration_seconds: f64, prompt_influence: f64) -> Self {
GenerationSettings {
use_auto_duration,
duration_seconds,
prompt_influence,
}
}
}
impl Endpoint for SoundGeneration {
type ResponseBody = Bytes;
fn method(&self) -> Method {
Method::POST
}
fn request_body(&self) -> Result<RequestBody> {
Ok(RequestBody::Json(serde_json::to_value(&self.0)?))
}
async fn response_body(self, resp: Response) -> Result<Self::ResponseBody> {
Ok(resp.bytes().await?)
}
fn url(&self) -> Url {
let mut url = BASE_URL.parse::<Url>().unwrap();
url.set_path(SOUND_GENERATION_PATH);
url
}
}