https://retellai.com/?utm_source=discord&utm_medium=seo logo
How do I use the clone voice method via the sdk fo...
# ❓・ai-evy-support
d
@AI Evy How do I use the clone voice method via the sdk for cloning a custom voice. In what format is the file is expected to be sent. I am currently trying to send a ReadableStream via the path of the file as mentioned in the documentation but I am receiving an HTML based internal server error response with no other explanation as to what is going wrong. Am i missing something?
a
Thanks for tagging me @DeadNecromancer. I'll look through relevant sources and get back to you shortly.
### Answer To clone a voice using the SDK, you need to pass the files as an array of file streams using
fs.createReadStream()
. Here's the documented approach:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const voiceResponse = await client.voice.clone({
 files: [fs.createReadStream('path/to/file') ],
 voice_name: 'x',
}) ;
console.log(voiceResponse.provider) ;
[(1) ]() Key details: - The
files
parameter expects an array of file streams created with
fs.createReadStream()
- You can upload up to 25 files for ElevenLabs, but only 1 file is supported for Cartesia and MiniMax - You can optionally specify a
voice_provider
(defaults to
elevenlabs
) , with available options:
elevenlabs
,
cartesia
,
minimax
If you're receiving an HTML-based internal server error, a few things to check: - Ensure you're using
fs.createReadStream()
with a valid file path (not a ReadableStream from another source) - Verify your API key is correctly set in the Authorization header - Confirm the audio file format is compatible with the voice provider you're using The documentation doesn't specify exact audio format requirements, so if issues persist, I'd recommend reaching out via: - Visit [Documentation]() - Visit [Hire certified Retell partner]()
​ To learn more, see the sources I considered: [[1] Clone Voice](https://docs.retellai.com/api-references/clone-voice) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
d
@AI Evy When you say path of the file, it means the local file path present on my system?
a
Thanks for the follow-up, @DeadNecromancer. I'll get back to you soon.
### Answer Yes,
fs.createReadStream('path/to/file')
expects the local file path on your system where the audio file is stored. [(1) ]() For example, if your audio file is located at
/Users/yourname/audio/voice-sample.mp3
, you would use:
Copy code
javascript
files: [fs.createReadStream('/Users/yourname/audio/voice-sample.mp3') ]
The
fs
module is Node.js's built-in file system module, and
createReadStream
reads the file from your local disk and streams it to the API.
​ To learn more, see the sources I considered: [[1] Clone Voice](https://docs.retellai.com/api-references/clone-voice) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
d
@AI Evy Also, how am i supposed to set the headers in this request. The documentation doesn't explicitly show that.
a
Thanks for the follow-up, @DeadNecromancer. I'll get back to you soon.
### Answer --- When using the Retell SDK, you don't need to manually set headers—the SDK handles authorization automatically when you initialize the client with your API key. [(1) ]()
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
}) ;
[(2) ]() The
apiKey
you provide during client initialization is automatically included as the
Authorization
header (in the format
Bearer YOUR_API_KEY
) for all subsequent API calls, including the
client.voice.clone()
method. So your complete clone voice call would simply be:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const voiceResponse = await client.voice.clone({
  files: [fs.createReadStream('path/to/file') ],
  voice_name: 'x',
}) ;
console.log(voiceResponse.provider) ;
No additional header configuration is needed when using the SDK—that's one of its main benefits over using the REST API directly. [(1) ]()
​ To learn more, see the sources I considered: [[1] SDKs](https://docs.retellai.com/get-started/sdk) [[2] Clone Voice](https://docs.retellai.com/api-references/clone-voice) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.