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