#how can I make a voice through the API with more than one file, what needs to be the structure of f
1 messages · Page 1 of 1 (latest)
To add a new voice using multiple audio files through the API, you need to structure your request as follows:
- Headers: Include your API key.
- Body: Use
multipart/form-datato send the voice name and the list of file paths.
Here's an example in Python:
from elevenlabs.client import ElevenLabs
client = ElevenLabs(api_key="YOUR_API_KEY")
client.voices.add(
name="YourVoiceName",
files=["path/to/first_audio_file.wav", "path/to/second_audio_file.wav"],
description="Description of the voice",
labels="{'label1': 'value1', 'label2': 'value2'}"
)
Request Structure
-
Headers:
xi-api-key: Your API key.
-
Body:
name: The name that identifies this voice.files: A list of file paths to audio recordings intended for voice cloning.description(optional): A description of the voice.labels(optional): Serialized labels dictionary for the voice.
Example cURL Request
curl -X POST "https://api.elevenlabs.io/v1/voices/add" \
-H "xi-api-key: YOUR_API_KEY" \
-F "name=YourVoiceName" \
-F "files=@path/to/first_audio_file.wav" \
-F "files=@path/to/second_audio_file.wav" \
-F "description=Description of the voice" \
-F "labels={'label1': 'value1', 'label2': 'value2'}"
This will add a new voice using the provided audio files. Make sure you have the necessary rights or consents to upload and clone the voice samples.
what if I store the audio of my files in this structure:
[('files', [('vf_e598a05f-ef8e-44c2-9591-a582c0111a44.wav', <_io.BytesIO object at 0x7fba02f2b830>, 'audio/wav')])]
To create a voice through the API with multiple files, you need to provide a list of file paths to audio recordings. Here is the structure you should follow:
Headers
xi-api-key: Your API key.
Body (multipart/form-data)
name(string, required): The name that identifies this voice.files(file[], required): A list of file paths to audio recordings intended for voice cloning.description(string): How would you describe the voice?labels(string): Serialized labels dictionary for the voice.
Example in Python
from elevenlabs.client import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.voices.add(
name="Alex",
files=[
('files', ('vf_e598a05f-ef8e-44c2-9591-a582c0111a44.wav', open('path/to/your/file1.wav', 'rb'), 'audio/wav')),
('files', ('another_file.wav', open('path/to/your/file2.wav', 'rb'), 'audio/wav'))
],
description="A description of the voice",
labels="{}"
)
Make sure each file is correctly formatted and accessible. If you have any issues with account, billing, or other related topics, please open a ticket via the ticket form.
I want to use a request, not the python library, and the audio content will be loaded in using BytesIO
To create a voice using the API with multiple audio files using requests and BytesIO, you can structure your request as follows:
import requests
from io import BytesIO
# Your API key
API_KEY = "your_api_key_here"
# URL for the API endpoint
url = "https://api.elevenlabs.io/v1/voice"
# Headers for the request
headers = {
"xi-api-key": API_KEY
}
# Example audio files loaded into BytesIO
audio_files = [
('files', ('file1.wav', BytesIO(b'audio_content_1'), 'audio/wav')),
('files', ('file2.wav', BytesIO(b'audio_content_2'), 'audio/wav'))
]
# Data payload for the request
data = {
"voice_name": "Your Voice Name",
"description": "Description of the voice"
}
# Make the POST request
response = requests.post(url, headers=headers, data=data, files=audio_files)
# Check the response
if response.ok:
print("Voice created successfully.")
print(response.json())
else:
print("Error:", response.text)
In this example:
- Replace
"your_api_key_here"with your actual API key. - Replace
b'audio_content_1'andb'audio_content_2'with the actual binary content of your audio files. - Adjust the
datadictionary to include any additional parameters required by the API.
This will send a multipart/form-data request to the API with multiple audio files.
[('files', ('vf_e598a05f-ef8e-44c2-9591-a582c0111a44.wav', <_io.BytesIO object at 0x7f4dc3e73e70>, 'audio/wav')), ('files', ('vf_ca456af8-4d93-4cef-815b-a6200f9e5ffb.wav', <_io.BytesIO object at 0x7f4ddbcc94e0>, 'audio/wav'))]
vf_e598a05f-ef8e-44c2-9591-a582c0111a44.wav
vf_ca456af8-4d93-4cef-815b-a6200f9e5ffb.wav
{'detail': {'status': 'duplicated_files', 'message': 'You cannot upload the same file twice.'}}
I get the duplicated_files error, the files are different