use crate::shared::response_wrapper::OpenAIError;
use crate::shared::types::FileMeta;
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum SttResponseFormat {
#[default]
#[strum(serialize = "json")]
Json,
#[strum(serialize = "text")]
Text,
#[strum(serialize = "srt")]
Srt,
#[strum(serialize = "verbose_json")]
VerboseJson,
#[strum(serialize = "vtt")]
Vtt,
}
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum TtsResponseFormat {
#[default]
#[strum(serialize = "mp3")]
Mp3,
#[strum(serialize = "opus")]
Opus,
#[strum(serialize = "aac")]
Aac,
#[strum(serialize = "flac")]
Flac,
#[strum(serialize = "wav")]
Wav,
#[strum(serialize = "pcm")]
Pcm,
}
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum Language {
#[default]
#[strum(serialize = "en")]
English,
#[strum(serialize = "zh")]
Chinese,
#[strum(serialize = "de")]
German,
#[strum(serialize = "es")]
Spanish,
#[strum(serialize = "ru")]
Russian,
#[strum(serialize = "ko")]
Korean,
#[strum(serialize = "fr")]
French,
#[strum(serialize = "ja")]
Japanese,
#[strum(serialize = "pt")]
Portuguese,
#[strum(serialize = "tr")]
Turkish,
#[strum(serialize = "pl")]
Polish,
#[strum(serialize = "ca")]
Catalan,
#[strum(serialize = "nl")]
Dutch,
#[strum(serialize = "ar")]
Arabic,
#[strum(serialize = "sv")]
Swedish,
#[strum(serialize = "it")]
Italian,
#[strum(serialize = "id")]
Indonesian,
#[strum(serialize = "hi")]
Hindi,
#[strum(serialize = "fi")]
Finnish,
#[strum(serialize = "vi")]
Vietnamese,
#[strum(serialize = "he")]
Hebrew,
#[strum(serialize = "uk")]
Ukrainian,
#[strum(serialize = "el")]
Greek,
#[strum(serialize = "ms")]
Malay,
#[strum(serialize = "cs")]
Czech,
#[strum(serialize = "ro")]
Romanian,
#[strum(serialize = "da")]
Danish,
#[strum(serialize = "hu")]
Hungarian,
#[strum(serialize = "ta")]
Tamil,
#[strum(serialize = "no")]
Norwegian,
#[strum(serialize = "th")]
Thai,
#[strum(serialize = "ur")]
Urdu,
#[strum(serialize = "hr")]
Croatian,
#[strum(serialize = "bg")]
Bulgarian,
#[strum(serialize = "lt")]
Lithuanian,
#[strum(serialize = "la")]
Latin,
#[strum(serialize = "mi")]
Maori,
#[strum(serialize = "ml")]
Malayalam,
#[strum(serialize = "cy")]
Welsh,
#[strum(serialize = "sk")]
Slovak,
#[strum(serialize = "te")]
Telugu,
#[strum(serialize = "fa")]
Persian,
#[strum(serialize = "lv")]
Latvian,
#[strum(serialize = "bn")]
Bengali,
#[strum(serialize = "sr")]
Serbian,
#[strum(serialize = "az")]
Azerbaijani,
#[strum(serialize = "sl")]
Slovenian,
#[strum(serialize = "kn")]
Kannada,
#[strum(serialize = "et")]
Estonian,
#[strum(serialize = "mk")]
Macedonian,
#[strum(serialize = "br")]
Breton,
#[strum(serialize = "eu")]
Basque,
#[strum(serialize = "is")]
Icelandic,
#[strum(serialize = "hy")]
Armenian,
#[strum(serialize = "ne")]
Nepali,
#[strum(serialize = "mn")]
Mongolian,
#[strum(serialize = "bs")]
Bosnian,
#[strum(serialize = "kk")]
Kazakh,
#[strum(serialize = "sq")]
Albanian,
#[strum(serialize = "sw")]
Swahili,
#[strum(serialize = "gl")]
Galician,
#[strum(serialize = "mr")]
Marathi,
#[strum(serialize = "pa")]
Punjabi,
#[strum(serialize = "si")]
Sinhala,
#[strum(serialize = "km")]
Khmer,
#[strum(serialize = "sn")]
Shona,
#[strum(serialize = "yo")]
Yoruba,
#[strum(serialize = "so")]
Somali,
#[strum(serialize = "af")]
Afrikaans,
#[strum(serialize = "oc")]
Occitan,
#[strum(serialize = "ka")]
Georgian,
#[strum(serialize = "be")]
Belarusian,
#[strum(serialize = "tg")]
Tajik,
#[strum(serialize = "sd")]
Sindhi,
#[strum(serialize = "gu")]
Gujarati,
#[strum(serialize = "am")]
Amharic,
#[strum(serialize = "yi")]
Yiddish,
#[strum(serialize = "lo")]
Lao,
#[strum(serialize = "uz")]
Uzbek,
#[strum(serialize = "fo")]
Faroese,
#[strum(serialize = "ht")]
HaitianCreole,
#[strum(serialize = "ps")]
Pashto,
#[strum(serialize = "tk")]
Turkmen,
#[strum(serialize = "nn")]
Nynorsk,
#[strum(serialize = "mt")]
Maltese,
#[strum(serialize = "sa")]
Sanskrit,
#[strum(serialize = "lb")]
Luxembourgish,
#[strum(serialize = "my")]
Myanmar,
#[strum(serialize = "bo")]
Tibetan,
#[strum(serialize = "tl")]
Tagalog,
#[strum(serialize = "mg")]
Malagasy,
#[strum(serialize = "as")]
Assamese,
#[strum(serialize = "tt")]
Tatar,
#[strum(serialize = "haw")]
Hawaiian,
#[strum(serialize = "ln")]
Lingala,
#[strum(serialize = "ha")]
Hausa,
#[strum(serialize = "ba")]
Bashkir,
#[strum(serialize = "jw")]
Javanese,
#[strum(serialize = "su")]
Sundanese,
}
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum Voice {
#[default]
#[strum(serialize = "alloy")]
Alloy,
#[strum(serialize = "echo")]
Echo,
#[strum(serialize = "fable")]
Fable,
#[strum(serialize = "onyx")]
Onyx,
#[strum(serialize = "nova")]
Nova,
#[strum(serialize = "shimmer")]
Shimmer,
}
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum SttModel {
#[default]
#[strum(serialize = "whisper-1")]
Whisper1,
}
#[derive(Debug, Serialize, Default, Clone, strum::Display)]
pub enum AudioSpeechModel {
#[default]
#[strum(serialize = "tts-1")]
Whisper1,
#[strum(serialize = "tts-1-hd")]
Whisper1Hd,
}
#[derive(Builder, Clone, Debug, Default, Serialize)]
#[builder(name = "CreateSpeechRequestBuilder")]
#[builder(pattern = "mutable")]
#[builder(setter(into, strip_option), default)]
#[builder(derive(Debug))]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CreateSpeechRequest {
pub model: AudioSpeechModel,
pub input: String,
pub voice: Voice,
pub response_format: Option<SttResponseFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub speed: Option<f32>, }
#[derive(Builder, Clone, Debug, Default, Serialize)]
#[builder(name = "CreateTranscriptionRequestBuilder")]
#[builder(pattern = "mutable")]
#[builder(setter(into, strip_option), default)]
#[builder(derive(Debug))]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CreateTranscriptionRequest {
pub file: FileMeta,
pub model: SttModel,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub response_format: Option<SttResponseFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language: Option<Language>,
}
#[derive(Builder, Clone, Debug, Default, Serialize)]
#[builder(name = "CreateTranslationRequestBuilder")]
#[builder(pattern = "mutable")]
#[builder(setter(into, strip_option), default)]
#[builder(derive(Debug))]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CreateTranslationRequest {
pub file: FileMeta,
pub model: SttModel,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub response_format: Option<SttResponseFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>, }
#[derive(Debug, Deserialize, Clone, Serialize)]
pub struct VerboseJsonForAudioResponse {
pub task: Option<String>,
pub language: Option<String>,
pub duration: Option<f32>,
pub segments: Option<Vec<Segment>>,
pub text: String,
}
#[derive(Debug, Deserialize, Clone, Serialize)]
pub struct Segment {
pub id: u32,
pub seek: u32,
pub start: f32,
pub end: f32,
pub text: String,
pub tokens: Vec<u32>,
pub temperature: f32,
pub avg_logprob: f32,
pub compression_ratio: f32,
pub no_speech_prob: f32,
}