Skip to main content

rig_core/client/
minimax_voice_clone.rs

1//! The verbs of a MiniMax [`VoiceClones`] model. Each is one call through
2//! the driver.
3
4use crate::driver::{Model, Transport};
5use crate::error::ProviderError;
6use crate::providers::minimax::voice_clone::{
7    CloneAudio, ClonedVoice, UploadedFile, VoiceClone, VoiceCloneRequest, VoiceClones,
8};
9
10impl<T> Model<VoiceClones, T>
11where
12    T: Transport<VoiceClones>,
13{
14    /// Upload `audio` and return the stored file.
15    pub async fn upload(&self, audio: CloneAudio) -> Result<UploadedFile, ProviderError> {
16        self.call(VoiceCloneRequest::Upload(audio))
17            .await?
18            .file
19            .ok_or_else(|| ProviderError::Response("MiniMax's upload reply named no file".into()))
20    }
21
22    /// Clone a sample as a new voice.
23    pub async fn clone_voice(&self, clone: VoiceClone) -> Result<ClonedVoice, ProviderError> {
24        let voice_id = clone.created_voice_id().to_owned();
25        let reply = self.call(VoiceCloneRequest::Clone(clone)).await?;
26        Ok(ClonedVoice {
27            voice_id,
28            demo_audio: reply.demo_audio.filter(|url| !url.is_empty()),
29            extra_info: reply.extra_info,
30        })
31    }
32}