From 3d3ef562e4479b9e138effc872ee512a6b3ce241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pathr=C3=B8m?= Date: Sun, 16 Jul 2023 10:56:14 +0200 Subject: [PATCH 1/3] Upgrade libraries [Very important .fs] --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9a4fa66..60ef305 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,11 @@ }, "homepage": "https://github.com/FelixWaweru/elevenlabs-node#readme", "dependencies": { - "axios": "^1.3.4", - "fs": "^0.0.1-security" + "axios": "^1.4.0", + "fs-extra": "^11.1.1" }, "devDependencies": { - "eslint": "^8.35.0", - "jest": "^29.5.0" + "eslint": "^8.45.0", + "jest": "^29.6.1" } } From ee1cc3abcdff34f82d6063e279306d1c118cf011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pathr=C3=B8m?= Date: Sun, 16 Jul 2023 11:02:03 +0200 Subject: [PATCH 2/3] Replace fs to fs-extra --- README.md | 69 +++++---- index.js | 428 +++++++++++++++++++++++++++--------------------------- 2 files changed, 250 insertions(+), 247 deletions(-) diff --git a/README.md b/README.md index 38467a4..39aa015 100644 --- a/README.md +++ b/README.md @@ -43,20 +43,20 @@ This is an open source Eleven Labs NodeJS package for converting text to speech ## Features -|
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` | -| `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` | +|
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` | +| `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` | ## Requirements -- [NodeJS](https://nodejs.org/en/download/) +- [NodeJS](https://nodejs.org/en/download/) ## Get Started @@ -65,57 +65,56 @@ To install the Elevenlabs package, run the following command: ```shell npm install elevenlabs-node ``` + ## Usage Getting voice details. ```javascript -const voice = require('elevenlabs-node'); +const voice = require("elevenlabs-node"); -const apiKey = '0e2c037kl8561005671b1de345s8765c'; // Your API key from Elevenlabs -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 voiceResponse = voice.getVoice(apiKey, voiceID).then(res => { - console.log(res); +const voiceResponse = voice.getVoice(apiKey, voiceID).then((res) => { + console.log(res); }); ``` Generating an audio file from text ```javascript -const voice = require('elevenlabs-node'); -const fs = require('fs'); +const voice = 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 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 -voice.textToSpeech(apiKey, voiceID, fileName, textInput).then(res => { - console.log(res); +voice.textToSpeech(apiKey, voiceID, fileName, textInput).then((res) => { + console.log(res); }); - ``` Generating an audio stream from text ```javascript -const voice = require('elevenlabs-node'); -const fs = require('fs'); +const voice = 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 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 -voice.textToSpeechStream(apiKey, voiceID, textInput).then(res => { - res.pipe(fs.createWriteStream(fileName)); +voice.textToSpeechStream(apiKey, voiceID, textInput).then((res) => { + res.pipe(fs.createWriteStream(fileName)); }); - ``` ## Contributing Contributions are welcome :) -Read our [CONTRIBUTING.md](https://github.com/FelixWaweru/elevenlabs-node/blob/main/docs/CONTRIBUTING.md) to learn more. \ No newline at end of file +Read our [CONTRIBUTING.md](https://github.com/FelixWaweru/elevenlabs-node/blob/main/docs/CONTRIBUTING.md) to learn more. diff --git a/index.js b/index.js index c49e23f..5be5c81 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ -const axios = require('axios'); -const fs = require('fs'); -const elevenLabsAPI = 'https://api.elevenlabs.io/v1'; +const axios = require("axios"); +const fs = require("fs-extra"); +const elevenLabsAPI = "https://api.elevenlabs.io/v1"; /** @@ -22,45 +22,51 @@ 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, voiceID, fileName, textInput, stability, similarityBoost, modelId) => { - try { - - if (!apiKey || !voiceID || !fileName || !textInput) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/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': apiKey, - 'Content-Type': 'application/json', - }, - responseType: 'stream' - }); - - response.data.pipe(fs.createWriteStream(fileName)); - - return { - status: 'ok' - }; - - } catch (error) { - console.log(error); - } +const textToSpeech = async ( + apiKey, + voiceID, + fileName, + textInput, + stability, + similarityBoost, + modelId +) => { + try { + if (!apiKey || !voiceID || !fileName || !textInput) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/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": apiKey, + "Content-Type": "application/json", + }, + responseType: "stream", + }); + + response.data.pipe(fs.createWriteStream(fileName)); + + return { + status: "ok", + }; + } catch (error) { + console.log(error); + } }; /** @@ -81,41 +87,46 @@ 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, voiceID, textInput, stability, similarityBoost, modelId) => { - try { - - if (!apiKey || !voiceID || !textInput) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/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': apiKey, - 'Content-Type': 'application/json', - }, - responseType: 'stream' - }); - - return response.data; - - } catch (error) { - console.log(error); - } +const textToSpeechStream = async ( + apiKey, + voiceID, + textInput, + stability, + similarityBoost, + modelId +) => { + try { + if (!apiKey || !voiceID || !textInput) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/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": apiKey, + "Content-Type": "application/json", + }, + responseType: "stream", + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -127,27 +138,25 @@ Function that returns an object containing the details for all the voices. @returns {Object} - An object containing the list of voices and their details. */ const getVoices = async (apiKey) => { - try { - - if (!apiKey) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/voices`; - - const response = await axios({ - method: 'GET', - url: voiceURL, - headers: { - 'xi-api-key': apiKey - } - }); - - return response.data; - - } catch (error) { - console.log(error); - } + try { + if (!apiKey) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/voices`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -157,20 +166,18 @@ 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 () => { - try { - - const voiceURL = `${elevenLabsAPI}/voices/settings/default`; - - const response = await axios({ - method: 'GET', - url: voiceURL - }); - - return response.data; - - } catch (error) { - console.log(error); - } + try { + const voiceURL = `${elevenLabsAPI}/voices/settings/default`; + + const response = await axios({ + method: "GET", + url: voiceURL, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -184,27 +191,25 @@ Function that returns an object containing the settings of the specified voice. @returns {Object} - An object containing the settings of the specified voice. */ const getVoiceSettings = async (apiKey, voiceID) => { - try { - - if (!apiKey || !voiceID) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}/settings`; - - const response = await axios({ - method: 'GET', - url: voiceURL, - headers: { - 'xi-api-key': apiKey - } - }); - - return response.data; - - } catch (error) { - console.log(error); - } + try { + if (!apiKey || !voiceID) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/voices/${voiceID}/settings`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -218,27 +223,25 @@ Function that returns an object containing the details of the specified voice. @returns {Object} - An object containing the details of the specified voice. */ const getVoice = async (apiKey, voiceID) => { - try { - - if (!apiKey || !voiceID) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; - - const response = await axios({ - method: 'GET', - url: voiceURL, - headers: { - 'xi-api-key': apiKey - } - }); - - return response.data; - - } catch (error) { - console.log(error); - } + try { + if (!apiKey || !voiceID) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; + + const response = await axios({ + method: "GET", + url: voiceURL, + headers: { + "xi-api-key": apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -252,27 +255,25 @@ Function that returns an object containing the status of the delete operation. @returns {Object} - An object containing the status of the delete operation. */ const deleteVoice = async (apiKey, voiceID) => { - try { - - if (!apiKey || !voiceID) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; - - const response = await axios({ - method: 'DELETE', - url: voiceURL, - headers: { - 'xi-api-key': apiKey - } - }); - - return response.data; - - } catch (error) { - console.log(error); - } + try { + if (!apiKey || !voiceID) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/voices/${voiceID}`; + + const response = await axios({ + method: "DELETE", + url: voiceURL, + headers: { + "xi-api-key": apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; /** @@ -289,43 +290,46 @@ 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, voiceID, stability, similarityBoost) => { - try { - - if (!apiKey || !voiceID) { - console.log('ERR: Missing parameter'); - } - - const voiceURL = `${elevenLabsAPI}/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': apiKey - } - }); - - return response.data; - - } catch (error) { - console.log(error); - } +const editVoiceSettings = async ( + apiKey, + voiceID, + stability, + similarityBoost +) => { + try { + if (!apiKey || !voiceID) { + console.log("ERR: Missing parameter"); + } + + const voiceURL = `${elevenLabsAPI}/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": apiKey, + }, + }); + + return response.data; + } catch (error) { + console.log(error); + } }; module.exports = { - textToSpeech: textToSpeech, - textToSpeechStream: textToSpeechStream, - getVoices: getVoices, - getDefaultVoiceSettings: getDefaultVoiceSettings, - getVoiceSettings: getVoiceSettings, - getVoice: getVoice, - deleteVoice: deleteVoice, - editVoiceSettings: editVoiceSettings -}; \ No newline at end of file + textToSpeech: textToSpeech, + textToSpeechStream: textToSpeechStream, + getVoices: getVoices, + getDefaultVoiceSettings: getDefaultVoiceSettings, + getVoiceSettings: getVoiceSettings, + getVoice: getVoice, + deleteVoice: deleteVoice, + editVoiceSettings: editVoiceSettings, +}; From 754faf8f45e49345895f66f4ca239ca869f835f1 Mon Sep 17 00:00:00 2001 From: Felix Waweru Date: Tue, 18 Jul 2023 16:59:26 +0000 Subject: [PATCH 3/3] feat: package semver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 60ef305..b2eca81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elevenlabs-node", - "version": "1.1.2", + "version": "1.1.3", "description": "This is an open source Eleven Labs NodeJS package for converting text to speech using the Eleven Labs API", "main": "index.js", "scripts": {