use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
pub struct ResembleProvider {
#[allow(dead_code)]
api_key: String,
#[allow(dead_code)]
base_url: String,
}
impl ResembleProvider {
pub fn new(api_key: &str) -> Self {
Self {
api_key: api_key.to_string(),
base_url: "https://app.resemble.ai/api/v2".to_string(),
}
}
pub fn with_base_url(api_key: &str, base_url: &str) -> Self {
Self {
api_key: api_key.to_string(),
base_url: base_url.to_string(),
}
}
pub fn from_env() -> Result<Self> {
let api_key = std::env::var("RESEMBLE_API_KEY")
.map_err(|_| Error::Configuration("RESEMBLE_API_KEY not set".to_string()))?;
Ok(Self::new(&api_key))
}
pub async fn list_features(&self) -> Result<Vec<String>> {
Ok(vec![
"text-to-speech".to_string(),
"voice-cloning".to_string(),
"speech-to-speech".to_string(),
"neural-audio-editing".to_string(),
])
}
pub fn get_feature_info(feature: &str) -> Option<ResembleFeatureInfo> {
match feature {
"text-to-speech" => Some(ResembleFeatureInfo {
name: feature.to_string(),
description: "Convert text to speech".to_string(),
languages: 24,
features: vec![
"emotion-control".to_string(),
"ssml".to_string(),
"real-time".to_string(),
],
use_cases: vec![
"audiobooks".to_string(),
"podcasts".to_string(),
"games".to_string(),
],
}),
"voice-cloning" => Some(ResembleFeatureInfo {
name: feature.to_string(),
description: "Clone any voice with samples".to_string(),
languages: 24,
features: vec![
"rapid-cloning".to_string(),
"custom-voices".to_string(),
"api-integration".to_string(),
],
use_cases: vec![
"personalization".to_string(),
"brand-voice".to_string(),
"localization".to_string(),
],
}),
"speech-to-speech" => Some(ResembleFeatureInfo {
name: feature.to_string(),
description: "Transform speech to another voice".to_string(),
languages: 10,
features: vec!["voice-conversion".to_string(), "real-time".to_string()],
use_cases: vec!["dubbing".to_string(), "voice-acting".to_string()],
}),
"neural-audio-editing" => Some(ResembleFeatureInfo {
name: feature.to_string(),
description: "Edit audio with AI".to_string(),
languages: 5,
features: vec![
"fill-in".to_string(),
"replace-words".to_string(),
"timing-adjustment".to_string(),
],
use_cases: vec!["post-production".to_string(), "corrections".to_string()],
}),
_ => None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResembleFeatureInfo {
pub name: String,
pub description: String,
pub languages: u32,
pub features: Vec<String>,
pub use_cases: Vec<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_provider_creation() {
let provider = ResembleProvider::new("test-key");
assert!(provider.base_url.contains("resemble.ai"));
}
#[tokio::test]
async fn test_list_features() {
let provider = ResembleProvider::new("test-key");
let features = provider.list_features().await.unwrap();
assert!(features.len() >= 3);
}
#[test]
fn test_feature_info() {
let info = ResembleProvider::get_feature_info("voice-cloning").unwrap();
assert_eq!(info.languages, 24);
}
}