use serde::{ Deserialize, Serialize };
#[ derive( Debug, Clone ) ]
pub enum AudioInput
{
Bytes( Vec< u8 > ),
Base64( String ),
Url( String ),
}
impl AudioInput
{
#[ inline ]
#[ must_use ]
pub fn from_bytes( bytes : Vec< u8 > ) -> Self
{
Self::Bytes( bytes )
}
#[ inline ]
#[ must_use ]
pub fn from_base64( data : impl Into< String > ) -> Self
{
Self::Base64( data.into() )
}
#[ inline ]
#[ must_use ]
pub fn from_url( url : impl Into< String > ) -> Self
{
Self::Url( url.into() )
}
#[ inline ]
#[ must_use ]
pub fn to_base64( &self ) -> String
{
match self
{
Self::Bytes( bytes ) => base64_encode( bytes ),
Self::Base64( data ) => data.clone(),
Self::Url( url ) => url.clone(), }
}
}
fn base64_encode( bytes : &[ u8 ] ) -> String
{
use base64::{ Engine, engine::general_purpose };
general_purpose::STANDARD.encode( bytes )
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct TranscriptionResult
{
pub text : String,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct AudioClassificationResult
{
pub label : String,
pub score : f64,
}
#[ derive( Debug, Clone ) ]
pub struct SpeechGenerationResult
{
pub audio_data : Vec< u8 >,
pub sample_rate : Option< u32 >,
pub format : Option< String >,
}
#[ derive( Debug, Clone ) ]
pub struct AudioTransformResult
{
pub audio_data : Vec< u8 >,
pub sample_rate : Option< u32 >,
pub format : Option< String >,
}