#Using api directly from mobile app or browser

1 messages · Page 1 of 1 (latest)

calm basin
#

Hi guys,
I want to integrate elevenlabs into my mobile app for tts feature. Currently i am using a node js app as a proxy to store api keys and then the mobile app sends the text for speech converstion to node js app and then the node js sends it to elevenlabs. then nodejs streams response to mobile app.

this is causing some extra latency which is killing user experience. is there a way to directly use elevenlabs api keys from mobile apps?

mint tundra
#

mostly because even if you were to create an API key with only generation permissions, users would likely still be able to sniff the api key from the traffic (or the app itself)

calm basin
#

Thanks @mint tundra
I am getting about 2-2.5 seconds for getting audio from elevenlabs for a text like this:
"Hi there! I'm excited to explore your character and social strengths together. May I ask, do you think of yourself as honest?"

here is what i am doing:

  if (!voiceMode) {
    return;
  }
  let start = Date.now();
  if (text) {
    try {
      const audioStream = await Elevenclient.generate({
        voice: 'Rachel',
        model_id: 'eleven_turbo_v2_5',
        text,
      });

      const chunks = [];
      for await (const chunk of audioStream) {
        chunks.push(chunk);
      }

      const content = Buffer.concat(chunks);
      ws.send(content);

    } catch (error) {
      console.error('Error generating or sending audio stream:', error);
    } finally {
      console.log('Time taken to generate and send TTS in milliseconds:', Date.now() - start);
    }
  }
}```

is it normal? 
Also I checked elevenlabs docs and they say that to minimise latency, we should be streaming api (https://elevenlabs.io/docs/api-reference/streaming). Can you point to certain examples as to how do we stream from a nodejs proxy to a front end? (I checked the javascript code given on this page. but not sure how do we send this stream to a front end)
ElevenLabs

Explore our Guides and API Reference to get the most out of ElevenLabs.

mint tundra
#

that's usually the metric used for latency

#

rather than the total time