Activate Audio Native within ElevenLabs
First you need to make sure that you activate Audio Native in your ElevenLabs account. After signing in, visit: https://elevenlabs.io/audio-native Select “Click to start with Audio Native” to begin the setup. Don’t worry about completing all the sections in the setup, as we just need to get to the code snippet at the end. Once you’ve gone through the setup, you should see a page like this:
Creating the Audio Native React component
Here’s a handy component that you can reuse across your project:The React component - ElevenLabsAudioNative.tsx
The React component - ElevenLabsAudioNative.tsx
Code Walkthrough
Code Walkthrough
use client
directive at the top of the file. This is mainly for Next.js, as we are using useEffect
which can only be used in client side components.Why can't I just use the snippet directly in React?
Why can't I just use the snippet directly in React?
React components are rendered and managed entirely in JavaScript, and their rendering lifecycle is controlled by React’s virtual DOM. When you try to include a script tag directly within a React component’s JSX, it doesn’t behave as it would when included directly in an HTML file. React’s virtual DOM does not execute script tags inserted into the DOM as part of component rendering. This is a security feature to prevent unintended or malicious code execution.This is why, if we were to just paste the Audio Native code snippet into our React application, it would not work.
Get the public user ID from the Audio Native snippet
Before you can use this component, you’ll need to retrieve your public user ID from the code snippet. Go back to https://elevenlabs.io/audio-native, and in the code snippet, copy the property calledpublicuserid
.

Use the Audio Native component
Now that you have the public user ID, you can use the component on your page. Simply import it, then pass it the public user ID from the previous step.Preview
Start your development server, if you haven’t already, and view the page. You should see something similar to the following, stating that the URL is not allowed. (If you don’t see anything, please see the Troubleshooting section below to perform a hard refresh)
Troubleshooting
If you don’t see the Audio Native player, try doing a hard refresh. This can sometimes be an issue because of the development server not properly reloading the script. In Chrome it’s: (⌘ or Ctrl) + Shift + RWhy am I seeing “URL not allowed”?
Here’s what’s happening behind the scenes. Remember that script we loaded in the useEffect hook? This script is trying to scrape the content from your page to get all the text and convert it to audio. However, it can’t load your page because it’s onlocalhost
. Audio Native can only process pages that are publicly accessible on the internet.
Local testing with ngrok
This is where a service such as ngrok can help us. ngrok is a way to get your site on localhost to map to a public URL on the internet. They have a free tier, so visit their website https://ngrok.com, create an account and install it. Here’s their getting started guide - https://ngrok.com/docs/getting-started Once you have it installed, you can use a command similar to the one below to point your local React project to a public URL with ngrok. I’m running Next.js locally on port3000
, so here’s the command I run. Your details may vary.