#So I am trying to upload my own custom voice with the add voice API in NodeJS, but I seem to be stu

1 messages · Page 1 of 1 (latest)

waxen aspenBOT
#
AI-generated Answer for x56sandmanx

From the information provided, it seems like you're correctly appending the 'name' field to your form data. The error message you're receiving suggests that the 'name' field is missing, which might be due to how the form data is being interpreted on the server side.

In the provided API documentation, the 'files' field is described as an array of file paths to audio recordings intended for voice cloning. However, in your code, you're appending a string representation of an array, which might not be interpreted correctly by the server.

Here's a modified version of your function:

export async function uploadCustomVoice(voiceName, file) {
  const form = new FormData()
  form.append('name', 'My Voice')
  form.append('files', fs.createReadStream(path.join(dirName, 'test.mp3')))

  const addVoiceResponse = await fetch(`https://api.elevenlabs.io/v1/voices/add`, {
    method: 'POST',
    headers: {
      'xi-api-key': apiKey,
      'Content-Type': form.getHeaders()['content-type']
    },
    body: form
  })
  const addVoiceData = await addVoiceResponse.json()
  console.log(addVoiceData.detail)
}

In this version, I'm using fs.createReadStream to create a stream from the file, which is then appended to the form data. This should correctly send the file to the server.

As for your question about uploading a blob or buffer of audio, the API documentation does not explicitly mention support for this. The 'files' field is described as requiring an array of file paths. You might need to save the buffer to a file before uploading it using the API.

prime summit
#

so after trying to use teh code you provided, I now receive the following error:

There was an error parsing the body

waxen aspenBOT
#
AI-generated Answer for x56sandmanx

The error message you're seeing, "There was an error parsing the body", suggests that the API is having trouble understanding the format of the data you're sending in the request body.

Looking at your code, it seems like you're sending the 'files' field as a string representation of an array. However, the API is expecting an array of file paths.

Here's how you can modify your code:

export async function uploadCustomVoice(voiceName, file) {
  const form = new FormData()
  form.append('name', 'My Voice')
  form.append('files', path.join(dirName, 'test.mp3'))

  const addVoiceResponse = await fetch(`https://api.elevenlabs.io/v1/voices/add`, {
    method: 'POST',
    headers: {
      'xi-api-key': apiKey
    },
    body: form
  })
  const addVoiceData = await addVoiceResponse.json()
  console.log(addVoiceData.detail)
}

In this modified version, 'files' is appended as a single file path, not as a string representation of an array. If you have multiple files to upload, you can append them one by one using multiple 'form.append('files', filePath)' lines.

As for your question about uploading a blob or buffer of audio, the API documentation does not mention support for this. It specifies that the 'files' field should be an array of file paths. You might need to save the uploaded buffers to temporary files on your server, and then provide the paths to these files in the API request.

prime summit
#

export async function uploadCustomVoice(voiceName, file) {
const form = new FormData()
form.append('name', 'My Voice')
form.append('files', path.join(dirName, 'test.mp3'))

const addVoiceResponse = await fetch(https://api.elevenlabs.io/v1/voices/add, {
method: 'POST',
headers: {
'xi-api-key': apiKey
},
body: form
})
const addVoiceData = await addVoiceResponse.json()
console.log(addVoiceData.detail)
}

so i am again receiving the error [ { loc: [ 'body', 'name' ], msg: 'field required', type: 'value_error.missing' } ]

waxen aspenBOT
#
AI-generated Answer for x56sandmanx

It seems like the API is not recognizing the 'name' field in your request. This could be due to how the form data is being handled.

In your code, you're appending the 'name' and 'files' fields to the form data as strings. However, the 'files' field is expected to be an array of file paths.

Here's a modified version of your function:

export async function uploadCustomVoice(voiceName, file) {
  const form = new FormData()
  form.append('name', voiceName)
  form.append('files', fs.createReadStream(file))

  const addVoiceResponse = await fetch(`https://api.elevenlabs.io/v1/voices/add`, {
    method: 'POST',
    headers: {
      'xi-api-key': apiKey,
      'Content-Type': 'multipart/form-data',
    },
    body: form
  })
  const addVoiceData = await addVoiceResponse.json()
  console.log(addVoiceData.detail)
}

In this version, I'm using fs.createReadStream(file) to create a stream from the file path. This should correctly append the file to the form data.

Also, make sure to replace 'voiceName' and 'file' with the actual name of the voice and the file path respectively when calling the function.

As for your second question, the API documentation does not mention the ability to upload a blob or buffer of audio. It only specifies that the 'files' field should contain a list of file paths to audio recordings. Therefore, you might need to save the buffer to a file before uploading it.

prime summit
#

export async function uploadCustomVoice(voiceName, file) {
const form = new FormData()
form.append('name', 'My Voice')
form.append('files', fs.createReadStream(path.join(dirName, 'test.mp3')))

console.log(form)

const addVoiceResponse = await fetch(https://api.elevenlabs.io/v1/voices/add, {
method: 'POST',
headers: {
'xi-api-key': apiKey
},
body: form
})
const addVoiceData = await addVoiceResponse.json()
console.log(addVoiceData.detail)
}
[
{
loc: [ 'body', 'files', 0 ],
msg: "Expected UploadFile, received: <class 'str'>",
type: 'value_error'
}
]

what is an UploadFile?