elevenlabs-examples
elevenlabs-examples copied to clipboard
Example code not working
I'm trying to use the code inside text_to_speech_stream.ts
to get audio stream and upload it on aws s3 but it gives me below error.
/**
* Uses the ElevenLabs API to convert text to audio
* @param text The text to convert to audio
* @returns The URL of the audio file
*/
export const textToSpeech: (text: string) => Promise<Buffer> = async (
text: string
) => {
return new Promise(async (resolve, reject) => {
try {
const audioStream = await elabs.generate({
voice: "Rachel",
model_id: "eleven_turbo_v2",
text,
});
console.log("audioStream", audioStream);
console.log(typeof audioStream);
const chunks: Buffer[] = [];
for await (const chunk of audioStream) {
chunks.push(chunk);
}
const audio = Buffer.concat(chunks);
resolve(audio);
} catch (error) {
console.log("error", error);
reject(error);
}
});
};