d_id/endpoints/resources/
audios.rs1use super::*;
5
6const AUDIOS_PATH: &str = "/audios";
7
8#[derive(Serialize, Deserialize, Debug)]
9pub struct AudioResponse {
10 pub id: String,
11 pub url: String,
12 pub duration: f64,
13}
14
15pub async fn upload_audio_by_file(mime_type: &str, path: &str) -> Result<AudioResponse> {
21 let mut form = MultipartFormData::new();
22 form.add_file(mime_type, "audio", path)?;
23 form.end_body()?;
24
25 let c = ClientBuilder::new()?
26 .method(POST)?
27 .path(AUDIOS_PATH)?
28 .header(ACCEPT, APPLICATION_JSON)?
29 .header(CONTENT_TYPE, &format!("{}{}", MULTIPART_FORM_DATA_BOUNDARY, form.boundary))?
30 .build()?;
31
32 let resp = c.send_request(Full::<Bytes>::new(form.body.into())).await?;
33
34 let json = serde_json::from_slice::<AudioResponse>(&resp.as_ref())?;
35
36 Ok(json)
37}
38
39
40pub async fn delete_audio(id: &str) -> Result<()> {
41 let c = ClientBuilder::new()?
42 .method(DELETE)?
43 .path(&format!("{}/{}", AUDIOS_PATH, id))?
44 .header(CONTENT_TYPE, APPLICATION_JSON)?
45 .build()?;
46
47 let _resp = c.send_request(Empty::<Bytes>::new()).await?;
48
49 Ok(())
50}
51