From e36780a944078223fa85c3d0cf79c3cbdce10358 Mon Sep 17 00:00:00 2001 From: Felix Waweru Date: Mon, 25 Sep 2023 18:14:34 +0000 Subject: [PATCH 01/29] feat: v2 endpoint --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index c1dace5..d0eb096 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const axios = require("axios"); const fs = require("fs-extra"); const elevenLabsAPI = "https://api.elevenlabs.io/v1"; +const elevenLabsAPIV2 = "https://api.elevenlabs.io/v2"; /** From 96dd6667eb22cd0a10325c8fbc034e8ad51f66cd Mon Sep 17 00:00:00 2001 From: Felix Waweru Date: Sat, 14 Oct 2023 15:04:36 +0000 Subject: [PATCH 02/29] feat: added variable constructor --- index.js | 166 ++++++++++++++++++++++++------------------------------- 1 file changed, 72 insertions(+), 94 deletions(-) diff --git a/index.js b/index.js index d0eb096..dbf915b 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,41 @@ const axios = require("axios"); const fs = require("fs-extra"); -const elevenLabsAPI = "https://api.elevenlabs.io/v1"; +const elevenLabsAPIV1 = "https://api.elevenlabs.io/v1"; const elevenLabsAPIV2 = "https://api.elevenlabs.io/v2"; + +/** +Creates an instance of ElevenLabs. +@param {Object} - An object containing the API Key and API Version [default: ElevenLabs V1]. +*/ +function ElevenLabs(options = { + apiKey: "", + apiVersion: "" + }) { + + this.apiKey = options.apiKey ? options.apiKey : ""; + + switch(options.apiVersion) { + case "V1": + this.apiVersion = elevenLabsAPIV1; + break; + case "V2": + this.apiVersion = elevenLabsAPIV2; + break; + case "": + this.apiVersion = elevenLabsAPIV1; + break; + default: + console.log("Invalid Version"); + break; + } + } + + /** Function that converts text to speech and saves the audio file to the specified file name. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @param {string} fileName - The name of the file to save the audio data to. @@ -23,21 +50,20 @@ Function that converts text to speech and saves the audio file to the specified @returns {Object} - An object containing the status of the operation. */ -const textToSpeech = async ( - apiKey, +ElevenLabs.prototype.textToSpeech = async function ( voiceID, fileName, textInput, stability, similarityBoost, modelId -) => { +) { try { - if (!apiKey || !voiceID || !fileName || !textInput) { + if (!voiceID || !fileName || !textInput) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/text-to-speech/${voiceID}`; + const voiceURL = `${this.apiVersion}/text-to-speech/${voiceID}`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; @@ -54,7 +80,7 @@ const textToSpeech = async ( }, headers: { Accept: "audio/mpeg", - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, "Content-Type": "application/json", }, responseType: "stream", @@ -80,8 +106,6 @@ const textToSpeech = async ( Function that converts text to speech and returns a readable stream of the audio data. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @param {string} textInput - The text to convert to speech. @@ -96,21 +120,20 @@ Function that converts text to speech and returns a readable stream of the audio @returns {Object} - A readable stream of the audio data. */ -const textToSpeechStream = async ( - apiKey, +ElevenLabs.prototype.textToSpeechStream = async function ( voiceID, textInput, stability, similarityBoost, modelId, responseType -) => { +) { try { - if (!apiKey || !voiceID || !textInput) { + if (!voiceID || !textInput) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/text-to-speech/${voiceID}/stream`; + const voiceURL = `${this.apiVersion}/text-to-speech/${voiceID}/stream`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; @@ -127,7 +150,7 @@ const textToSpeechStream = async ( }, headers: { Accept: "audio/mpeg", - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, "Content-Type": "application/json", }, responseType: responseType ? responseType : "stream" @@ -143,23 +166,17 @@ const textToSpeechStream = async ( Function that returns an object containing the details for all the voices. -@param {string} apiKey - The API key to authenticate the request. - @returns {Object} - An object containing the list of voices and their details. */ -const getVoices = async (apiKey) => { +ElevenLabs.prototype.getVoices = async function () { try { - if (!apiKey) { - console.log("ERR: Missing parameter"); - } - - const voiceURL = `${elevenLabsAPI}/voices`; + const voiceURL = `${this.apiVersion}/voices`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -175,9 +192,9 @@ Function that returns an object containing the default settings for the voices. @returns {Object} - An object containing the default settings for the voices. */ -const getDefaultVoiceSettings = async () => { +ElevenLabs.prototype.getDefaultVoiceSettings = async function () { try { - const voiceURL = `${elevenLabsAPI}/voices/settings/default`; + const voiceURL = `${this.apiVersion}/voices/settings/default`; const response = await axios({ method: "GET", @@ -194,25 +211,23 @@ const getDefaultVoiceSettings = async () => { Function that returns an object containing the settings of the specified voice. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the settings of the specified voice. */ -const getVoiceSettings = async (apiKey, voiceID) => { +ElevenLabs.prototype.getVoiceSettings = async function (voiceID) { try { - if (!apiKey || !voiceID) { + if (!voiceID) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}/settings`; + const voiceURL = `${this.apiVersion}/voices/${voiceID}/settings`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -226,25 +241,23 @@ const getVoiceSettings = async (apiKey, voiceID) => { Function that returns an object containing the details of the specified voice. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the details of the specified voice. */ -const getVoice = async (apiKey, voiceID) => { +ElevenLabs.prototype.getVoice = async function (voiceID) { try { - if (!apiKey || !voiceID) { + if (!voiceID) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; + const voiceURL = `${this.apiVersion}/voices/${voiceID}`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -258,25 +271,23 @@ const getVoice = async (apiKey, voiceID) => { Function that returns an object containing the status of the delete operation. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the status of the delete operation. */ -const deleteVoice = async (apiKey, voiceID) => { +ElevenLabs.prototype.deleteVoice = async function (voiceID) { try { - if (!apiKey || !voiceID) { + if (!voiceID) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; + const voiceURL = `${this.apiVersion}/voices/${voiceID}`; const response = await axios({ method: "DELETE", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -290,8 +301,6 @@ const deleteVoice = async (apiKey, voiceID) => { Function that returns an object containing the status of the edit operation. -@param {string} apiKey - The API key to authenticate the request. - @param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. @param {number} stability - The stability setting for the voice. @@ -300,18 +309,17 @@ Function that returns an object containing the status of the edit operation. @returns {Object} - An object containing the status of the edit operation. */ -const editVoiceSettings = async ( - apiKey, +ElevenLabs.prototype.editVoiceSettings = async function ( voiceID, stability, similarityBoost -) => { +) { try { - if (!apiKey || !voiceID) { + if (!voiceID) { console.log("ERR: Missing parameter"); } - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}/settings/edit`; + const voiceURL = `${this.apiVersion}/voices/${voiceID}/settings/edit`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; @@ -323,7 +331,7 @@ const editVoiceSettings = async ( similarity_boost: similarityBoostValue, }, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -337,23 +345,17 @@ const editVoiceSettings = async ( Function that returns an object containing the list of voice models. -@param {string} apiKey - The API key to authenticate the request. - @returns {Object} - An object containing the list of voice models and their details. */ -const getModels = async (apiKey) => { +ElevenLabs.prototype.getModels = async function () { try { - if (!apiKey) { - console.log("ERR: Missing parameter"); - } - - const voiceURL = `${elevenLabsAPI}/models`; + const voiceURL = `${this.apiVersion}/models`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -367,23 +369,17 @@ const getModels = async (apiKey) => { Function that returns the user details. -@param {string} apiKey - The API key to authenticate the request. - @returns {Object} - An object containing the user details. */ -const getUserInfo = async (apiKey) => { +ElevenLabs.prototype.getUserInfo = async function () { try { - if (!apiKey) { - console.log("ERR: Missing parameter"); - } - - const voiceURL = `${elevenLabsAPI}/user`; + const voiceURL = `${this.apiVersion}/user`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -397,23 +393,17 @@ const getUserInfo = async (apiKey) => { Function that returns the user subscription details. -@param {string} apiKey - The API key to authenticate the request. - @returns {Object} - An object containing the user subscription details. */ -const getUserSubscription = async (apiKey) => { +ElevenLabs.prototype.getUserSubscription = async function () { try { - if (!apiKey) { - console.log("ERR: Missing parameter"); - } - - const voiceURL = `${elevenLabsAPI}/user/subscription`; + const voiceURL = `${this.apiVersion}/user/subscription`; const response = await axios({ method: "GET", url: voiceURL, headers: { - "xi-api-key": apiKey, + "xi-api-key": this.apiKey, }, }); @@ -423,16 +413,4 @@ const getUserSubscription = async (apiKey) => { } }; -module.exports = { - textToSpeech: textToSpeech, - textToSpeechStream: textToSpeechStream, - getVoices: getVoices, - getDefaultVoiceSettings: getDefaultVoiceSettings, - getVoiceSettings: getVoiceSettings, - getVoice: getVoice, - deleteVoice: deleteVoice, - editVoiceSettings: editVoiceSettings, - getModels: getModels, - getUserInfo: getUserInfo, - getUserSubscription: getUserSubscription, -}; +module.exports = ElevenLabs; From 84d1f255b05e678dec2dfda4de73fba50d2a3a09 Mon Sep 17 00:00:00 2001 From: Felix Waweru Date: Sat, 14 Oct 2023 15:14:54 +0000 Subject: [PATCH 03/29] feat: updated test file --- test/app.test.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index de2764a..d7332a9 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,4 +1,4 @@ -const script = require('../index.js'); +const ElevenLabs = require('../index.js'); const apiKey = process.env.ELEVENLABS_API_KEY; const voiceID = process.env.ELEVENLABS_VOICE_ID; @@ -9,13 +9,20 @@ const similarityBoost = '0.5'; const modelId = 'eleven_multilingual_v1'; const responseType = 'stream'; +const script = new ElevenLabs( + { + apiKey: apiKey, + apiVersion: "V1" + } +); + describe("Eleven Labs Node Unit Test", () => { // textToSpeech test test("Test textToSpeech", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeech(apiKey, voiceID, fileName, textInput, stability, similarityBoost, modelId); + const response = await script.textToSpeech(voiceID, fileName, textInput, stability, similarityBoost, modelId); // Response check expect(response.status).toEqual('ok'); @@ -25,7 +32,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeechStream", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeechStream(apiKey, voiceID, textInput, stability, similarityBoost, modelId, responseType); + const response = await script.textToSpeechStream(voiceID, textInput, stability, similarityBoost, modelId, responseType); // Response check expect(!response).toBeFalsy(); @@ -35,7 +42,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoices", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoices(apiKey); + const response = await script.getVoices(); // Response check expect(response.voices).toBeTruthy(); @@ -56,7 +63,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoiceSettings(apiKey, voiceID); + const response = await script.getVoiceSettings(voiceID); // Response check expect(response.stability).toBeTruthy(); @@ -67,7 +74,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoice", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoice(apiKey, voiceID); + const response = await script.getVoice(voiceID); // Response check expect(response.voice_id).toBeTruthy(); @@ -77,7 +84,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test editVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.editVoiceSettings(apiKey, voiceID, stability, similarityBoost); + const response = await script.editVoiceSettings(voiceID, stability, similarityBoost); // Response check expect(response.status).toEqual('ok'); @@ -87,7 +94,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getModels", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getModels(apiKey); + const response = await script.getModels(); // Response check expect(response).toBeTruthy(); @@ -97,7 +104,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getUserInfo", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getUserInfo(apiKey); + const response = await script.getUserInfo(); // Response check expect(response.xi_api_key).toEqual(apiKey); @@ -107,19 +114,9 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getUserSubscription", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getUserSubscription(apiKey); + const response = await script.getUserSubscription(); // Response check expect(response.status).toBeTruthy(); }); - - // deleteVoice test - // TODO: Add create voice test first - // test("Test deleteVoice", async () => { - // // Execute test - // const response = await script.deleteVoice(apiKey, voiceID); - - // // Response check - // expect(response.status).toEqual('ok'); - // }); }); \ No newline at end of file From 9f8be73252f15a2d3561708728bf3bf2068b6468 Mon Sep 17 00:00:00 2001 From: Felix Waweru Date: Sat, 14 Oct 2023 15:15:20 +0000 Subject: [PATCH 04/29] feat: updated semver and test command --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a881de4..40ad86c 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "elevenlabs-node", - "version": "1.2.0", + "version": "2.0.0", "description": "This is an open source Eleven Labs NodeJS package for converting text to speech using the Eleven Labs API", "main": "index.js", "scripts": { - "test": "jest --testPathPattern=test --detectOpenHandles --forceExit" + "test": "jest --testPathPattern=test --forceExit" }, "repository": { "type": "git", From 140e2b0d02a1c4e553913ccf39489bb9afd418f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:19:20 +0300 Subject: [PATCH 05/29] feat: added speaker boost and variable constructor --- index.js | 546 +++++++++++++++++++++++++++---------------------------- 1 file changed, 269 insertions(+), 277 deletions(-) diff --git a/index.js b/index.js index dbf915b..3434986 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ const axios = require("axios"); const fs = require("fs-extra"); const elevenLabsAPIV1 = "https://api.elevenlabs.io/v1"; -const elevenLabsAPIV2 = "https://api.elevenlabs.io/v2"; /** @@ -9,35 +8,19 @@ Creates an instance of ElevenLabs. @param {Object} - An object containing the API Key and API Version [default: ElevenLabs V1]. */ function ElevenLabs(options = { - apiKey: "", - apiVersion: "" - }) { + apiKey: "", + voiceId: "" +}) { this.apiKey = options.apiKey ? options.apiKey : ""; - - switch(options.apiVersion) { - case "V1": - this.apiVersion = elevenLabsAPIV1; - break; - case "V2": - this.apiVersion = elevenLabsAPIV2; - break; - case "": - this.apiVersion = elevenLabsAPIV1; - break; - default: - console.log("Invalid Version"); - break; - } - } + this.voiceId = options.voiceId ? options.voiceId : "ErXwobaYiN019PkySvjV"; +} /** Function that converts text to speech and saves the audio file to the specified file name. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. - @param {string} fileName - The name of the file to save the audio data to. @param {string} textInput - The text to convert to speech. @@ -48,66 +31,72 @@ Function that converts text to speech and saves the audio file to the specified @param {string} modelId - The model to use for the text-to-speech conversion. If null, it will use elevenlab's default model. +@param {boolean} speakerBoost - The speaker boost setting for the voice. + @returns {Object} - An object containing the status of the operation. */ -ElevenLabs.prototype.textToSpeech = async function ( - voiceID, - fileName, - textInput, - stability, - similarityBoost, - modelId +ElevenLabs.prototype.textToSpeech = async function( + fileName, + textInput, + stability, + similarityBoost, + modelId, + speakerBoost ) { - try { - if (!voiceID || !fileName || !textInput) { - console.log("ERR: Missing parameter"); + try { + if (!fileName) { + console.log("ERR: Missing parameter {fileName}"); + } else if (!textInput) { + console.log("ERR: Missing parameter {textInput}"); + } + + const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}`; + const stabilityValue = stability ? stability : 0; + const similarityBoostValue = similarityBoost ? similarityBoost : 0; + + const response = await axios({ + method: "POST", + url: voiceURL, + data: { + text: textInput, + voice_settings: { + stability: stabilityValue, + similarity_boost: similarityBoostValue, + use_speaker_boost: speakerBoost, + }, + model_id: modelId ? modelId : undefined, + }, + headers: { + Accept: "audio/mpeg", + "xi-api-key": this.apiKey, + "Content-Type": "application/json", + }, + responseType: "stream", + }); + + response.data.pipe(fs.createWriteStream(fileName)); + + const writeStream = fs.createWriteStream(fileName); + response.data.pipe(writeStream); + + return new Promise((resolve, reject) => { + const responseJson = { + status: "ok", + fileName: fileName + }; + writeStream.on('finish', () => resolve(responseJson)); + + writeStream.on('error', reject); + }); + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/text-to-speech/${voiceID}`; - const stabilityValue = stability ? stability : 0; - const similarityBoostValue = similarityBoost ? similarityBoost : 0; - - const response = await axios({ - method: "POST", - url: voiceURL, - data: { - text: textInput, - voice_settings: { - stability: stabilityValue, - similarity_boost: similarityBoostValue, - }, - model_id: modelId ? modelId : undefined, - }, - headers: { - Accept: "audio/mpeg", - "xi-api-key": this.apiKey, - "Content-Type": "application/json", - }, - responseType: "stream", - }); - - response.data.pipe(fs.createWriteStream(fileName)); - - const writeStream = fs.createWriteStream(fileName); - response.data.pipe(writeStream); - - return new Promise((resolve, reject) => { - const responseJson = { status: "ok", fileName: fileName }; - writeStream.on('finish', () => resolve(responseJson)); - - writeStream.on('error', reject); - }); - } catch (error) { - console.log(error); - } }; /** Function that converts text to speech and returns a readable stream of the audio data. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. - @param {string} textInput - The text to convert to speech. @param {number} stability - The stability setting for the voice. @@ -118,48 +107,51 @@ Function that converts text to speech and returns a readable stream of the audio @param {string} responseType - The response type for the text-to-speech function (arrayBuffer, stream, etc). If null, it will use 'stream' by default. +@param {boolean} speakerBoost - The speaker boost setting for the voice. + @returns {Object} - A readable stream of the audio data. */ -ElevenLabs.prototype.textToSpeechStream = async function ( - voiceID, - textInput, - stability, - similarityBoost, - modelId, - responseType +ElevenLabs.prototype.textToSpeechStream = async function( + textInput, + stability, + similarityBoost, + modelId, + responseType, + speakerBoost ) { - try { - if (!voiceID || !textInput) { - console.log("ERR: Missing parameter"); + try { + if (!textInput) { + console.log("ERR: Missing parameter {textInput}"); + } + + const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}/stream`; + const stabilityValue = stability ? stability : 0; + const similarityBoostValue = similarityBoost ? similarityBoost : 0; + + const response = await axios({ + method: "POST", + url: voiceURL, + data: { + text: textInput, + voice_settings: { + stability: stabilityValue, + similarity_boost: similarityBoostValue, + use_speaker_boost: speakerBoost, + }, + model_id: modelId ? modelId : undefined, + }, + headers: { + Accept: "audio/mpeg", + "xi-api-key": this.apiKey, + "Content-Type": "application/json", + }, + responseType: responseType ? responseType : "stream" + }); + + return response.data; + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/text-to-speech/${voiceID}/stream`; - const stabilityValue = stability ? stability : 0; - const similarityBoostValue = similarityBoost ? similarityBoost : 0; - - const response = await axios({ - method: "POST", - url: voiceURL, - data: { - text: textInput, - voice_settings: { - stability: stabilityValue, - similarity_boost: similarityBoostValue, - }, - model_id: modelId ? modelId : undefined, - }, - headers: { - Accept: "audio/mpeg", - "xi-api-key": this.apiKey, - "Content-Type": "application/json", - }, - responseType: responseType ? responseType : "stream" - }); - - return response.data; - } catch (error) { - console.log(error); - } }; /** @@ -168,22 +160,22 @@ Function that returns an object containing the details for all the voices. @returns {Object} - An object containing the list of voices and their details. */ -ElevenLabs.prototype.getVoices = async function () { - try { - const voiceURL = `${this.apiVersion}/voices`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } +ElevenLabs.prototype.getVoices = async function() { + try { + const voiceURL = `${elevenLabsAPIV1}/voices`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -192,116 +184,116 @@ Function that returns an object containing the default settings for the voices. @returns {Object} - An object containing the default settings for the voices. */ -ElevenLabs.prototype.getDefaultVoiceSettings = async function () { - try { - const voiceURL = `${this.apiVersion}/voices/settings/default`; - - const response = await axios({ - method: "GET", - url: voiceURL, - }); - - return response.data; - } catch (error) { - console.log(error); - } +ElevenLabs.prototype.getDefaultVoiceSettings = async function() { + try { + const voiceURL = `${elevenLabsAPIV1}/voices/settings/default`; + + const response = await axios({ + method: "GET", + url: voiceURL, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** Function that returns an object containing the settings of the specified voice. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. +@param {string} voiceId - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the settings of the specified voice. */ -ElevenLabs.prototype.getVoiceSettings = async function (voiceID) { - try { - if (!voiceID) { - console.log("ERR: Missing parameter"); +ElevenLabs.prototype.getVoiceSettings = async function(voiceId) { + try { + if (!voiceId) { + console.log("ERR: Missing parameter {voiceId}"); + } + + const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}/settings`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/voices/${voiceID}/settings`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } }; /** Function that returns an object containing the details of the specified voice. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. +@param {string} voiceId - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the details of the specified voice. */ -ElevenLabs.prototype.getVoice = async function (voiceID) { - try { - if (!voiceID) { - console.log("ERR: Missing parameter"); +ElevenLabs.prototype.getVoice = async function(voiceId) { + try { + if (!voiceId) { + console.log("ERR: Missing parameter {voiceId}"); + } + + const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/voices/${voiceID}`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } }; /** Function that returns an object containing the status of the delete operation. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. +@param {string} voiceId - The ID of the voice to use for the text-to-speech conversion. @returns {Object} - An object containing the status of the delete operation. */ -ElevenLabs.prototype.deleteVoice = async function (voiceID) { - try { - if (!voiceID) { - console.log("ERR: Missing parameter"); +ElevenLabs.prototype.deleteVoice = async function(voiceId) { + try { + if (!voiceId) { + console.log("ERR: Missing parameter {voiceId}"); + } + + const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}`; + + const response = await axios({ + method: "DELETE", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/voices/${voiceID}`; - - const response = await axios({ - method: "DELETE", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } }; /** Function that returns an object containing the status of the edit operation. -@param {string} voiceID - The ID of the voice to use for the text-to-speech conversion. +@param {string} voiceId - The ID of the voice to use for the text-to-speech conversion. @param {number} stability - The stability setting for the voice. @@ -309,36 +301,36 @@ Function that returns an object containing the status of the edit operation. @returns {Object} - An object containing the status of the edit operation. */ -ElevenLabs.prototype.editVoiceSettings = async function ( - voiceID, - stability, - similarityBoost +ElevenLabs.prototype.editVoiceSettings = async function( + voiceId, + stability, + similarityBoost ) { - try { - if (!voiceID) { - console.log("ERR: Missing parameter"); + try { + if (!voiceId) { + console.log("ERR: Missing parameter {voiceId}"); + } + + const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}/settings/edit`; + const stabilityValue = stability ? stability : 0; + const similarityBoostValue = similarityBoost ? similarityBoost : 0; + + const response = await axios({ + method: "POST", + url: voiceURL, + data: { + stability: stabilityValue, + similarity_boost: similarityBoostValue, + }, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); } - - const voiceURL = `${this.apiVersion}/voices/${voiceID}/settings/edit`; - const stabilityValue = stability ? stability : 0; - const similarityBoostValue = similarityBoost ? similarityBoost : 0; - - const response = await axios({ - method: "POST", - url: voiceURL, - data: { - stability: stabilityValue, - similarity_boost: similarityBoostValue, - }, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } }; /** @@ -347,22 +339,22 @@ Function that returns an object containing the list of voice models. @returns {Object} - An object containing the list of voice models and their details. */ -ElevenLabs.prototype.getModels = async function () { - try { - const voiceURL = `${this.apiVersion}/models`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } +ElevenLabs.prototype.getModels = async function() { + try { + const voiceURL = `${elevenLabsAPIV1}/models`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -371,22 +363,22 @@ Function that returns the user details. @returns {Object} - An object containing the user details. */ -ElevenLabs.prototype.getUserInfo = async function () { - try { - const voiceURL = `${this.apiVersion}/user`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } +ElevenLabs.prototype.getUserInfo = async function() { + try { + const voiceURL = `${elevenLabsAPIV1}/user`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -395,22 +387,22 @@ Function that returns the user subscription details. @returns {Object} - An object containing the user subscription details. */ -ElevenLabs.prototype.getUserSubscription = async function () { - try { - const voiceURL = `${this.apiVersion}/user/subscription`; - - const response = await axios({ - method: "GET", - url: voiceURL, - headers: { - "xi-api-key": this.apiKey, - }, - }); - - return response.data; - } catch (error) { - console.log(error); - } +ElevenLabs.prototype.getUserSubscription = async function() { + try { + const voiceURL = `${elevenLabsAPIV1}/user/subscription`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": this.apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; -module.exports = ElevenLabs; +module.exports = ElevenLabs; \ No newline at end of file From 589d0fceecd878a9ad5917ad185ce33dd928e64c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:19:38 +0300 Subject: [PATCH 06/29] doc: updated readme doc --- README.md | 87 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 701375c..c11eedd 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,17 @@ This is an open source Eleven Labs NodeJS package for converting text to speech |
Function
| Parameters | Endpoint | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `textToSpeech` | (apiKey, voiceID, fileName, textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}` | -| `textToSpeechStream` | (apiKey, voiceID, textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}/stream` | -| `getVoices` | (apiKey) | `/v1/voices` | +| `textToSpeech` | (fileName, textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}` | +| `textToSpeechStream` | (textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}/stream` | +| `editVoiceSettings` | (voiceID, stability, similarityBoost) | `/v1/voices/{voice_id}/settings/edit` | +| `getVoiceSettings` | (voiceID) | `/v1/voices/{voice_id}/settings` | +| `deleteVoice` | (voiceID) | `/v1/voices/{voice_id}` | +| `getVoice` | (voiceID) | `/v1/voices/{voice_id}` | +| `getVoices` | N/A | `/v1/voices` | +| `getModels` | N/A | `/v1/models` | +| `getUserInfo` | N/A | `/v1/user` | +| `getUserSubscription` | N/A | `/v1/user/subscription` | | `getDefaultVoiceSettings` | N/A | `/v1/voices/settings/default` | -| `getVoiceSettings` | (apiKey, voiceID) | `/v1/voices/{voice_id}/settings` | -| `getVoice` | (apiKey, voiceID) | `/v1/voices/{voice_id}` | -| `deleteVoice` | (apiKey, voiceID) | `/v1/voices/{voice_id}` | -| `editVoiceSettings` | (apiKey, voiceID, stability, similarityBoost) | `/v1/voices/{voice_id}/settings/edit` | -| `getModels` | (apiKey) | `/v1/models` | -| `getUserInfo` | (apiKey) | `/v1/user` | -| `getUserSubscription` | (apiKey) | `/v1/user/subscription` | ## Requirements @@ -69,17 +69,42 @@ To install the Elevenlabs package, run the following command: npm install elevenlabs-node ``` +## Setup + +Setup the ElevenLabs configurations for your project. + +|
Variable
| Description | +| --------------------------------------- | --------------------------------------------------------------------------- | +| `apiKey` (Required) | Your API key from Elevenlabs | +| `voiceId` (Optional) | A Voice ID from Elevenlabs | + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + } +); +``` + ## Usage Getting voice details. ```javascript -const voice = require("elevenlabs-node"); +const ElevenLabs = require("elevenlabs-node"); + +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get -const apiKey = "0e2c037kl8561005671b1de345s8765c"; // Your API key from Elevenlabs -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); -const voiceResponse = voice.getVoice(apiKey, voiceID).then((res) => { +const voiceResponse = voice.getVoice(voiceID).then((res) => { console.log(res); }); ``` @@ -87,15 +112,20 @@ const voiceResponse = voice.getVoice(apiKey, voiceID).then((res) => { Generating an audio file from text ```javascript -const voice = require("elevenlabs-node"); +const ElevenLabs = require("elevenlabs-node"); const fs = require("fs-extra"); -const apiKey = "0e2c037kl8561005671b1de345s8765c"; // Your API key from Elevenlabs -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get -const fileName = "audio.mp3"; // The name of your audio file -const textInput = "mozzy is cool"; // The text you wish to convert to speech +const fileName = "audio.mp3"; // The name of your audio file +const textInput = "mozzy is cool"; // The text you wish to convert to speech -voice.textToSpeech(apiKey, voiceID, fileName, textInput).then((res) => { +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + } +); + +voice.textToSpeech(fileName, textInput).then((res) => { console.log(res); }); ``` @@ -103,15 +133,20 @@ voice.textToSpeech(apiKey, voiceID, fileName, textInput).then((res) => { Generating an audio stream from text ```javascript -const voice = require("elevenlabs-node"); +const ElevenLabs = require("elevenlabs-node"); const fs = require("fs-extra"); -const apiKey = "0e2c037kl8561005671b1de345s8765c"; // Your API key from Elevenlabs -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get -const fileName = "audio.mp3"; // The name of your audio file -const textInput = "mozzy is cool"; // The text you wish to convert to speech +const fileName = "audio.mp3"; // The name of your audio file +const textInput = "mozzy is cool"; // The text you wish to convert to speech + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + } +); -voice.textToSpeechStream(apiKey, voiceID, textInput).then((res) => { +voice.textToSpeechStream(textInput).then((res) => { res.pipe(fs.createWriteStream(fileName)); }); ``` From 0fcf16893202d0079f8bdfdcd4c62ce27fd8c641 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:20:35 +0300 Subject: [PATCH 07/29] feat: updated test cases --- test/app.test.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index d7332a9..a54c5ed 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -8,11 +8,12 @@ const stability = '0.5'; const similarityBoost = '0.5'; const modelId = 'eleven_multilingual_v1'; const responseType = 'stream'; +const speakerBoost = true; const script = new ElevenLabs( { apiKey: apiKey, - apiVersion: "V1" + voiceId: voiceID } ); @@ -22,7 +23,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeech", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeech(voiceID, fileName, textInput, stability, similarityBoost, modelId); + const response = await script.textToSpeech(fileName, textInput, stability, similarityBoost, modelId, speakerBoost); // Response check expect(response.status).toEqual('ok'); @@ -32,7 +33,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeechStream", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeechStream(voiceID, textInput, stability, similarityBoost, modelId, responseType); + const response = await script.textToSpeechStream(textInput, stability, similarityBoost, modelId, responseType, speakerBoost); // Response check expect(!response).toBeFalsy(); @@ -63,7 +64,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoiceSettings(voiceID); + const response = await script.getVoiceSettings(voiceId); // Response check expect(response.stability).toBeTruthy(); @@ -74,7 +75,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoice", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoice(voiceID); + const response = await script.getVoice(voiceId); // Response check expect(response.voice_id).toBeTruthy(); @@ -84,7 +85,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test editVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.editVoiceSettings(voiceID, stability, similarityBoost); + const response = await script.editVoiceSettings(voiceId, stability, similarityBoost); // Response check expect(response.status).toEqual('ok'); From 8620138b826379cddfa3f99f73f0364a34e06e04 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:33:51 +0300 Subject: [PATCH 08/29] feat: updated default voice --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3434986..8624c5d 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ function ElevenLabs(options = { }) { this.apiKey = options.apiKey ? options.apiKey : ""; - this.voiceId = options.voiceId ? options.voiceId : "ErXwobaYiN019PkySvjV"; + this.voiceId = options.voiceId ? options.voiceId : "pNInz6obpgDQGcFmaJgB"; } From 96d3708c0ff9df8a1eafb900f2db6e577017aadb Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:35:07 +0300 Subject: [PATCH 09/29] docs: updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c11eedd..aac3f27 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,10 @@ npm install elevenlabs-node Setup the ElevenLabs configurations for your project. -|
Variable
| Description | -| --------------------------------------- | --------------------------------------------------------------------------- | -| `apiKey` (Required) | Your API key from Elevenlabs | -| `voiceId` (Optional) | A Voice ID from Elevenlabs | +|
Variable
| Description | Default | +| --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | +| `apiKey` | Your API key from Elevenlabs (Required) | N/A | +| `voiceId` | A Voice ID from Elevenlabs (Optional) | Adam (`pNInz6obpgDQGcFmaJgB`) | ```javascript const ElevenLabs = require("elevenlabs-node"); From c9724e8c022889688f30326fb71bcb25021258bf Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:42:16 +0300 Subject: [PATCH 10/29] fix: fixed test variable --- test/app.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app.test.js b/test/app.test.js index a54c5ed..d07ef0d 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -13,7 +13,7 @@ const speakerBoost = true; const script = new ElevenLabs( { apiKey: apiKey, - voiceId: voiceID + voiceId: voiceId } ); From 7b7c52510fbfc778072f96f41293014c94176105 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 19:42:32 +0300 Subject: [PATCH 11/29] doc: updated README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aac3f27..a902a97 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,8 @@ Setup the ElevenLabs configurations for your project. |
Variable
| Description | Default | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `apiKey` | Your API key from Elevenlabs (Required) | N/A | -| `voiceId` | A Voice ID from Elevenlabs (Optional) | Adam (`pNInz6obpgDQGcFmaJgB`) | +| `apiKey` | (`Required`) Your API key from Elevenlabs | N/A | +| `voiceId` | (`Optional`) A Voice ID from Elevenlabs | Adam (`pNInz6obpgDQGcFmaJgB`) | ```javascript const ElevenLabs = require("elevenlabs-node"); From 2f1fd35094e8905eb74601341311e74989cc06a1 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 20:01:16 +0300 Subject: [PATCH 12/29] docs: updated README with function details --- README.md | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 172 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a902a97..3f94abe 100644 --- a/README.md +++ b/README.md @@ -91,25 +91,32 @@ const voice = new ElevenLabs( ## Usage -Getting voice details. +### Text To Speech + +Generating an audio file from text. ```javascript const ElevenLabs = require("elevenlabs-node"); +const fs = require("fs-extra"); -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get +const fileName = "audio.mp3"; // The name of your audio file +const textInput = "mozzy is cool"; // The text you wish to convert to speech const voice = new ElevenLabs( { apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); -const voiceResponse = voice.getVoice(voiceID).then((res) => { +voice.textToSpeech(fileName, textInput).then((res) => { console.log(res); }); ``` -Generating an audio file from text +### Text To Speech Stream + +Generating an audio stream from text. ```javascript const ElevenLabs = require("elevenlabs-node"); @@ -125,29 +132,182 @@ const voice = new ElevenLabs( } ); -voice.textToSpeech(fileName, textInput).then((res) => { +voice.textToSpeechStream(textInput).then((res) => { + res.pipe(fs.createWriteStream(fileName)); +}); +``` + +### Edit Voice Settings + +Editing voice settings. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get +const stabilityBoost = 0.1; // The Stability Boost for the voice you want to edit +const similarityBoost = 0.1; // The Similarity Boost for the voice you want to edit + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.editVoiceSettings(voiceID, stabilityBoost, similarityBoost).then((res) => { console.log(res); }); ``` -Generating an audio stream from text +### Get Voice Settings + +Getting voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); -const fs = require("fs-extra"); -const fileName = "audio.mp3"; // The name of your audio file -const textInput = "mozzy is cool"; // The text you wish to convert to speech +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const voice = new ElevenLabs( { apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs - voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); -voice.textToSpeechStream(textInput).then((res) => { - res.pipe(fs.createWriteStream(fileName)); +const voiceResponse = voice.getVoiceSettings(voiceID).then((res) => { + console.log(res); +}); +``` + +### Delete Voice + +Delete voice. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.deleteVoice(voiceID).then((res) => { + console.log(res); +}); +``` + +### Get Voice + +Getting voice details. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getVoice(voiceID).then((res) => { + console.log(res); +}); +``` + +### Get Voices + +Getting all voice details. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getVoices().then((res) => { + console.log(res); +}); +``` + +### Get Models + +Getting all model details. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getModels().then((res) => { + console.log(res); +}); +``` + +### Get User Info + +Getting user info associated with the API Key. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getUserInfo().then((res) => { + console.log(res); +}); +``` + +### Get User Subscription + +Getting user subscription info associated with the API Key. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getUserSubscription().then((res) => { + console.log(res); +}); +``` + +### Get Default Voice Settings + +Getting default voice settings. + +```javascript +const ElevenLabs = require("elevenlabs-node"); + +const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get + +const voice = new ElevenLabs( + { + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + } +); + +const voiceResponse = voice.getDefaultVoiceSettings(voiceID).then((res) => { + console.log(res); }); ``` From d3c97ecc706cc3273df80b95bff6b99f73bb49ce Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 20:25:20 +0300 Subject: [PATCH 13/29] feat: added parameters --- README.md | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3f94abe..dac02da 100644 --- a/README.md +++ b/README.md @@ -45,18 +45,31 @@ This is an open source Eleven Labs NodeJS package for converting text to speech |
Function
| Parameters | Endpoint | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `textToSpeech` | (fileName, textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}` | -| `textToSpeechStream` | (textInput, stability, similarityBoost, modelId) | `/v1/text-to-speech/{voice_id}/stream` | -| `editVoiceSettings` | (voiceID, stability, similarityBoost) | `/v1/voices/{voice_id}/settings/edit` | -| `getVoiceSettings` | (voiceID) | `/v1/voices/{voice_id}/settings` | -| `deleteVoice` | (voiceID) | `/v1/voices/{voice_id}` | -| `getVoice` | (voiceID) | `/v1/voices/{voice_id}` | +| `textToSpeech` | (fileName, textInput, stability, similarityBoost, modelId, speakerBoost) | `/v1/text-to-speech/{voice_id}` | +| `textToSpeechStream` | (textInput, stability, similarityBoost, modelId, responseType, speakerBoost) | `/v1/text-to-speech/{voice_id}/stream` | +| `editVoiceSettings` | (voiceId, stability, similarityBoost) | `/v1/voices/{voice_id}/settings/edit` | +| `getVoiceSettings` | (voiceId) | `/v1/voices/{voice_id}/settings` | +| `deleteVoice` | (voiceId) | `/v1/voices/{voice_id}` | +| `getVoice` | (voiceId) | `/v1/voices/{voice_id}` | | `getVoices` | N/A | `/v1/voices` | | `getModels` | N/A | `/v1/models` | | `getUserInfo` | N/A | `/v1/user` | | `getUserSubscription` | N/A | `/v1/user/subscription` | | `getDefaultVoiceSettings` | N/A | `/v1/voices/settings/default` | +## Parameters +|
Variable
| Description | Type | +| --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | +| `fileName` | Name and file path for your audio file e.g (`./audio`) | Text | +| `textInput` | Text to be converted into audio e.g (`Hello`) | Text | +| `stability` | Stability for Text to Speech e.g (`0.5`) | Float | +| `similarityBoost` | Similarity Boost for Text to Speech e.g (`0.5`) | Float | +| `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | Text | +| `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | Text | +| `responseType` | Streaming response type e.g (`stream`) | Text | +| `similarityBoost` | Speaker Boost for Text to Speech e.g (`true`) | Boolean | + + ## Requirements - [NodeJS](https://nodejs.org/en/download/) @@ -97,7 +110,6 @@ Generating an audio file from text. ```javascript const ElevenLabs = require("elevenlabs-node"); -const fs = require("fs-extra"); const fileName = "audio.mp3"; // The name of your audio file const textInput = "mozzy is cool"; // The text you wish to convert to speech From 5f73cfc1a73b2d24ea00bbe910e5c302f5571668 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 20:42:09 +0300 Subject: [PATCH 14/29] doc: Updated README --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dac02da..50540e7 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@

+ + NPM Package Build + +
+
@@ -111,9 +116,16 @@ Generating an audio file from text. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const fileName = "audio.mp3"; // The name of your audio file const textInput = "mozzy is cool"; // The text you wish to convert to speech +// Optional Parameters +const stability = 0.5; // The stability for the converted speech +const similarityBoost = 0.5; // The similarity boost for the converted speech +const modelId = "elevenlabs_multilingual_v2"; // The ElevenLabs Model ID +const speakerBoost = true; // The speaker boost for the converted speech + const voice = new ElevenLabs( { apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs @@ -121,7 +133,7 @@ const voice = new ElevenLabs( } ); -voice.textToSpeech(fileName, textInput).then((res) => { +voice.textToSpeech(fileName, textInput, stability, similarityBoost, modelId, speakerBoost).then((res) => { console.log(res); }); ``` @@ -134,9 +146,16 @@ Generating an audio stream from text. const ElevenLabs = require("elevenlabs-node"); const fs = require("fs-extra"); -const fileName = "audio.mp3"; // The name of your audio file +// Required Parameters const textInput = "mozzy is cool"; // The text you wish to convert to speech +// Optional Parameters +const stability = 0.5; // The stability for the converted speech +const similarityBoost = 0.5; // The similarity boost for the converted speech +const modelId = "elevenlabs_multilingual_v2"; // The ElevenLabs Model ID +const responseType = 'stream'; // The streaming response type for the converted speech +const speakerBoost = true; // The speaker boost for the converted speech + const voice = new ElevenLabs( { apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs @@ -144,7 +163,7 @@ const voice = new ElevenLabs( } ); -voice.textToSpeechStream(textInput).then((res) => { +voice.textToSpeechStream(textInput, stability, similarityBoost, modelId, responseType, speakerBoost).then((res) => { res.pipe(fs.createWriteStream(fileName)); }); ``` @@ -156,6 +175,7 @@ Editing voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const stabilityBoost = 0.1; // The Stability Boost for the voice you want to edit const similarityBoost = 0.1; // The Similarity Boost for the voice you want to edit @@ -178,6 +198,7 @@ Getting voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const voice = new ElevenLabs( @@ -198,6 +219,7 @@ Delete voice. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const voice = new ElevenLabs( @@ -218,6 +240,7 @@ Getting voice details. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const voice = new ElevenLabs( @@ -310,6 +333,7 @@ Getting default voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); +// Required Parameters const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get const voice = new ElevenLabs( From 5dc2e133c3b33e87dd839b2f7f48da37d64da423 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Oct 2023 20:44:01 +0300 Subject: [PATCH 15/29] doc: added highlights --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 50540e7..8a399a9 100644 --- a/README.md +++ b/README.md @@ -65,14 +65,14 @@ This is an open source Eleven Labs NodeJS package for converting text to speech ## Parameters |
Variable
| Description | Type | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `fileName` | Name and file path for your audio file e.g (`./audio`) | Text | -| `textInput` | Text to be converted into audio e.g (`Hello`) | Text | -| `stability` | Stability for Text to Speech e.g (`0.5`) | Float | -| `similarityBoost` | Similarity Boost for Text to Speech e.g (`0.5`) | Float | -| `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | Text | -| `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | Text | -| `responseType` | Streaming response type e.g (`stream`) | Text | -| `similarityBoost` | Speaker Boost for Text to Speech e.g (`true`) | Boolean | +| `fileName` | Name and file path for your audio file e.g (`./audio`) | `Text` | +| `textInput` | Text to be converted into audio e.g (`Hello`) | `Text` | +| `stability` | Stability for Text to Speech e.g (`0.5`) | `Float` | +| `similarityBoost` | Similarity Boost for Text to Speech e.g (`0.5`) | `Float` | +| `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | `Text` | +| `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | `Text` | +| `responseType` | Streaming response type e.g (`stream`) | `Text` | +| `similarityBoost` | Speaker Boost for Text to Speech e.g (`true`) | `Boolean` | ## Requirements From 57d92a1e29586f0aa9c23c2f83966ca1febad148 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:21:46 +0300 Subject: [PATCH 16/29] feat: updated gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fa035d0..e75bd3f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules package-lock.json .DS_Store .eslintrc.json -audio.mp3 \ No newline at end of file +audio.mp3 +.env \ No newline at end of file From 91e2fbc59be32bf5f9f5aecf4b141616a8e82987 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:22:04 +0300 Subject: [PATCH 17/29] feat: dev dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 40ad86c..27e4929 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "fs-extra": "^11.1.1" }, "devDependencies": { + "dotenv": "^16.3.1", "eslint": "^8.45.0", "jest": "^29.6.1" } From 2a766060754eb4a5fbbb9bec30aee9ffb9d5fc15 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:22:37 +0300 Subject: [PATCH 18/29] feat: updated test cases --- test/app.test.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index d07ef0d..23def95 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,7 +1,8 @@ const ElevenLabs = require('../index.js'); +require('dotenv').config() const apiKey = process.env.ELEVENLABS_API_KEY; -const voiceID = process.env.ELEVENLABS_VOICE_ID; +const voiceId = process.env.ELEVENLABS_VOICE_ID; const fileName = 'audio.mp3'; const textInput = 'mozzy is cool'; const stability = '0.5'; @@ -23,7 +24,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeech", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeech(fileName, textInput, stability, similarityBoost, modelId, speakerBoost); + const response = await script.textToSpeech({fileName, textInput, stability, similarityBoost, modelId, speakerBoost}); // Response check expect(response.status).toEqual('ok'); @@ -33,7 +34,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeechStream", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeechStream(textInput, stability, similarityBoost, modelId, responseType, speakerBoost); + const response = await script.textToSpeechStream({textInput, stability, similarityBoost, modelId, responseType, speakerBoost}); // Response check expect(!response).toBeFalsy(); @@ -64,7 +65,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoiceSettings(voiceId); + const response = await script.getVoiceSettings({voiceId}); // Response check expect(response.stability).toBeTruthy(); @@ -75,7 +76,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test getVoice", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.getVoice(voiceId); + const response = await script.getVoice({voiceId}); // Response check expect(response.voice_id).toBeTruthy(); @@ -85,7 +86,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test editVoiceSettings", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.editVoiceSettings(voiceId, stability, similarityBoost); + const response = await script.editVoiceSettings({voiceId, stability, similarityBoost}); // Response check expect(response.status).toEqual('ok'); From d7ed35c47592be2de076f35001956e78b35a9f66 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:23:34 +0300 Subject: [PATCH 19/29] feat: changed function variables to object --- index.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 8624c5d..78bf35d 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,9 @@ const elevenLabsAPIV1 = "https://api.elevenlabs.io/v1"; /** -Creates an instance of ElevenLabs. + +Function initializes ElevenLabs API. + @param {Object} - An object containing the API Key and API Version [default: ElevenLabs V1]. */ function ElevenLabs(options = { @@ -13,7 +15,12 @@ function ElevenLabs(options = { }) { this.apiKey = options.apiKey ? options.apiKey : ""; - this.voiceId = options.voiceId ? options.voiceId : "pNInz6obpgDQGcFmaJgB"; + this.voiceId = options.voiceId ? options.voiceId : "pNInz6obpgDQGcFmaJgB"; // Default voice 'Adam' + + if(this.apiKey === ""){ + console.log("ERR: Missing API key"); + return; + } } @@ -35,19 +42,21 @@ Function that converts text to speech and saves the audio file to the specified @returns {Object} - An object containing the status of the operation. */ -ElevenLabs.prototype.textToSpeech = async function( +ElevenLabs.prototype.textToSpeech = async function({ fileName, textInput, stability, similarityBoost, modelId, speakerBoost -) { +}) { try { if (!fileName) { console.log("ERR: Missing parameter {fileName}"); + return; } else if (!textInput) { console.log("ERR: Missing parameter {textInput}"); + return; } const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}`; @@ -111,17 +120,18 @@ Function that converts text to speech and returns a readable stream of the audio @returns {Object} - A readable stream of the audio data. */ -ElevenLabs.prototype.textToSpeechStream = async function( +ElevenLabs.prototype.textToSpeechStream = async function({ textInput, stability, similarityBoost, modelId, responseType, speakerBoost -) { +}) { try { if (!textInput) { console.log("ERR: Missing parameter {textInput}"); + return; } const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}/stream`; @@ -207,10 +217,11 @@ Function that returns an object containing the settings of the specified voice. @returns {Object} - An object containing the settings of the specified voice. */ -ElevenLabs.prototype.getVoiceSettings = async function(voiceId) { +ElevenLabs.prototype.getVoiceSettings = async function({voiceId}) { try { if (!voiceId) { console.log("ERR: Missing parameter {voiceId}"); + return; } const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}/settings`; @@ -237,10 +248,11 @@ Function that returns an object containing the details of the specified voice. @returns {Object} - An object containing the details of the specified voice. */ -ElevenLabs.prototype.getVoice = async function(voiceId) { +ElevenLabs.prototype.getVoice = async function({voiceId}) { try { if (!voiceId) { console.log("ERR: Missing parameter {voiceId}"); + return; } const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}`; @@ -267,10 +279,11 @@ Function that returns an object containing the status of the delete operation. @returns {Object} - An object containing the status of the delete operation. */ -ElevenLabs.prototype.deleteVoice = async function(voiceId) { +ElevenLabs.prototype.deleteVoice = async function({voiceId}) { try { if (!voiceId) { console.log("ERR: Missing parameter {voiceId}"); + return; } const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}`; @@ -301,14 +314,15 @@ Function that returns an object containing the status of the edit operation. @returns {Object} - An object containing the status of the edit operation. */ -ElevenLabs.prototype.editVoiceSettings = async function( +ElevenLabs.prototype.editVoiceSettings = async function({ voiceId, stability, similarityBoost -) { +}) { try { if (!voiceId) { console.log("ERR: Missing parameter {voiceId}"); + return; } const voiceURL = `${elevenLabsAPIV1}/voices/${voiceId}/settings/edit`; From 97dc57b5a40ed6d64f8ca12e4f7f03c12f3013d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:23:50 +0300 Subject: [PATCH 20/29] feat: provenance badge --- .github/workflows/npm-publish.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6a58767..e200ea2 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,6 +11,9 @@ on: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -32,6 +35,6 @@ jobs: node-version: 16 registry-url: https://registry.npmjs.org/ - run: npm install - - run: npm publish + - run: npm publish --provenance env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} From b62f6eaef634b7727560f6b9d3d1b886c485ece1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:40:06 +0300 Subject: [PATCH 21/29] docs: updated documentation --- README.md | 161 +++++++++++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 8a399a9..740c66e 100644 --- a/README.md +++ b/README.md @@ -50,29 +50,29 @@ This is an open source Eleven Labs NodeJS package for converting text to speech |
Function
| Parameters | Endpoint | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `textToSpeech` | (fileName, textInput, stability, similarityBoost, modelId, speakerBoost) | `/v1/text-to-speech/{voice_id}` | -| `textToSpeechStream` | (textInput, stability, similarityBoost, modelId, responseType, speakerBoost) | `/v1/text-to-speech/{voice_id}/stream` | -| `editVoiceSettings` | (voiceId, stability, similarityBoost) | `/v1/voices/{voice_id}/settings/edit` | -| `getVoiceSettings` | (voiceId) | `/v1/voices/{voice_id}/settings` | -| `deleteVoice` | (voiceId) | `/v1/voices/{voice_id}` | -| `getVoice` | (voiceId) | `/v1/voices/{voice_id}` | -| `getVoices` | N/A | `/v1/voices` | -| `getModels` | N/A | `/v1/models` | -| `getUserInfo` | N/A | `/v1/user` | -| `getUserSubscription` | N/A | `/v1/user/subscription` | -| `getDefaultVoiceSettings` | N/A | `/v1/voices/settings/default` | +| `textToSpeech` | ({fileName, textInput, stability, similarityBoost, modelId, speakerBoost}) | `/v1/text-to-speech/{voice_id}` | +| `textToSpeechStream` | ({textInput, stability, similarityBoost, modelId, responseType, speakerBoost}) | `/v1/text-to-speech/{voice_id}/stream` | +| `editVoiceSettings` | ({voiceId, stability, similarityBoost}) | `/v1/voices/{voice_id}/settings/edit` | +| `getVoiceSettings` | ({voiceId}) | `/v1/voices/{voice_id}/settings` | +| `deleteVoice` | ({voiceId}) | `/v1/voices/{voice_id}` | +| `getVoice` | ({voiceId}) | `/v1/voices/{voice_id}` | +| `getVoices` | N/A | `/v1/voices` | +| `getModels` | N/A | `/v1/models` | +| `getUserInfo` | N/A | `/v1/user` | +| `getUserSubscription` | N/A | `/v1/user/subscription` | +| `getDefaultVoiceSettings` | N/A | `/v1/voices/settings/default` | ## Parameters |
Variable
| Description | Type | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `fileName` | Name and file path for your audio file e.g (`./audio`) | `Text` | -| `textInput` | Text to be converted into audio e.g (`Hello`) | `Text` | +| `fileName` | Name and file path for your audio file e.g (`./gen/hello`) | `String` | +| `textInput` | Text to be converted into audio e.g (`Hello`) | `String` | | `stability` | Stability for Text to Speech e.g (`0.5`) | `Float` | | `similarityBoost` | Similarity Boost for Text to Speech e.g (`0.5`) | `Float` | -| `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | `Text` | -| `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | `Text` | -| `responseType` | Streaming response type e.g (`stream`) | `Text` | -| `similarityBoost` | Speaker Boost for Text to Speech e.g (`true`) | `Boolean` | +| `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | `String` | +| `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | `String` | +| `responseType` | Streaming response type e.g (`stream`) | `String` | +| `speakerBoost` | Speaker Boost for Text to Speech e.g (`true`) | `Boolean` | ## Requirements @@ -101,8 +101,8 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs - voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); ``` @@ -116,25 +116,25 @@ Generating an audio file from text. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const fileName = "audio.mp3"; // The name of your audio file -const textInput = "mozzy is cool"; // The text you wish to convert to speech - -// Optional Parameters -const stability = 0.5; // The stability for the converted speech -const similarityBoost = 0.5; // The similarity boost for the converted speech -const modelId = "elevenlabs_multilingual_v2"; // The ElevenLabs Model ID -const speakerBoost = true; // The speaker boost for the converted speech - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs - voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); -voice.textToSpeech(fileName, textInput, stability, similarityBoost, modelId, speakerBoost).then((res) => { - console.log(res); +voice.textToSpeech({ + // Required Parameters + fileName: "audio.mp3", // The name of your audio file + textInput: "mozzy is cool", // The text you wish to convert to speech + + // Optional Parameters + stability: 0.5, // The stability for the converted speech + similarityBoost: 0.5, // The similarity boost for the converted speech + modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID + speakerBoost: true // The speaker boost for the converted speech + }).then((res) => { + console.log(res); }); ``` @@ -146,25 +146,25 @@ Generating an audio stream from text. const ElevenLabs = require("elevenlabs-node"); const fs = require("fs-extra"); -// Required Parameters -const textInput = "mozzy is cool"; // The text you wish to convert to speech - -// Optional Parameters -const stability = 0.5; // The stability for the converted speech -const similarityBoost = 0.5; // The similarity boost for the converted speech -const modelId = "elevenlabs_multilingual_v2"; // The ElevenLabs Model ID -const responseType = 'stream'; // The streaming response type for the converted speech -const speakerBoost = true; // The speaker boost for the converted speech - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs - voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); -voice.textToSpeechStream(textInput, stability, similarityBoost, modelId, responseType, speakerBoost).then((res) => { - res.pipe(fs.createWriteStream(fileName)); +const voiceResponse = voice.textToSpeechStream({ + // Required Parameters + textInput: "mozzy is cool", // The text you wish to convert to speech + + // Optional Parameters + stability: 0.5, // The stability for the converted speech + similarityBoost: 0.5, // The similarity boost for the converted speech + modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID + responseType: "stream", // The streaming type (arraybuffer, stream, json) + speakerBoost: true // The speaker boost for the converted speech + }).then((res) => { + res.pipe(fs.createWriteStream(fileName)); }); ``` @@ -175,18 +175,18 @@ Editing voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get -const stabilityBoost = 0.1; // The Stability Boost for the voice you want to edit -const similarityBoost = 0.1; // The Similarity Boost for the voice you want to edit - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); -const voiceResponse = voice.editVoiceSettings(voiceID, stabilityBoost, similarityBoost).then((res) => { +const voiceResponse = voice.editVoiceSettings({ + // Required Parameters + voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + stabilityBoost: 0.5, // The Stability Boost for the voice + similarityBoost: 0.5, // The Similarity Boost for the voice + }).then((res) => { console.log(res); }); ``` @@ -198,17 +198,17 @@ Getting voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); -const voiceResponse = voice.getVoiceSettings(voiceID).then((res) => { - console.log(res); +const voiceResponse = voice.getVoiceSettings({ + // Required Parameters + voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + }).then((res) => { + console.log(res); }); ``` @@ -219,17 +219,17 @@ Delete voice. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); -const voiceResponse = voice.deleteVoice(voiceID).then((res) => { - console.log(res); +const voiceResponse = voice.deleteVoice({ + // Required Parameters + voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + }).then((res) => { + console.log(res); }); ``` @@ -240,17 +240,17 @@ Getting voice details. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); -const voiceResponse = voice.getVoice(voiceID).then((res) => { - console.log(res); +const voiceResponse = voice.getVoice({ + // Required Parameters + voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + }).then((res) => { + console.log(res); }); ``` @@ -263,7 +263,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -281,7 +281,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -299,7 +299,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -317,7 +317,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -333,17 +333,14 @@ Getting default voice settings. ```javascript const ElevenLabs = require("elevenlabs-node"); -// Required Parameters -const voiceID = "pNInz6obpgDQGcFmaJgB"; // The ID of the voice you want to get - const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); -const voiceResponse = voice.getDefaultVoiceSettings(voiceID).then((res) => { - console.log(res); +const voiceResponse = voice.getDefaultVoiceSettings().then((res) => { + console.log(res); }); ``` From 2a0e6aed39c6191e1b6b6f187d909b9b55e709f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:54:22 +0300 Subject: [PATCH 22/29] doc: updated styling --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 740c66e..30378ab 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); @@ -118,7 +118,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); @@ -148,7 +148,7 @@ const fs = require("fs-extra"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs voiceId: "pNInz6obpgDQGcFmaJgB", // A Voice ID from Elevenlabs } ); @@ -177,7 +177,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -200,7 +200,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -221,7 +221,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -242,7 +242,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -263,7 +263,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -281,7 +281,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -299,7 +299,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -317,7 +317,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); @@ -335,7 +335,7 @@ const ElevenLabs = require("elevenlabs-node"); const voice = new ElevenLabs( { - apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs + apiKey: "0e2c037kl8561005671b1de345s8765c", // Your API key from Elevenlabs } ); From bb2738a864c521110b8193e9c2be014861af6f89 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2023 16:58:21 +0300 Subject: [PATCH 23/29] doc: fixed typos --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 30378ab..9807760 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.editVoiceSettings({ // Required Parameters - voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB", // The ID of the voice you want to get stabilityBoost: 0.5, // The Stability Boost for the voice similarityBoost: 0.5, // The Similarity Boost for the voice }).then((res) => { @@ -206,7 +206,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.getVoiceSettings({ // Required Parameters - voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get }).then((res) => { console.log(res); }); @@ -227,7 +227,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.deleteVoice({ // Required Parameters - voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get }).then((res) => { console.log(res); }); @@ -248,7 +248,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.getVoice({ // Required Parameters - voiceID: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get }).then((res) => { console.log(res); }); From 839b399f136b0dfdfea1c30e30a8db18ea878057 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 15:19:16 +0300 Subject: [PATCH 24/29] feat: added speaker style --- README.md | 2 +- index.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9807760..3cc28cb 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ const voiceResponse = voice.editVoiceSettings({ stabilityBoost: 0.5, // The Stability Boost for the voice similarityBoost: 0.5, // The Similarity Boost for the voice }).then((res) => { - console.log(res); + console.log(res); }); ``` diff --git a/index.js b/index.js index 78bf35d..3025a07 100644 --- a/index.js +++ b/index.js @@ -48,6 +48,7 @@ ElevenLabs.prototype.textToSpeech = async function({ stability, similarityBoost, modelId, + style, speakerBoost }) { try { @@ -62,6 +63,7 @@ ElevenLabs.prototype.textToSpeech = async function({ const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; + const styleValue = style ? style : 0; const response = await axios({ method: "POST", @@ -71,6 +73,7 @@ ElevenLabs.prototype.textToSpeech = async function({ voice_settings: { stability: stabilityValue, similarity_boost: similarityBoostValue, + style: styleValue, use_speaker_boost: speakerBoost, }, model_id: modelId ? modelId : undefined, @@ -126,6 +129,7 @@ ElevenLabs.prototype.textToSpeechStream = async function({ similarityBoost, modelId, responseType, + style, speakerBoost }) { try { @@ -137,6 +141,7 @@ ElevenLabs.prototype.textToSpeechStream = async function({ const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}/stream`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; + const styleValue = style ? style : 0; const response = await axios({ method: "POST", @@ -146,6 +151,7 @@ ElevenLabs.prototype.textToSpeechStream = async function({ voice_settings: { stability: stabilityValue, similarity_boost: similarityBoostValue, + style: styleValue, use_speaker_boost: speakerBoost, }, model_id: modelId ? modelId : undefined, From aa44679c2d7651e7d1ace7f578da18fd29f33608 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 15:29:30 +0300 Subject: [PATCH 25/29] feat: updated use cases --- test/app.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index 23def95..88f2527 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -9,6 +9,7 @@ const stability = '0.5'; const similarityBoost = '0.5'; const modelId = 'eleven_multilingual_v1'; const responseType = 'stream'; +const style = 0; const speakerBoost = true; const script = new ElevenLabs( @@ -24,7 +25,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeech", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeech({fileName, textInput, stability, similarityBoost, modelId, speakerBoost}); + const response = await script.textToSpeech({fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}); // Response check expect(response.status).toEqual('ok'); @@ -34,7 +35,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeechStream", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeechStream({textInput, stability, similarityBoost, modelId, responseType, speakerBoost}); + const response = await script.textToSpeechStream({textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}); // Response check expect(!response).toBeFalsy(); From 4c5bd9782dc4e297d1f904df85162ce1849f6abb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 15:30:06 +0300 Subject: [PATCH 26/29] doc: updated documentation --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3cc28cb..dcec710 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ This is an open source Eleven Labs NodeJS package for converting text to speech |
Function
| Parameters | Endpoint | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `textToSpeech` | ({fileName, textInput, stability, similarityBoost, modelId, speakerBoost}) | `/v1/text-to-speech/{voice_id}` | -| `textToSpeechStream` | ({textInput, stability, similarityBoost, modelId, responseType, speakerBoost}) | `/v1/text-to-speech/{voice_id}/stream` | +| `textToSpeech` | ({fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}` | +| `textToSpeechStream` | ({textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}/stream` | | `editVoiceSettings` | ({voiceId, stability, similarityBoost}) | `/v1/voices/{voice_id}/settings/edit` | | `getVoiceSettings` | ({voiceId}) | `/v1/voices/{voice_id}/settings` | | `deleteVoice` | ({voiceId}) | `/v1/voices/{voice_id}` | @@ -67,12 +67,13 @@ This is an open source Eleven Labs NodeJS package for converting text to speech | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | | `fileName` | Name and file path for your audio file e.g (`./gen/hello`) | `String` | | `textInput` | Text to be converted into audio e.g (`Hello`) | `String` | -| `stability` | Stability for Text to Speech e.g (`0.5`) | `Float` | -| `similarityBoost` | Similarity Boost for Text to Speech e.g (`0.5`) | `Float` | +| `stability` | Stability for Text to Speech default (`0`) | `Float` | +| `similarityBoost` | Similarity Boost for Text to Speech default (`0`) | `Float` | | `voiceId` | ElevenLabs Voice ID e.g (`pNInz6obpgDQGcFmaJgB`) | `String` | | `modelId` | ElevenLabs Model ID e.g (`elevenlabs_multilingual_v2`) | `String` | | `responseType` | Streaming response type e.g (`stream`) | `String` | | `speakerBoost` | Speaker Boost for Text to Speech e.g (`true`) | `Boolean` | +| `style` | Style Exaggeration for Text to Speech (0-100) default (`0`) | `Integer` | ## Requirements @@ -132,6 +133,7 @@ voice.textToSpeech({ stability: 0.5, // The stability for the converted speech similarityBoost: 0.5, // The similarity boost for the converted speech modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID + style: 1, // The style exaggeration for the converted speech speakerBoost: true // The speaker boost for the converted speech }).then((res) => { console.log(res); @@ -161,6 +163,7 @@ const voiceResponse = voice.textToSpeechStream({ stability: 0.5, // The stability for the converted speech similarityBoost: 0.5, // The similarity boost for the converted speech modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID + style: 1, // The style exaggeration for the converted speech responseType: "stream", // The streaming type (arraybuffer, stream, json) speakerBoost: true // The speaker boost for the converted speech }).then((res) => { From 9368f96c5e9a7aa36b9daae20f94679956630d3d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 16:47:57 +0300 Subject: [PATCH 27/29] feat: added variable voice ID --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3025a07..9d2e1b4 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,8 @@ function ElevenLabs(options = { Function that converts text to speech and saves the audio file to the specified file name. +@param {string} voiceId - A different ID for the voice to use with the text-to-speech conversion. + @param {string} fileName - The name of the file to save the audio data to. @param {string} textInput - The text to convert to speech. @@ -43,6 +45,7 @@ Function that converts text to speech and saves the audio file to the specified @returns {Object} - An object containing the status of the operation. */ ElevenLabs.prototype.textToSpeech = async function({ + voiceId, fileName, textInput, stability, @@ -60,7 +63,8 @@ ElevenLabs.prototype.textToSpeech = async function({ return; } - const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}`; + const voiceIdValue = voiceId ? voiceId : this.voiceId; + const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${voiceIdValue}`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; const styleValue = style ? style : 0; @@ -109,6 +113,8 @@ ElevenLabs.prototype.textToSpeech = async function({ Function that converts text to speech and returns a readable stream of the audio data. +@param {string} voiceId - A different ID for the voice to use with the text-to-speech conversion. + @param {string} textInput - The text to convert to speech. @param {number} stability - The stability setting for the voice. @@ -124,6 +130,7 @@ Function that converts text to speech and returns a readable stream of the audio @returns {Object} - A readable stream of the audio data. */ ElevenLabs.prototype.textToSpeechStream = async function({ + voiceId, textInput, stability, similarityBoost, @@ -138,7 +145,8 @@ ElevenLabs.prototype.textToSpeechStream = async function({ return; } - const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${this.voiceId}/stream`; + const voiceIdValue = voiceId ? voiceId : this.voiceId; + const voiceURL = `${elevenLabsAPIV1}/text-to-speech/${voiceIdValue}/stream`; const stabilityValue = stability ? stability : 0; const similarityBoostValue = similarityBoost ? similarityBoost : 0; const styleValue = style ? style : 0; From d430e21f24c494ec1918ebf9957dcd87907fa8f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 16:48:15 +0300 Subject: [PATCH 28/29] doc: updated documentation --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dcec710..1c302ae 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ This is an open source Eleven Labs NodeJS package for converting text to speech |
Function
| Parameters | Endpoint | | --------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------- | -| `textToSpeech` | ({fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}` | -| `textToSpeechStream` | ({textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}/stream` | +| `textToSpeech` | ({voiceId, fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}` | +| `textToSpeechStream` | ({voiceId, textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}) | `/v1/text-to-speech/{voice_id}/stream` | | `editVoiceSettings` | ({voiceId, stability, similarityBoost}) | `/v1/voices/{voice_id}/settings/edit` | | `getVoiceSettings` | ({voiceId}) | `/v1/voices/{voice_id}/settings` | | `deleteVoice` | ({voiceId}) | `/v1/voices/{voice_id}` | @@ -130,6 +130,7 @@ voice.textToSpeech({ textInput: "mozzy is cool", // The text you wish to convert to speech // Optional Parameters + voiceId: "21m00Tcm4TlvDq8ikWAM", // A different Voice ID from the default stability: 0.5, // The stability for the converted speech similarityBoost: 0.5, // The similarity boost for the converted speech modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID @@ -160,6 +161,7 @@ const voiceResponse = voice.textToSpeechStream({ textInput: "mozzy is cool", // The text you wish to convert to speech // Optional Parameters + voiceId: "21m00Tcm4TlvDq8ikWAM", // A different Voice ID from the default stability: 0.5, // The stability for the converted speech similarityBoost: 0.5, // The similarity boost for the converted speech modelId: "elevenlabs_multilingual_v2", // The ElevenLabs Model ID @@ -186,7 +188,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.editVoiceSettings({ // Required Parameters - voiceId: "pNInz6obpgDQGcFmaJgB", // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB", // The ID of the voice you want to edit stabilityBoost: 0.5, // The Stability Boost for the voice similarityBoost: 0.5, // The Similarity Boost for the voice }).then((res) => { @@ -230,7 +232,7 @@ const voice = new ElevenLabs( const voiceResponse = voice.deleteVoice({ // Required Parameters - voiceId: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get + voiceId: "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to delete }).then((res) => { console.log(res); }); From 9bf60221039558bc79e97c7d1186f0fa42ba1e95 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Nov 2023 16:48:31 +0300 Subject: [PATCH 29/29] feat: updated test cases --- test/app.test.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index 88f2527..24ca6cb 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -25,7 +25,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeech", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeech({fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}); + const response = await script.textToSpeech({voiceId, fileName, textInput, stability, similarityBoost, modelId, style, speakerBoost}); // Response check expect(response.status).toEqual('ok'); @@ -35,7 +35,7 @@ describe("Eleven Labs Node Unit Test", () => { test("Test textToSpeechStream", async () => { // Execute test await process.nextTick(() => {}); - const response = await script.textToSpeechStream({textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}); + const response = await script.textToSpeechStream({voiceId, textInput, stability, similarityBoost, modelId, responseType, style, speakerBoost}); // Response check expect(!response).toBeFalsy(); @@ -122,4 +122,27 @@ describe("Eleven Labs Node Unit Test", () => { // Response check expect(response.status).toBeTruthy(); }); +}); + +describe("Required Variables Test", () => { + + // textToSpeech test + test("Test textToSpeech", async () => { + // Execute test + await process.nextTick(() => {}); + const response = await script.textToSpeech({fileName, textInput}); + + // Response check + expect(response.status).toEqual('ok'); + }); + + // textToSpeechStream test + test("Test textToSpeechStream", async () => { + // Execute test + await process.nextTick(() => {}); + const response = await script.textToSpeechStream({textInput}); + + // Response check + expect(!response).toBeFalsy(); + }); }); \ No newline at end of file