async_dashscope/operation/
audio.rs1use crate::{error::DashScopeError, operation::audio::tts::output::TextToSpeechOutputStream, Client};
2use crate::{error::Result, operation::audio::tts::output::TextToSpeechOutput};
3pub use tts::param::{
4 Input as TextToSpeechInput, InputBuilder as TextToSpeechInputBuilder, TextToSpeechParam,
5 TextToSpeechParamBuilder,
6};
7mod tts;
8
9const AUDIO_PATH: &str = "/services/aigc/multimodal-generation/generation";
10
11pub struct Audio<'a> {
12 client: &'a Client,
13}
14
15impl<'a> Audio<'a> {
16 pub fn new(client: &'a Client) -> Self {
17 Self { client }
18 }
19
20 pub async fn tts(&self, request: TextToSpeechParam) -> Result<TextToSpeechOutput> {
27 if request.stream == Some(true) {
29 return Err(DashScopeError::InvalidArgument(
30 "When stream is true, use Audio::call_stream".into(),
31 ));
32 }
33 self.client.post(AUDIO_PATH, request).await
34 }
35
36 pub async fn tts_stream(&self, request: TextToSpeechParam) -> Result<TextToSpeechOutputStream> {
37 if request.stream == Some(false) {
39 return Err(DashScopeError::InvalidArgument(
40 "When stream is false, use Audio::call".into(),
41 ));
42 }
43 self.client.post_stream(AUDIO_PATH, request).await
44 }
45}