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