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