Eleven Labs Node
Eleven Labs NodeJS package for converting text to speech!
Report Bug
·
Request Feature
Drop us a ⭐ on GitHub to help the project improve!
About
This is an open source Eleven Labs NodeJS package for converting text to speech using the Eleven Labs API.
Features
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} |
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
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 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 (eleven_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
Get Started
To install the Elevenlabs package, run the following command:
npm install elevenlabs-node
Setup
Setup the ElevenLabs configurations for your project.
apiKey | (Required ) Your API key from Elevenlabs | N/A |
voiceId | (Optional ) A Voice ID from Elevenlabs | Adam (pNInz6obpgDQGcFmaJgB ) |
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
voiceId: "pNInz6obpgDQGcFmaJgB",
}
);
Usage
Text To Speech
Generating an audio file from text.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
voiceId: "pNInz6obpgDQGcFmaJgB",
}
);
voice.textToSpeech({
fileName: "audio.mp3",
textInput: "mozzy is cool",
voiceId: "21m00Tcm4TlvDq8ikWAM",
stability: 0.5,
similarityBoost: 0.5,
modelId: "eleven_multilingual_v2",
style: 1,
speakerBoost: true
}).then((res) => {
console.log(res);
});
Text To Speech Stream
Generating an audio stream from text.
const ElevenLabs = require("elevenlabs-node");
const fs = require("fs-extra");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
voiceId: "pNInz6obpgDQGcFmaJgB",
}
);
const voiceResponse = voice.textToSpeechStream({
textInput: "mozzy is cool",
voiceId: "21m00Tcm4TlvDq8ikWAM",
stability: 0.5,
similarityBoost: 0.5,
modelId: "eleven_multilingual_v2",
style: 1,
responseType: "stream",
speakerBoost: true
}).then((res) => {
res.pipe(fs.createWriteStream(fileName));
});
Edit Voice Settings
Editing voice settings.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.editVoiceSettings({
voiceId: "pNInz6obpgDQGcFmaJgB",
stabilityBoost: 0.5,
similarityBoost: 0.5,
}).then((res) => {
console.log(res);
});
Get Voice Settings
Getting voice settings.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getVoiceSettings({
voiceId: "pNInz6obpgDQGcFmaJgB"
}).then((res) => {
console.log(res);
});
Delete Voice
Delete voice.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.deleteVoice({
voiceId: "pNInz6obpgDQGcFmaJgB"
}).then((res) => {
console.log(res);
});
Get Voice
Getting voice details.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getVoice({
voiceId: "pNInz6obpgDQGcFmaJgB"
}).then((res) => {
console.log(res);
});
Get Voices
Getting all voice details.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getVoices().then((res) => {
console.log(res);
});
Get Models
Getting all model details.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getModels().then((res) => {
console.log(res);
});
Get User Info
Getting user info associated with the API Key.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getUserInfo().then((res) => {
console.log(res);
});
Get User Subscription
Getting user subscription info associated with the API Key.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getUserSubscription().then((res) => {
console.log(res);
});
Get Default Voice Settings
Getting default voice settings.
const ElevenLabs = require("elevenlabs-node");
const voice = new ElevenLabs(
{
apiKey: "0e2c037kl8561005671b1de345s8765c",
}
);
const voiceResponse = voice.getDefaultVoiceSettings().then((res) => {
console.log(res);
});
Contributing
Contributions are welcome :)
Read our CONTRIBUTING.md to learn more.