zai_rs/model/text_to_audio/
data.rs1use serde::Serialize;
2
3use super::{
4 super::traits::*,
5 request::{TextToAudioBody, TtsAudioFormat, Voice},
6};
7use crate::client::http::HttpClient;
8
9pub struct TextToAudioRequest<N>
11where
12 N: ModelName + TextToAudio + Serialize,
13{
14 pub key: String,
15 body: TextToAudioBody<N>,
16}
17
18impl<N> TextToAudioRequest<N>
19where
20 N: ModelName + TextToAudio + Serialize,
21{
22 pub fn new(model: N, key: String) -> Self {
23 let body = TextToAudioBody::new(model);
24 Self { key, body }
25 }
26
27 pub fn body_mut(&mut self) -> &mut TextToAudioBody<N> {
28 &mut self.body
29 }
30
31 pub fn with_input(mut self, input: impl Into<String>) -> Self {
32 self.body = self.body.with_input(input);
33 self
34 }
35 pub fn with_voice(mut self, voice: Voice) -> Self {
36 self.body = self.body.with_voice(voice);
37 self
38 }
39 pub fn with_speed(mut self, speed: f32) -> Self {
40 self.body = self.body.with_speed(speed);
41 self
42 }
43 pub fn with_volume(mut self, volume: f32) -> Self {
44 self.body = self.body.with_volume(volume);
45 self
46 }
47 pub fn with_response_format(mut self, fmt: TtsAudioFormat) -> Self {
48 self.body = self.body.with_response_format(fmt);
49 self
50 }
51 pub fn with_watermark_enabled(mut self, enabled: bool) -> Self {
52 self.body = self.body.with_watermark_enabled(enabled);
53 self
54 }
55}
56
57impl<N> HttpClient for TextToAudioRequest<N>
58where
59 N: ModelName + TextToAudio + Serialize,
60{
61 type Body = TextToAudioBody<N>;
62 type ApiUrl = &'static str;
63 type ApiKey = String;
64
65 fn api_url(&self) -> &Self::ApiUrl {
66 &"https://open.bigmodel.cn/api/paas/v4/audio/speech"
67 }
68 fn api_key(&self) -> &Self::ApiKey {
69 &self.key
70 }
71 fn body(&self) -> &Self::Body {
72 &self.body
73 }
74}