How to Clone a Voice
Voice cloning is a powerful feature that allows you to create a digital replica of a voice using a sample audio file. This can be particularly useful for creating personalized text-to-speech applications, voice assistants, and more. In this guide, we will walk you through the process of cloning a voice using the Neuphonic API. You will learn how to prepare your audio sample, send it to the API for cloning, and use the cloned voice in your applications. Let's get started!
Clone a Voice
Prepare Your Voice
In order to clone a voice, you need an audio sample of the target voice you want to clone. The audio sample must adhere to the following requirements.
Make sure the audio sample is clear and free of background noise. The better the quality of your audio sample, the more accurately the cloning process will replicate the voice.
Clone Your Voice
To clone a voice, you need to send a POST request to the Neuphonic API with the necessary parameters. This includes the name you want to assign to the cloned voice, any descriptive tags, and the path to the audio file you wish to use for cloning.
- cURL
- Python SDK
- JavaScript SDK
curl -X POST "http://api.neuphonic.com/voices?voice_name=<VOICE_NAME>" \
-H "X-API-KEY: <API_KEY>" \
-F "voice_tags=<VOICE_TAGS>" \
-F "voice_file=@<FILE_PATH>.wav;type=audio/wav"
# Example:
# curl -X POST "http://api.neuphonic.com/voices?voice_name=Mike" \
# -H "X-API-KEY: <API_KEY>" \
# -F "voice_tags=Male, Thirties" \
# -F "voice_file=@./audio_sample.wav;type=audio/wav"
import os
from pyneuphonic import Neuphonic
# Ensure the API key is set in your environment
client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY'))
response = client.voices.clone(
voice_name='<VOICE_NAME>',
voice_tags=['tag1', 'tag2'], # optional, add descriptive tags of what your voice sounds like
voice_file_path='<FILE_PATH>.wav' # replace with file path to a sample of the voice to clone
)
print(response.data) # this will contain a success message with the voice_id of the cloned voice
voice_id = response.data['voice_id'] # store the voice_id for later use
import { createClient } from '@neuphonic/neuphonic-js';
const client = createClient({ apiKey: '<API_KEY>'});
const id = await client.voices.clone({
voiceName: 'Cloned Name',
voiceFilePath: __dirname + '/data/voice1.wav',
voiceTags: ['Tag 1']
});
// New voice ID returned if the voice is cloned successfully
console.log(id);
You can now view your cloned voice when you get a list of all voices available in your library
using GET /voices
:
- cURL
- Python SDK
- JavaScript SDK
curl -X GET "http://api.neuphonic.com/voices" \
-H "X-API-KEY: <API_KEY>"
import os
from pyneuphonic import Neuphonic
# Ensure the API key is set in your environment
client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY'))
response = client.voices.list() # get's all available voices
print(response.data['voices']) # display list of voices
import { createClient } from '@neuphonic/neuphonic-js';
const client = createClient({ apiKey: '<API_KEY>'});
const voices = await client.voices.list();
console.log(voices);
You can now utilize this cloned voice with its voice_id
by following the instructions in
How to Use Text to Speech.
Currently Neuphonic only supports voice cloning in English.
Delete a Cloned Voice
To delete a voice, you need to send a DELETE /voices
request with the voice_id
of the voice you
want to delete:
- cURL
- JavaScript SDK
curl -X DELETE "http://api.neuphonic.com/voices/<VOICE_ID>" \
-H "X-API-KEY: <API_KEY>"
from pyneuphonic import Neuphonic
import os
# Ensure the API key is set in your environment
client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY'))
# Delete using the voices `voice_id`
response = client.voices.delete(voice_id='<VOICE_ID>')
print(response.data) # display response
import { createClient } from '@neuphonic/neuphonic-js';
const client = createClient({ apiKey: '<API_KEY>'});
const voiceDeleted = await client.voices.delete({
name: 'Cloned Name'
});
// Will return true if the voice was deleted successfully
console.log(voiceDeleted);