Skip to content

Commit

Permalink
Merge pull request #13 from KeystoneScience/add_model_field
Browse files Browse the repository at this point in the history
added in model_id as a passed parameter
  • Loading branch information
FelixWaweru committed May 23, 2023
2 parents 9673741 + 521d490 commit 6e7789f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ This is an open source Eleven Labs NodeJS package for converting text to speech

| <div style="width:290px">Function</div> | Parameters | Endpoint |
| --------------------------------------- | --------------------------------------------------------------------- | ------------------------------------- |
| `textToSpeech` | (apiKey, voiceID, fileName, textInput, stability, similarityBoost) | `/v1/text-to-speech/{voice_id}` |
| `textToSpeechStream` | (apiKey, voiceID, textInput, stability, similarityBoost) | `/v1/text-to-speech/{voice_id}/stream`|
| `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` |
Expand All @@ -58,7 +58,7 @@ This is an open source Eleven Labs NodeJS package for converting text to speech
To install the Elevenlabs package, run the following command:

```shell
npm install -g elevenlabs-node
npm install elevenlabs-node
```
## Usage

Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Function that converts text to speech and saves the audio file to the specified
@param {number} similarityBoost - The similarity boost setting for the voice.
@param {string} modelId - The model to use for the text-to-speech conversion. If null, it will use elevenlab's default model.
@returns {Object} - An object containing the status of the operation.
*/
const textToSpeech = async (apiKey, voiceID, fileName, textInput, stability, similarityBoost) => {
const textToSpeech = async (apiKey, voiceID, fileName, textInput, stability, similarityBoost, modelId) => {
try {

if (!apiKey || !voiceID || !fileName || !textInput) {
Expand All @@ -39,7 +41,8 @@ const textToSpeech = async (apiKey, voiceID, fileName, textInput, stability, sim
voice_settings: {
stability: stabilityValue,
similarity_boost: similarityBoostValue
}
},
model_id: modelId ? modelId : undefined
},
headers: {
'Accept': 'audio/mpeg',
Expand Down Expand Up @@ -74,9 +77,11 @@ Function that converts text to speech and returns a readable stream of the audio
@param {number} similarityBoost - The similarity boost setting for the voice.
@param {string} modelId - The model to use for the text-to-speech conversion. If null, it will use elevenlab's default model.
@returns {Object} - A readable stream of the audio data.
*/
const textToSpeechStream = async (apiKey, voiceID, textInput, stability, similarityBoost) => {
const textToSpeechStream = async (apiKey, voiceID, textInput, stability, similarityBoost, modelId) => {
try {

if (!apiKey || !voiceID || !textInput) {
Expand All @@ -95,7 +100,8 @@ const textToSpeechStream = async (apiKey, voiceID, textInput, stability, similar
voice_settings: {
stability: stabilityValue,
similarity_boost: similarityBoostValue
}
},
model_id: modelId ? modelId : undefined
},
headers: {
'Accept': 'audio/mpeg',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elevenlabs-node",
"version": "1.0.2",
"version": "1.1.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": {
Expand Down
5 changes: 3 additions & 2 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const fileName = 'audio.mp3';
const textInput = 'mozzy is cool';
const stability = '0.5';
const similarityBoost = '0.5';
const modelId = 'eleven_multilingual_v1';

describe("Eleven Labs Node Unit Test", () => {

// textToSpeech test
test("Test textToSpeech", async () => {
// Execute test
const response = await script.textToSpeech(apiKey, voiceID, fileName, textInput, stability, similarityBoost);
const response = await script.textToSpeech(apiKey, voiceID, fileName, textInput, stability, similarityBoost, modelId);

// Response check
expect(response.status).toEqual('ok');
Expand All @@ -21,7 +22,7 @@ describe("Eleven Labs Node Unit Test", () => {
// textToSpeechStream test
test("Test textToSpeechStream", async () => {
// Execute test
const response = await script.textToSpeechStream(apiKey, voiceID, textInput, stability, similarityBoost);
const response = await script.textToSpeechStream(apiKey, voiceID, textInput, stability, similarityBoost, modelId);

// Response check
expect(!response).toBeFalsy();
Expand Down

0 comments on commit 6e7789f

Please sign in to comment.