ai/
voice.rs

1use clap::{Args,Subcommand};
2use serde::{Serialize,Deserialize};
3use derive_more::From;
4use std::path::PathBuf;
5use reqwest::{Client};
6use crate::eleven_labs::voice::{ElevenLabsListCommand,ElevenLabsGenerateCommand,ElevenLabsVoiceError};
7use crate::Config;
8
9#[derive(Args)]
10pub struct VoiceCommand {
11    #[command(subcommand)]
12    pub command: Voice,
13}
14
15#[derive(Subcommand)]
16pub enum Voice {
17    List(VoiceList),
18    Generate(VoiceGenerate)
19}
20
21#[derive(Args, Clone, Default, Debug, Serialize, Deserialize)]
22pub struct VoiceList {
23    #[arg(long, short, default_value_t = false)]
24    pub verbose: bool,
25
26    #[arg(long, short, default_value_t = false)]
27    pub quiet: bool
28}
29
30#[derive(Args, Clone, Default, Debug, Serialize, Deserialize)]
31pub struct VoiceGenerate {
32    /// The text to transcribe to a voice
33    pub text: String,
34
35    #[arg(long, short)]
36    pub out: PathBuf,
37
38    /// The name of the voice to use, run the list command to see your options
39    #[arg(long, short)]
40    pub voice: String,
41
42    #[arg(long)]
43    pub voice_stability: Option<usize>,
44
45    #[arg(long)]
46    pub voice_similarity_boost: Option<usize>,
47}
48
49impl Voice {
50    pub async fn run(&self, client: &Client, config: &Config) -> VoiceResult {
51        match self {
52            Self::List(list) => {
53                let command = ElevenLabsListCommand::try_from(list.clone())?;
54                command.run(client, &config).await?;
55                Ok(())
56            },
57            Self::Generate(generate) => {
58                let command = ElevenLabsGenerateCommand::try_from(generate.clone())?;
59                command.run(client, &config).await?;
60                Ok(())
61            }
62        }
63    }
64}
65
66#[derive(Debug, From)]
67pub enum VoiceError {
68    InvalidArguments(String),
69    ElevenLabsVoiceError(ElevenLabsVoiceError),
70    NetworkError(reqwest::Error),
71    IOError(std::io::Error),
72    Serde(serde_json::Error),
73    Unauthorized
74}
75
76pub type VoiceResult = Result<(), VoiceError>;