openai_api_rs/v1/
audio.rs1use reqwest::header::HeaderMap;
2use serde::{Deserialize, Serialize};
3
4use crate::impl_builder_methods;
5
6pub const WHISPER_1: &str = "whisper-1";
7
8#[derive(Debug, Serialize, Clone)]
9pub struct AudioTranscriptionRequest {
10 pub model: String,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub file: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub bytes: Option<Vec<u8>>,
15 pub prompt: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub response_format: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub temperature: Option<f32>,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub language: Option<String>,
22}
23
24impl AudioTranscriptionRequest {
25 pub fn new(file: String, model: String) -> Self {
26 Self {
27 model,
28 file: Some(file),
29 bytes: None,
30 prompt: None,
31 response_format: None,
32 temperature: None,
33 language: None,
34 }
35 }
36
37 pub fn new_bytes(bytes: Vec<u8>, model: String) -> Self {
38 Self {
39 model,
40 file: None,
41 bytes: Some(bytes),
42 prompt: None,
43 response_format: None,
44 temperature: None,
45 language: None,
46 }
47 }
48}
49
50impl_builder_methods!(
51 AudioTranscriptionRequest,
52 prompt: String,
53 response_format: String,
54 temperature: f32,
55 language: String
56);
57
58#[derive(Debug, Deserialize, Serialize)]
59pub struct AudioTranscriptionResponse {
60 pub text: String,
61}
62
63#[derive(Debug, Serialize, Clone)]
64pub struct AudioTranslationRequest {
65 pub file: String,
66 pub model: String,
67 #[serde(skip_serializing_if = "Option::is_none")]
68 pub prompt: Option<String>,
69 #[serde(skip_serializing_if = "Option::is_none")]
70 pub response_format: Option<String>,
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub temperature: Option<f32>,
73}
74
75impl AudioTranslationRequest {
76 pub fn new(file: String, model: String) -> Self {
77 Self {
78 file,
79 model,
80 prompt: None,
81 response_format: None,
82 temperature: None,
83 }
84 }
85}
86
87impl_builder_methods!(
88 AudioTranslationRequest,
89 prompt: String,
90 response_format: String,
91 temperature: f32
92);
93
94#[derive(Debug, Deserialize, Serialize)]
95pub struct AudioTranslationResponse {
96 pub text: String,
97}
98
99pub const TTS_1: &str = "tts-1";
100pub const TTS_1_HD: &str = "tts-1-hd";
101
102pub const VOICE_ALLOY: &str = "alloy";
103pub const VOICE_ECHO: &str = "echo";
104pub const VOICE_FABLE: &str = "fable";
105pub const VOICE_ONYX: &str = "onyx";
106pub const VOICE_NOVA: &str = "nova";
107pub const VOICE_SHIMMER: &str = "shimmer";
108
109#[derive(Debug, Serialize, Clone)]
110pub struct AudioSpeechRequest {
111 pub model: String,
112 pub input: String,
113 pub voice: String,
114 pub output: String,
115}
116
117impl AudioSpeechRequest {
118 pub fn new(model: String, input: String, voice: String, output: String) -> Self {
119 Self {
120 model,
121 input,
122 voice,
123 output,
124 }
125 }
126}
127
128impl_builder_methods!(AudioSpeechRequest,);
129
130#[derive(Debug)]
131pub struct AudioSpeechResponse {
132 pub result: bool,
133 pub headers: Option<HeaderMap>,
134}