openai_req/audio/
mod.rs

1use crate::{FormRequest, OpenAiClient, process_response, process_text_response};
2use std::io;
3use std::path::{PathBuf};
4use reqwest::multipart::{Form, Part};
5use serde::{Serialize,Deserialize};
6use crate::file_to_part;
7use async_trait::async_trait;
8use anyhow::Result;
9use futures_util::TryFutureExt;
10use reqwest::Response;
11use strum_macros::Display;
12use crate::conversions::AsyncTryFrom;
13
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub enum ResponseFormat{
16    Json,
17    VerboseJson,
18    Text,
19    Srt,
20    Vtt
21}
22
23impl ToString for ResponseFormat {
24    fn to_string(&self) -> String {
25        match self {
26            ResponseFormat::Json => "json".to_string(),
27            ResponseFormat::Text => "text".to_string(),
28            ResponseFormat::Srt => "srt".to_string(),
29            ResponseFormat::VerboseJson => "verbose_json".to_string(),
30            ResponseFormat::Vtt => "vtt".to_string()
31        }
32    }
33}
34
35
36#[derive(Clone, Debug, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum AudioResponse{
39    Json(ShortAudioResponse),
40    VerboseJson(VerboseAudioResponse),
41    Text(String),
42    Srt(String),
43    Vtt(String)
44}
45
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
48pub struct ShortAudioResponse{
49    pub text:String
50}
51
52
53#[derive(Serialize, Deserialize, Clone, Debug)]
54pub struct Segment {
55    pub id: i64,
56    pub seek: i64,
57    pub start: f64,
58    pub end: f64,
59    pub text: String,
60    pub tokens: Vec<i64>,
61    pub temperature: f64,
62    pub avg_logprob: f64,
63    pub compression_ratio: f64,
64    pub no_speech_prob: f64,
65    pub transient: bool,
66}
67
68#[derive(Serialize, Deserialize, Clone, Debug)]
69pub struct VerboseAudioResponse {
70    pub task: String,
71    pub language: String,
72    pub duration: f64,
73    pub segments: Vec<Segment>,
74    pub text: String,
75}
76
77///request that provides transcription for given audio file
78///parameter details at  https://platform.openai.com/docs/api-reference/audio/create
79///
80/// # Usage example
81///```
82///
83/// use std::path::PathBuf;
84/// use openai_req::audio::{Iso639_1, TranscriptionRequest};
85/// use openai_req::FormRequest;
86///
87///   let req = TranscriptionRequest::new(PathBuf::from("tests/Linus-linux.mp3"))
88///         .language(Iso639_1::En);
89///   let res = req.run(&client).await?;
90///
91/// ```
92#[derive(Clone, Debug, Serialize, Deserialize)]
93pub struct TranscriptionRequest{
94    file: PathBuf,
95    model: String,
96    prompt:Option<String>,
97    response_format: Option<ResponseFormat>,
98    temperature: Option<f64>,
99    language: Option<Iso639_1>
100}
101
102#[async_trait]
103impl FormRequest<AudioResponse> for TranscriptionRequest{
104    const ENDPOINT: &'static str = "/audio/transcriptions";
105
106    async fn run(&self, client:&OpenAiClient)-> Result<AudioResponse>{
107        let final_url =  client.url.to_owned()+Self::ENDPOINT;
108        let res = self.get_response(&client.client,final_url,&client.key).await?;
109        process_audio_response(&self.response_format,res).await
110    }
111}
112
113
114#[async_trait]
115impl AsyncTryFrom<TranscriptionRequest> for Form {
116    type Error = io::Error;
117
118    async fn try_from(transcription_request: TranscriptionRequest) -> Result<Self, Self::Error> {
119        let mut form = Form::new();
120        form = form.part("model", Part::text(transcription_request.model));
121        form = form.part("file", file_to_part(&transcription_request.file).await?);
122
123        if let Some(prompt) = transcription_request.prompt {
124            form = form.part("prompt", Part::text(prompt));
125        }
126
127        if let Some(response_format) = transcription_request.response_format {
128            form = form.part("response_format", Part::text(response_format.to_string()));
129        }
130
131        if let Some(temperature) = transcription_request.temperature {
132            form = form.part("temperature", Part::text(temperature.to_string()));
133        }
134
135        if let Some(language) = transcription_request.language {
136
137            form = form.part("language", Part::text(language.to_string()));
138        }
139
140        Ok(form)
141    }
142}
143
144
145impl TranscriptionRequest {
146
147    /// Minimal constructor is enough to run a request,
148    /// you can get a transcription by only providing file name.
149    /// But quality will be significantly better if you at least specify source language
150    pub fn new(file: PathBuf) -> Self {
151        TranscriptionRequest {
152            file,
153            model: "whisper-1".to_string(),
154            prompt: None,
155            response_format: None,
156            temperature: None,
157            language: None
158        }
159    }
160
161    pub fn with_model(file: PathBuf, model: String) -> Self {
162        TranscriptionRequest {
163            file,
164            model,
165            prompt: None,
166            response_format: None,
167            temperature: None,
168            language: None
169        }
170    }
171
172    pub fn file(mut self, file: PathBuf) -> Self {
173        self.file = file;
174        self
175    }
176
177    pub fn model(mut self, model: String) -> Self {
178        self.model = model;
179        self
180    }
181
182    pub fn prompt(mut self, prompt: String) -> Self {
183        self.prompt = Some(prompt);
184        self
185    }
186
187    pub fn response_format(mut self, response_format: ResponseFormat) -> Self {
188        self.response_format = Some(response_format);
189        self
190    }
191
192    pub fn temperature(mut self, temperature: f64) -> Self {
193        self.temperature = Some(temperature);
194        self
195    }
196
197    pub fn language(mut self, language: Iso639_1) -> Self {
198        self.language = Some(language);
199        self
200    }
201
202}
203
204///request that provides translation to english for given audio file
205///parameter details at  https://platform.openai.com/docs/api-reference/audio/create
206/// # Usage example
207///```
208///
209/// use std::path::PathBuf;
210/// use openai_req::audio::TranslationRequest;
211/// use openai_req::FormRequest;
212/// let req = TranslationRequest::new(PathBuf::from("tests/Linus-linux.mp3"));
213/// let res = req.run(&client).await?;
214/// ```
215#[derive(Clone, Debug, Serialize, Deserialize)]
216pub struct TranslationRequest{
217    file: PathBuf,
218    model: String,
219    prompt:Option<String>,
220    response_format: Option<ResponseFormat>,
221    temperature: Option<f64>
222}
223
224#[async_trait]
225impl FormRequest<AudioResponse> for TranslationRequest{
226    const ENDPOINT: &'static str = "/audio/translations";
227
228    async fn run(&self, client:&OpenAiClient)-> Result<AudioResponse>{
229        let final_url =  client.url.to_owned()+Self::ENDPOINT;
230        let res = self.get_response(&client.client,final_url,&client.key).await?;
231        process_audio_response(&self.response_format,res).await
232    }
233}
234
235
236#[async_trait]
237impl AsyncTryFrom<TranslationRequest> for Form {
238    type Error = io::Error;
239
240    async fn try_from(translation_request: TranslationRequest) -> Result<Self, Self::Error> {
241        let mut form = Form::new();
242        form = form.part("model", Part::text(translation_request.model));
243        form = form.part("file", file_to_part(&translation_request.file).await?);
244
245        if let Some(prompt) = translation_request.prompt {
246            form = form.part("prompt", Part::text(prompt));
247        }
248
249        if let Some(response_format) = translation_request.response_format {
250            form = form.part("response_format", Part::text(response_format.to_string()));
251        }
252
253        if let Some(temperature) = translation_request.temperature {
254            form = form.part("temperature", Part::text(temperature.to_string()));
255        }
256
257        Ok(form)
258    }
259}
260
261impl TranslationRequest {
262    pub fn new(file: PathBuf) -> Self {
263        TranslationRequest {
264            file,
265            model:"whisper-1".to_string(),
266            prompt: None,
267            response_format: None,
268            temperature: None
269        }
270    }
271
272    pub fn with_model(file: PathBuf, model: String) -> Self {
273        TranslationRequest {
274            file,
275            model,
276            prompt: None,
277            response_format: None,
278            temperature: None
279        }
280    }
281
282    pub fn file(mut self, file: PathBuf) -> Self {
283        self.file = file;
284        self
285    }
286
287    pub fn model(mut self, model: String) -> Self {
288        self.model = model;
289        self
290    }
291
292    pub fn prompt(mut self, prompt: String) -> Self {
293        self.prompt = Some(prompt);
294        self
295    }
296
297    pub fn response_format(mut self, response_format: ResponseFormat) -> Self {
298        self.response_format = Some(response_format);
299        self
300    }
301
302    pub fn temperature(mut self, temperature: f64) -> Self {
303        self.temperature = Some(temperature);
304        self
305    }
306}
307
308
309
310
311#[derive(Clone, Debug, PartialEq, Display, Serialize, Deserialize)]
312#[strum(serialize_all = "lowercase")]
313pub enum Iso639_1 {
314    /// 639-2: aar, name: Afar (Afaraf)
315    Aa,
316    /// 639-2: abk, name: Abkhaz (аҧсуа бызшәа, аҧсшәа)
317    Ab,
318    /// 639-2: ave, name: Avestan (avesta)
319    Ae,
320    /// 639-2: afr, name: Afrikaans
321    Af,
322    /// 639-2: aka, name: Akan
323    Ak,
324    /// 639-2: amh, name: Amharic (አማርኛ)
325    Am,
326    /// 639-2: arg, name: Aragonese (aragonés)
327    An,
328    /// 639-2: ara, name: Arabic (العربية)
329    Ar,
330    /// 639-2: asm, name: Assamese (অসমীয়া)
331    As,
332    /// 639-2: ava, name: Avaric (авар мацӀ, магӀарул мацӀ)
333    Av,
334    /// 639-2: aym, name: Aymara (aymar aru)
335    Ay,
336    /// 639-2: aze, name: Azerbaijani (azərbaycan dili)
337    Az,
338    /// 639-2: bak, name: Bashkir (башҡорт теле)
339    Ba,
340    /// 639-2: bel, name: Belarusian (беларуская мова)
341    Be,
342    /// 639-2: bul, name: Bulgarian (български език)
343    Bg,
344    /// 639-2: bih, name: Bihari (भोजपुरी)
345    Bh,
346    /// 639-2: bis, name: Bislama
347    Bi,
348    /// 639-2: bam, name: Bambara (bamanankan)
349    Bm,
350    /// 639-2: ben, name: Bengali, Bangla (বাংলা)
351    Bn,
352    /// 639-2: bod, name: Tibetan Standard, Tibetan, Central (བོད་ཡིག)
353    Bo,
354    /// 639-2: bre, name: Breton (brezhoneg)
355    Br,
356    /// 639-2: bos, name: Bosnian (bosanski jezik)
357    Bs,
358    /// 639-2: cat, name: Catalan (català)
359    Ca,
360    /// 639-2: che, name: Chechen (нохчийн мотт)
361    Ce,
362    /// 639-2: cha, name: Chamorro (Chamoru)
363    Ch,
364    /// 639-2: cos, name: Corsican (corsu, lingua corsa)
365    Co,
366    /// 639-2: cre, name: Cree (ᓀᐦᐃᔭᐍᐏᐣ)
367    Cr,
368    /// 639-2: ces, name: Czech (čeština, český jazyk)
369    Cs,
370    /// 639-2: chu, name: Old Church Slavonic, Church Slavonic, Old Bulgarian (ѩзыкъ словѣньскъ)
371    Cu,
372    /// 639-2: chv, name: Chuvash (чӑваш чӗлхи)
373    Cv,
374    /// 639-2: cym, name: Welsh (Cymraeg)
375    Cy,
376    /// 639-2: dan, name: Danish (dansk)
377    Da,
378    /// 639-2: deu, name: German (Deutsch)
379    De,
380    /// 639-2: div, name: Divehi, Dhivehi, Maldivian (ދިވެހި)
381    Dv,
382    /// 639-2: dzo, name: Dzongkha (རྫོང་ཁ)
383    Dz,
384    /// 639-2: ewe, name: Ewe (Eʋegbe)
385    Ee,
386    /// 639-2: ell, name: Greek (modern) (ελληνικά)
387    El,
388    /// 639-2: eng, name: English
389    En,
390    /// 639-2: epo, name: Esperanto
391    Eo,
392    /// 639-2: spa, name: Spanish (Español)
393    Es,
394    /// 639-2: est, name: Estonian (eesti, eesti keel)
395    Et,
396    /// 639-2: eus, name: Basque (euskara, euskera)
397    Eu,
398    /// 639-2: fas, name: Persian (Farsi) (فارسی)
399    Fa,
400    /// 639-2: ful, name: Fula, Fulah, Pulaar, Pular (Fulfulde, Pulaar, Pular)
401    Ff,
402    /// 639-2: fin, name: Finnish (suomi, suomen kieli)
403    Fi,
404    /// 639-2: fij, name: Fijian (vosa Vakaviti)
405    Fj,
406    /// 639-2: fao, name: Faroese (føroyskt)
407    Fo,
408    /// 639-2: fra, name: French (français, langue française)
409    Fr,
410    /// 639-2: fry, name: Western Frisian (Frysk)
411    Fy,
412    /// 639-2: gle, name: Irish (Gaeilge)
413    Ga,
414    /// 639-2: gla, name: Scottish Gaelic, Gaelic (Gàidhlig)
415    Gd,
416    /// 639-2: glg, name: Galician (galego)
417    Gl,
418    /// 639-2: grn, name: Guaraní (Avañe'ẽ)
419    Gn,
420    /// 639-2: guj, name: Gujarati (ગુજરાતી)
421    Gu,
422    /// 639-2: glv, name: Manx (Gaelg, Gailck)
423    Gv,
424    /// 639-2: hau, name: Hausa ((Hausa) هَوُسَ)
425    Ha,
426    /// 639-2: heb, name: Hebrew (modern) (עברית)
427    He,
428    /// 639-2: hin, name: Hindi (हिन्दी, हिंदी)
429    Hi,
430    /// 639-2: hmo, name: Hiri Motu
431    Ho,
432    /// 639-2: hrv, name: Croatian (hrvatski jezik)
433    Hr,
434    /// 639-2: hat, name: Haitian, Haitian Creole (Kreyòl ayisyen)
435    Ht,
436    /// 639-2: hun, name: Hungarian (magyar)
437    Hu,
438    /// 639-2: hye, name: Armenian (Հայերեն)
439    Hy,
440    /// 639-2: her, name: Herero (Otjiherero)
441    Hz,
442    /// 639-2: ina, name: Interlingua
443    Ia,
444    /// 639-2: ind, name: Indonesian (Bahasa Indonesia)
445    Id,
446    /// 639-2: ile, name: Interlingue (Originally called Occidental; then Interlingue after WWII)
447    Ie,
448    /// 639-2: ibo, name: Igbo (Asụsụ Igbo)
449    Ig,
450    /// 639-2: iii, name: Nuosu (ꆈꌠ꒿ Nuosuhxop)
451    Ii,
452    /// 639-2: ipk, name: Inupiaq (Iñupiaq, Iñupiatun)
453    Ik,
454    /// 639-2: ido, name: Ido
455    Io,
456    /// 639-2: isl, name: Icelandic (Íslenska)
457    Is,
458    /// 639-2: ita, name: Italian (Italiano)
459    It,
460    /// 639-2: iku, name: Inuktitut (ᐃᓄᒃᑎᑐᑦ)
461    Iu,
462    /// 639-2: jpn, name: Japanese (日本語 (にほんご))
463    Ja,
464    /// 639-2: jav, name: Javanese (ꦧꦱꦗꦮ, Basa Jawa)
465    Jv,
466    /// 639-2: kat, name: Georgian (ქართული)
467    Ka,
468    /// 639-2: kon, name: Kongo (Kikongo)
469    Kg,
470    /// 639-2: kik, name: Kikuyu, Gikuyu (Gĩkũyũ)
471    Ki,
472    /// 639-2: kua, name: Kwanyama, Kuanyama (Kuanyama)
473    Kj,
474    /// 639-2: kaz, name: Kazakh (қазақ тілі)
475    Kk,
476    /// 639-2: kal, name: Kalaallisut, Greenlandic (kalaallisut, kalaallit oqaasii)
477    Kl,
478    /// 639-2: khm, name: Khmer (ខ្មែរ, ខេមរភាសា, ភាសាខ្មែរ)
479    Km,
480    /// 639-2: kan, name: Kannada (ಕನ್ನಡ)
481    Kn,
482    /// 639-2: kor, name: Korean (한국어)
483    Ko,
484    /// 639-2: kau, name: Kanuri
485    Kr,
486    /// 639-2: kas, name: Kashmiri (कश्मीरी, كشميري‎)
487    Ks,
488    /// 639-2: kur, name: Kurdish (Kurdî, كوردی‎)
489    Ku,
490    /// 639-2: kom, name: Komi (коми кыв)
491    Kv,
492    /// 639-2: cor, name: Cornish (Kernewek)
493    Kw,
494    /// 639-2: kir, name: Kyrgyz (Кыргызча, Кыргыз тили)
495    Ky,
496    /// 639-2: lat, name: Latin (latine, lingua latina)
497    La,
498    /// 639-2: ltz, name: Luxembourgish, Letzeburgesch (Lëtzebuergesch)
499    Lb,
500    /// 639-2: lug, name: Ganda (Luganda)
501    Lg,
502    /// 639-2: lim, name: Limburgish, Limburgan, Limburger (Limburgs)
503    Li,
504    /// 639-2: lin, name: Lingala (Lingála)
505    Ln,
506    /// 639-2: lao, name: Lao (ພາສາລາວ)
507    Lo,
508    /// 639-2: lit, name: Lithuanian (lietuvių kalba)
509    Lt,
510    /// 639-2: lub, name: Luba-Katanga (Tshiluba)
511    Lu,
512    /// 639-2: lav, name: Latvian (latviešu valoda)
513    Lv,
514    /// 639-2: mlg, name: Malagasy (fiteny malagasy)
515    Mg,
516    /// 639-2: mah, name: Marshallese (Kajin M̧ajeļ)
517    Mh,
518    /// 639-2: mri, name: Māori (te reo Māori)
519    Mi,
520    /// 639-2: mkd, name: Macedonian (македонски јазик)
521    Mk,
522    /// 639-2: mal, name: Malayalam (മലയാളം)
523    Ml,
524    /// 639-2: mon, name: Mongolian (Монгол хэл)
525    Mn,
526    /// 639-2: mar, name: Marathi (Marāṭhī) (मराठी)
527    Mr,
528    /// 639-2: msa, name: Malay (bahasa Melayu, بهاس ملايو‎)
529    Ms,
530    /// 639-2: mlt, name: Maltese (Malti)
531    Mt,
532    /// 639-2: mya, name: Burmese (ဗမာစာ)
533    My,
534    /// 639-2: nau, name: Nauruan (Dorerin Naoero)
535    Na,
536    /// 639-2: nob, name: Norwegian Bokmål (Norsk bokmål)
537    Nb,
538    /// 639-2: nde, name: Northern Ndebele (isiNdebele)
539    Nd,
540    /// 639-2: nep, name: Nepali (नेपाली)
541    Ne,
542    /// 639-2: ndo, name: Ndonga (Owambo)
543    Ng,
544    /// 639-2: nld, name: Dutch (Nederlands, Vlaams)
545    Nl,
546    /// 639-2: nno, name: Norwegian Nynorsk (Norsk nynorsk)
547    Nn,
548    /// 639-2: nor, name: Norwegian (Norsk)
549    No,
550    /// 639-2: nbl, name: Southern Ndebele (isiNdebele)
551    Nr,
552    /// 639-2: nav, name: Navajo, Navaho (Diné bizaad)
553    Nv,
554    /// 639-2: nya, name: Chichewa, Chewa, Nyanja (chiCheŵa, chinyanja)
555    Ny,
556    /// 639-2: oci, name: Occitan (occitan, lenga d'òc)
557    Oc,
558    /// 639-2: oji, name: Ojibwe, Ojibwa (ᐊᓂᔑᓈᐯᒧᐎᓐ)
559    Oj,
560    /// 639-2: orm, name: Oromo (Afaan Oromoo)
561    Om,
562    /// 639-2: ori, name: Oriya (ଓଡ଼ିଆ)
563    Or,
564    /// 639-2: oss, name: Ossetian, Ossetic (ирон æвзаг)
565    Os,
566    /// 639-2: pan, name: (Eastern) Punjabi (ਪੰਜਾਬੀ)
567    Pa,
568    /// 639-2: pli, name: Pāli (पाऴि)
569    Pi,
570    /// 639-2: pol, name: Polish (język polski, polszczyzna)
571    Pl,
572    /// 639-2: pus, name: Pashto, Pushto (پښتو)
573    Ps,
574    /// 639-2: por, name: Portuguese (Português)
575    Pt,
576    /// 639-2: que, name: Quechua (Runa Simi, Kichwa)
577    Qu,
578    /// 639-2: roh, name: Romansh (rumantsch grischun)
579    Rm,
580    /// 639-2: run, name: Kirundi (Ikirundi)
581    Rn,
582    /// 639-2: ron, name: Romanian (Română)
583    Ro,
584    /// 639-2: rus, name: Russian (Русский)
585    Ru,
586    /// 639-2: kin, name: Kinyarwanda (Ikinyarwanda)
587    Rw,
588    /// 639-2: san, name: Sanskrit (Saṁskṛta) (संस्कृतम्)
589    Sa,
590    /// 639-2: srd, name: Sardinian (sardu)
591    Sc,
592    /// 639-2: snd, name: Sindhi (सिन्धी, سنڌي، سندھی‎)
593    Sd,
594    /// 639-2: sme, name: Northern Sami (Davvisámegiella)
595    Se,
596    /// 639-2: sag, name: Sango (yângâ tî sängö)
597    Sg,
598    /// 639-2: sin, name: Sinhalese, Sinhala (සිංහල)
599    Si,
600    /// 639-2: slk, name: Slovak (slovenčina, slovenský jazyk)
601    Sk,
602    /// 639-2: slv, name: Slovene (slovenski jezik, slovenščina)
603    Sl,
604    /// 639-2: smo, name: Samoan (gagana fa'a Samoa)
605    Sm,
606    /// 639-2: sna, name: Shona (chiShona)
607    Sn,
608    /// 639-2: som, name: Somali (Soomaaliga, af Soomaali)
609    So,
610    /// 639-2: sqi, name: Albanian (Shqip)
611    Sq,
612    /// 639-2: srp, name: Serbian (српски језик)
613    Sr,
614    /// 639-2: ssw, name: Swati (SiSwati)
615    Ss,
616    /// 639-2: sot, name: Southern Sotho (Sesotho)
617    St,
618    /// 639-2: sun, name: Sundanese (Basa Sunda)
619    Su,
620    /// 639-2: swe, name: Swedish (svenska)
621    Sv,
622    /// 639-2: swa, name: Swahili (Kiswahili)
623    Sw,
624    /// 639-2: tam, name: Tamil (தமிழ்)
625    Ta,
626    /// 639-2: tel, name: Telugu (తెలుగు)
627    Te,
628    /// 639-2: tgk, name: Tajik (тоҷикӣ, toçikī, تاجیکی‎)
629    Tg,
630    /// 639-2: tha, name: Thai (ไทย)
631    Th,
632    /// 639-2: tir, name: Tigrinya (ትግርኛ)
633    Ti,
634    /// 639-2: tuk, name: Turkmen (Türkmen, Түркмен)
635    Tk,
636    /// 639-2: tgl, name: Tagalog (Wikang Tagalog)
637    Tl,
638    /// 639-2: tsn, name: Tswana (Setswana)
639    Tn,
640    /// 639-2: ton, name: Tonga (Tonga Islands) (faka Tonga)
641    To,
642    /// 639-2: tur, name: Turkish (Türkçe)
643    Tr,
644    /// 639-2: tso, name: Tsonga (Xitsonga)
645    Ts,
646    /// 639-2: tat, name: Tatar (татар теле, tatar tele)
647    Tt,
648    /// 639-2: twi, name: Twi
649    Tw,
650    /// 639-2: tah, name: Tahitian (Reo Tahiti)
651    Ty,
652    /// 639-2: uig, name: Uyghur (ئۇيغۇرچە‎, Uyghurche)
653    Ug,
654    /// 639-2: ukr, name: Ukrainian (Українська)
655    Uk,
656    /// 639-2: urd, name: Urdu (اردو)
657    Ur,
658    /// 639-2: uzb, name: Uzbek (Oʻzbek, Ўзбек, أۇزبېك‎)
659    Uz,
660    /// 639-2: ven, name: Venda (Tshivenḓa)
661    Ve,
662    /// 639-2: vie, name: Vietnamese (Tiếng Việt)
663    Vi,
664    /// 639-2: vol, name: Volapük
665    Vo,
666    /// 639-2: wln, name: Walloon (walon)
667    Wa,
668    /// 639-2: wol, name: Wolof (Wollof)
669    Wo,
670    /// 639-2: xho, name: Xhosa (isiXhosa)
671    Xh,
672    /// 639-2: yid, name: Yiddish (ייִדיש)
673    Yi,
674    /// 639-2: yor, name: Yoruba (Yorùbá)
675    Yo,
676    /// 639-2: zha, name: Zhuang, Chuang (Saɯ cueŋƅ, Saw cuengh)
677    Za,
678    /// 639-2: zho, name: Chinese (中文 (Zhōngwén), 汉语, 漢語)
679    Zh,
680    /// 639-2: zul, name: Zulu (isiZulu)
681    Zu,
682}
683
684
685
686async fn process_audio_response(resp_format:&Option<ResponseFormat>,res:Response)-> Result<AudioResponse>{
687    match resp_format {
688        None => process_response::<ShortAudioResponse>(res).map_ok(AudioResponse::Json).await,
689        Some(format) => match format {
690            ResponseFormat::Json => process_response::<ShortAudioResponse>(res).map_ok(AudioResponse::Json).await,
691            ResponseFormat::VerboseJson => process_response::<VerboseAudioResponse>(res).map_ok(AudioResponse::VerboseJson).await,
692            ResponseFormat::Text => process_text_response(res).map_ok(AudioResponse::Text).await,
693            ResponseFormat::Srt => process_text_response(res).map_ok(AudioResponse::Srt).await,
694            ResponseFormat::Vtt => process_text_response(res).map_ok(AudioResponse::Vtt).await
695        }
696    }
697}