elevenlabs / elevenlabs-examples

https://elevenlabs.io/docs/api-reference/getting-started
MIT License
110 stars 33 forks source link

Example code not working #45

Open didemkkaslan opened 1 month ago

didemkkaslan commented 1 month ago

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);
    }
  });
};
Screenshot 2024-08-05 at 13 44 05
usamatariq180 commented 4 weeks ago

Hi there, I want to ask that whether your app is capturing users voice from twilio and converting it to text or not?