Skip to content

Commit bdb1c68

Browse files
committed
Merge branch 'master' of github.com:arellak/elevenlabs-wrapper
2 parents 22fe1e0 + 44d8ca3 commit bdb1c68

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

src/elevenlabs.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import * as fs from "fs";
22
import * as Path from "path";
33

44
class ElevenLabs {
5+
/**
6+
* Creates an instance of ElevenLabs.
7+
* @param {object} [options={apiKey: "", outputFolder: "./output"}]
8+
* @memberof ElevenLabs
9+
*/
510
constructor(options = {apiKey: "", outputFolder: "./output"}){
611
this.apiKey = options.apiKey;
712
this.apiUrl = "https://api.elevenlabs.io/v1";
@@ -23,6 +28,17 @@ class ElevenLabs {
2328
});
2429
}
2530

31+
32+
/**
33+
*
34+
* @param {string} text
35+
* @param {string} voiceId
36+
* @param {string} [modelId = "eleven_multilingual_v2"]
37+
* @param {object} [voiceSettings = {stability: 0.5, similarity_boost: 0.75}]
38+
* @param {object} [params = {output_format: "mp3_44100_128", optimize_streaming_latency: 0}]
39+
* @return Status message
40+
* @memberof ElevenLabs
41+
*/
2642
async tts(text, voiceId, modelId = "eleven_multilingual_v2", voiceSettings = {stability: 0.5, similarity_boost: 0.75}, params = {output_format: "mp3_44100_128", optimize_streaming_latency: 0}){
2743
const body = {
2844
text,
@@ -54,6 +70,15 @@ class ElevenLabs {
5470
return `File written successfully: ${fileName}`;
5571
}
5672

73+
74+
/**
75+
*
76+
* @param {string} name
77+
* @param {array} filePaths
78+
* @param {object} [optionalSettings={}]
79+
* @return voiceId
80+
* @memberof ElevenLabs
81+
*/
5782
async addVoice(name, filePaths, optionalSettings = {}){
5883
const formData = new FormData();
5984

@@ -78,6 +103,15 @@ class ElevenLabs {
78103
return response;
79104
}
80105

106+
107+
/**
108+
*
109+
* @param {string} name
110+
* @param {string} voiceId
111+
* @param {object} [optionalSettings = {}]
112+
* @return status message
113+
* @memberof ElevenLabs
114+
*/
81115
async editVoice(name, voiceId, optionalSettings = {}){
82116
const formData = new FormData();
83117

@@ -104,11 +138,23 @@ class ElevenLabs {
104138
return response;
105139
}
106140

141+
142+
/**
143+
*
144+
* @return remaining letters you have left in your subscription
145+
* @memberof ElevenLabs
146+
*/
107147
async getRemainingLetters(){
108148
const userInfo = await this.getUserInfo();
109149
return userInfo === undefined ? undefined : userInfo.subscription.character_limit - userInfo.subscription.character_count;
110150
}
111151

152+
153+
/**
154+
*
155+
* @return all the models that are available
156+
* @memberof ElevenLabs
157+
*/
112158
async getModels(){
113159
return await fetch(`${this.apiUrl}/models`, {
114160
method: "GET",
@@ -121,6 +167,12 @@ class ElevenLabs {
121167
});
122168
}
123169

170+
171+
/**
172+
*
173+
* @return all the voices including the custom ones and the default ones
174+
* @memberof ElevenLabs
175+
*/
124176
async getVoices(){
125177
return await fetch(`${this.apiUrl}/voices`, {
126178
method: "GET",
@@ -133,6 +185,12 @@ class ElevenLabs {
133185
});
134186
}
135187

188+
189+
/**
190+
*
191+
* @return all the voices you created
192+
* @memberof ElevenLabs
193+
*/
136194
async getCustomVoices(){
137195
const voices = await fetch(`${this.apiUrl}/voices`, {
138196
method: "GET",
@@ -145,6 +203,12 @@ class ElevenLabs {
145203
return voices.voices.filter((voice) => voice.category === "cloned");
146204
}
147205

206+
207+
/**
208+
*
209+
* @return all the voice ids of voices you created
210+
* @memberof ElevenLabs
211+
*/
148212
async getCustomVoiceIds(){
149213
const voices = await this.getCustomVoices();
150214
return voices.map((voice) => {
@@ -155,6 +219,12 @@ class ElevenLabs {
155219
});
156220
}
157221

222+
223+
/**
224+
*
225+
* @return default settings for voices
226+
* @memberof ElevenLabs
227+
*/
158228
async getDefaultVoiceSettings(){
159229
return await fetch(`${this.apiUrl}/voices/settings/default`, {
160230
method: "GET",
@@ -164,6 +234,13 @@ class ElevenLabs {
164234
}).then((response) => response.json());
165235
}
166236

237+
238+
/**
239+
*
240+
* @param {string} voiceId
241+
* @return settings for a specific voice
242+
* @memberof ElevenLabs
243+
*/
167244
async getVoiceSettings(voiceId){
168245
return await fetch(`${this.apiUrl}/voices/${voiceId}/settings`, {
169246
method: "GET",
@@ -174,6 +251,14 @@ class ElevenLabs {
174251
}).then((response) => response.json());
175252
}
176253

254+
255+
/**
256+
*
257+
* @param {object} settings
258+
* @param {string} voiceId
259+
* @return status message
260+
* @memberof ElevenLabs
261+
*/
177262
async editVoiceSettings(settings, voiceId){
178263
return await fetch(`${this.apiUrl}/voices/${voiceId}/settings/edit`, {
179264
method: "POST",
@@ -186,6 +271,13 @@ class ElevenLabs {
186271
}).then((response) => response.json());
187272
}
188273

274+
275+
/**
276+
*
277+
* @param {string} voiceId
278+
* @return a specific voice object
279+
* @memberof ElevenLabs
280+
*/
189281
async getVoice(voiceId){
190282
return await fetch(`${this.apiUrl}/voices/${voiceId}?with_settings=false`, {
191283
method: "GET",
@@ -196,6 +288,13 @@ class ElevenLabs {
196288
}).then((response) => response.json());
197289
}
198290

291+
292+
/**
293+
*
294+
* @param {string} voiceId
295+
* @return status message
296+
* @memberof ElevenLabs
297+
*/
199298
async deleteVoice(voiceId){
200299
return await fetch(`${this.apiUrl}/voices/${voiceId}`, {
201300
method: "DELETE",
@@ -206,6 +305,13 @@ class ElevenLabs {
206305
}).then((response) => response.json());
207306
}
208307

308+
309+
/**
310+
*
311+
* @param {string} voiceId
312+
* @return all the sample ids of a specific voice
313+
* @memberof ElevenLabs
314+
*/
209315
async getSampleIds(voiceId){
210316
const voice = await this.getVoice(voiceId);
211317
return voice.samples.map((sample) => {
@@ -216,6 +322,14 @@ class ElevenLabs {
216322
});
217323
}
218324

325+
326+
/**
327+
*
328+
* @param {string} voiceId
329+
* @param {string} sampleId
330+
* @return status message
331+
* @memberof ElevenLabs
332+
*/
219333
async getAudioFromSample(voiceId, sampleId){
220334
const response = await fetch(`${this.apiUrl}/voices/${voiceId}/samples/${sampleId}/audio`, {
221335
method: "GET",
@@ -241,6 +355,14 @@ class ElevenLabs {
241355
return `File written successfully: ${fileName}`;
242356
}
243357

358+
359+
/**
360+
*
361+
* @param {string} voiceId
362+
* @param {string} sampleId
363+
* @return status message
364+
* @memberof ElevenLabs
365+
*/
244366
async deleteSample(voiceId, sampleId){
245367
return await fetch(`${this.apiUrl}/voices/${voiceId}/samples/${sampleId}`, {
246368
method: "DELETE",
@@ -251,6 +373,12 @@ class ElevenLabs {
251373
}).then((response) => response.json());
252374
}
253375

376+
377+
/**
378+
*
379+
* @return history object
380+
* @memberof ElevenLabs
381+
*/
254382
async getHistory(){
255383
return await fetch(`${this.apiUrl}/history`, {
256384
method: "GET",
@@ -261,6 +389,13 @@ class ElevenLabs {
261389
}).then((response) => response.json());
262390
}
263391

392+
393+
/**
394+
*
395+
* @param {string} historyItemId
396+
* @return history item object
397+
* @memberof ElevenLabs
398+
*/
264399
async getHistoryItem(historyItemId){
265400
return await fetch(`${this.apiUrl}/history/${historyItemId}`, {
266401
method: "GET",
@@ -271,6 +406,13 @@ class ElevenLabs {
271406
}).then((response) => response.json());
272407
}
273408

409+
410+
/**
411+
*
412+
* @param {string} historyItemId
413+
* @return status message
414+
* @memberof ElevenLabs
415+
*/
274416
async getAudioFromHistoryItem(historyItemId){
275417
const response = await fetch(`${this.apiUrl}/history/${historyItemId}/audio`, {
276418
method: "GET",
@@ -296,6 +438,13 @@ class ElevenLabs {
296438
return `File written successfully: ${fileName}`;
297439
}
298440

441+
442+
/**
443+
*
444+
* @param {string} historyItemId
445+
* @return status message
446+
* @memberof ElevenLabs
447+
*/
299448
async deleteHistoryItem(historyItemId){
300449
return await fetch(`${this.apiUrl}/history/${historyItemId}`, {
301450
method: "DELETE",
@@ -306,6 +455,13 @@ class ElevenLabs {
306455
}).then((response) => response.json());
307456
}
308457

458+
459+
/**
460+
*
461+
* @param {array} historyItemIds
462+
* @return status message
463+
* @memberof ElevenLabs
464+
*/
309465
async downloadHistoryItems(historyItemIds){
310466
const response = await fetch(`${this.apiUrl}/history/download`, {
311467
method: "POST",
@@ -336,6 +492,12 @@ class ElevenLabs {
336492
return `File written successfully: ${fileName}`;
337493
}
338494

495+
496+
/**
497+
*
498+
* @return user object
499+
* @memberof ElevenLabs
500+
*/
339501
async getUserInfo(){
340502
return await fetch(`${this.apiUrl}/user`, {
341503
method: "GET",
@@ -346,6 +508,12 @@ class ElevenLabs {
346508
}).then((response) => response.json());
347509
}
348510

511+
512+
/**
513+
*
514+
* @return subscription object
515+
* @memberof ElevenLabs
516+
*/
349517
async getUserSubscriptionInfo(){
350518
return await fetch(`${this.apiUrl}/user/subscription`, {
351519
method: "GET",

0 commit comments

Comments
 (0)