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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//! Voice design endpoints
//!
//! # Voice Design Guide From Official Documentation
//!
//! ## Voice Design Types
//!
//! - **Realistic Voice Design**: Create original, realistic voices by specifying attributes like age, accent/nationality, gender, tone, pitch, intonation, speed, and emotion.
//!
//! Example prompts:
//! - "A young Indian female with a soft, high voice. Conversational, slow, and calm."
//! - "An old British male with a raspy, deep voice. Professional, relaxed, and assertive."
//! - "A middle-aged Australian female with a warm, low voice. Corporate, fast, and happy."
//!
//! - **Character Voice Design**: Generate unique voices for creative characters using simpler prompts.
//!
//! Example prompts:
//! - "A massive evil ogre, troll."
//! - "A sassy little squeaky mouse."
//! - "An angry old pirate, shouting."
//!
//! Other creative character ideas include Goblin, Vampire, Elf, Troll, Werewolf, Ghost, Alien, Giant, Witch, Wizard, Zombie, Demon, Pirate, Genie, Ogre, Orc, Knight, Samurai, etc.
//!
//! ## Voice Attributes
//!
//! When designing a voice, the following attributes can be customized:
//!
//! - **Age** (High Importance): Young, Teenage, Adult, Middle-Aged, Old, etc.
//! - **Accent/Nationality** (High Importance): British, Indian, Polish, American, etc.
//! - **Gender** (High Importance): Male, Female, Gender Neutral.
//! - **Tone** (Optional): Gruff, Soft, Warm, Raspy, etc.
//! - **Pitch** (Optional): Deep, Low, High, Squeaky, etc.
//! - **Intonation** (Optional): Conversational, Professional, Corporate, Urban, Posh, etc.
//! - **Speed** (Optional): Fast, Quick, Slow, Relaxed, etc.
//! - **Emotion/Delivery** (Optional): Angry, Calm, Scared, Happy, Assertive, Whispering, Shouting, etc.
//!
//! For further reading, check the official [voice design guide documentation](https://elevenlabs.io/docs/voices/voice-lab/voice-design)
//!
//!
//! ## Example
//! ```no_run
//! use elevenlabs_rs::*;
//! use elevenlabs_rs::utils::save;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let c = ElevenLabsClient::default()?;
//!
//! // Create a new voice preview for a whimsical, mischievous fairy character
//! let body = CreatePreviewsBody::new(
//! "A mischievous fairy with a playful and curious voice",
//!
//! "Hee-hee! I bet you can't catch me! Oh, look at all the sparkles and glowing lights! /
//! I fly faster than the wind, always tricking and teasing. /
//! Come play with me in the forest! But beware, I love a good prank or two! /
//! I might sprinkle pixie dust in your hair, or hide your shoes, just for fun! /
//! What a delightful day to play tricks and spread a little mischief! /
//! No one will ever see me coming, hee-hee!",
//! );
//!
//! let voice_previews = c.hit(CreatePreviews::new(body)).await?;
//!
//! for (i, preview) in voice_previews.enumerate() {
//! let id = preview.generated_voice_id();
//! let sample = preview.audio_sample()?;
//! save(&format!("fairy_sample_{}_{}.mp3", i, id), sample)?;
//! }
//!
//! Ok(())
//! }
//! ```
use HashMap;
use *;
const CREATE_PREVIEW_PATH: &str = "/v1/text-to-voice/create-previews";
const CREATE_VOICE_FROM_PREVIEW_PATH: &str = "/v1/text-to-voice/create-voice-from-preview";
/// Create previews of voices from a text
///
///
/// ## Official Documentation
/// "Generate custom voice previews based on provided voice description.
/// The response includes a list of voice previews, each containing an
/// id and a sample of the voice audio."
///
/// For further reading, check the official [create previews API reference](https://elevenlabs.io/docs/api-reference/ttv-create-previews)
///
/// ## Example
/// ```no_run
/// use elevenlabs_rs::*;
/// use elevenlabs_rs::utils::save;
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// let c = ElevenLabsClient::default()?;
/// let body = CreatePreviewsBody::new(
/// "The chief orc of a fearsome army",
///
/// "Mwahahaha, marvel at my magic ye mortals! /
/// My incantation masters sound everywhere I go!
/// Mwahahaha, Mwahahaha",
/// );
///
/// let voice_previews = c.hit(CreatePreviews::new(body)).await?;
///
/// for (i, preview) in voice_previews.enumerate() {
/// let id = preview.generated_voice_id();
/// let sample = preview.audio_sample()?;
/// save(&format!("sample_{}_{}.mp3", i, id), sample)?;
/// }
/// Ok(())
/// }
/// ```
///
/// # Note
/// The text must be at least 100 characters long and at most 1000 characters long.
;
/// Create a voice from a preview
///
/// ## Official Documentation
///
/// "Create a new voice from previously generated voice preview.
/// This endpoint should be called after you fetched a generated_voice_id using /v1/text-to-voice/create-previews.". i.e. `CreatePreviews`
///
/// For further reading, check the official [create voice from preview API reference](https://elevenlabs.io/docs/api-reference/ttv-create-voice-from-preview)
///
/// ## Example
/// ```no_run
/// use elevenlabs_rs::*;
/// use std::collections::HashMap;
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// let c = ElevenLabsClient::default()?;
/// let name = "Anubis";
/// let voice_description = "The chief orc of a fearsome army";
/// let some_id = "generated_voice_id";
/// let mut body = CreateVoiceFromPreviewBody::new(name, voice_description, some_id);
/// let mut labels = HashMap::new();
/// labels.insert("language".to_string(), "en".into());
/// body.with_labels(labels);
/// let resp = c.hit(CreateVoiceFromPreview::new(body)).await?;
/// println!("{:?}", resp);
/// Ok(())
/// }
/// ```
/// # Note
/// The `generated_voice_id` must be from a call to `CreatePreviews`
;
//#[derive(Clone, Debug, Deserialize, Serialize)]
//pub struct CreateVoiceFromPreviewResponse {
// voice_id: String,
//}