elevenlabs / elevenlabs-js

The official JavaScript (Node) library for ElevenLabs Text to Speech.
https://elevenlabs.io
MIT License
149 stars 15 forks source link

Voice add 422 - "Expected UploadFile, received: <class 'str'>", #76

Closed tmageebtr closed 1 month ago

tmageebtr commented 3 months ago

Trying code similar to example. Getting error. Node 18.19.1 "elevenlabs": "^0.13.0"

async function generateClone11(project, job, speaker) {

  const clonePath = filePath + project + "/dubaudio/" + "speaker" + speaker.number + "/clone.wav";
  const speakername = project + "-" + speaker.number;

  const elevenlabs = new ElevenLabsClient({
    apiKey: "API_KEY"
  })

  const voice = await elevenlabs.voices.add({
    files: [fs.createReadStream(clonePath)],

    name: speakername
  });

  console.log("voice id: " + voice);

}

`/home/ubuntu/web/node_modules/elevenlabs/api/resources/voices/client/Client.js:496 throw new ElevenLabs.UnprocessableEntityError(_response.error.body); ^

UnprocessableEntityError: UnprocessableEntityError Status code: 422 Body: { "detail": [ { "loc": [ "body", "files", 0 ], "msg": "Expected UploadFile, received: <class 'str'>", "type": "value_error" } ] } at Voices. (/home/ubuntu/web/node_modules/elevenlabs/api/resources/voices/client/Client.js:496:31) at Generator.next () at fulfilled (/home/ubuntu/web/node_modules/elevenlabs/api/resources/voices/client/Client.js:31:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { statusCode: 422, body: { detail: [ { loc: [ 'body', 'files', 0 ], msg: "Expected UploadFile, received: <class 'str'>", type: 'value_error' } ] } } `

manthan-p-simformsolutions commented 2 months ago

I am also facing this issue. Any updates on this?

steve-opus commented 2 months ago

Same issue. I am using the latest version now.

manthan-p-simformsolutions commented 2 months ago

I found one alternative is to create a Blob of the uploaded file buffer. Node: v20.9.0 elevenlabs: ^0.15.0

const express = require("express");
const multer = require("multer");
const { ElevenLabsClient } = require("elevenlabs");

const app = express();
const port = 3000;

const client = new ElevenLabsClient({
  apiKey: "API_KEY",
});

const upload = multer();

app.post("/add-voice", upload.array("files"), async (req, res) => {
  try {
    const { name } = req.body;
    const files = req.files;

    if (!files?.length) {
      return res.status(400).send({ message: "No file uploaded" });
    }

    if (!name) {
      return res.status(400).send({ message: "Name is required" });
    }

    const filesArr = files.map(
      (file) =>
        new Blob([file.buffer], {
          type: file?.mimetype,
        })
    );

    const response = await client.voices.add({
      files: filesArr,
      name: name,
    });

    res.send({
      response,
    });
  } catch (error) {
    res.send({
      error: error?.message,
    });
  }
});
echotech11 commented 2 months ago

Same issue.

dsinghvi commented 1 month ago

@tmageebtr we've also merged a fix into the SDK on the latest version