Skip to main content

Create an AI Voice Assistant with ElevenLabs & Node.js

Learn how to build a command-line AI voice assistant using Node.js and ElevenLabs API for realistic text-to-speech and custom voice cloning.

AI-written
Inewgen
29 Oct 2026Source: Dev.to3 min read (0 views)
Share
Create an AI Voice Assistant with ElevenLabs & Node.js

Stock photo for illustration only, not from the actual event

Font size
  • Build an AI voice assistant using ElevenLabs API and Node.js.
  • Keep code lightweight with native fetch instead of extra HTTP libraries.
  • Clone custom voices using just a 10-second target speaker audio sample.
  • Integrate OpenAI to give your assistant intelligent Q&A capabilities.

If you want to give your application a natural, expressive voice that can even mimic specific speakers, ElevenLabs is the go-to service. Their API provides powerful text-to-speech (TTS) and voice cloning capabilities via simple HTTP calls, offering generous developer tiers suitable for hobbyist projects and prototypes.

In this tutorial, we explore how to wire up a simple AI voice assistant using Node.js and the ElevenLabs API, resulting in a functional command-line tool. Start by verifying your Node installation with node -v and installing ffmpeg using your system package manager, such as brew install ffmpeg or apt-get install ffmpeg.

code editor workspace software development dark theme

Stock photo for illustration only, not from the actual event

The project directory structure for voice-assistant/ contains the following files:

  • .env for storing API keys
  • index.js as the main program entry point
  • tts.js as a tiny wrapper around ElevenLabs
  • package.json for dependency management

Create the project folder and initialize npm using mkdir voice-assistant && cd voice-assistant, npm init -y, and npm install dotenv openai. The implementation remains lightweight by avoiding extra HTTP dependencies, leveraging native fetch instead.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

Utilizing native fetch in modern Node.js environments reduces unnecessary external dependencies like axios, streamlining small-scale prototypes such as voice assistants for faster deployment and easier maintenance.

Next, create a .env file to store your credentials:

  • ELEVENLABS_API_KEY=your_elevenlabs_key_here
  • OPENAI_API_KEY=your_openai_key_here (optional for LLM integration)

Load these runtime values, and if you want your assistant to answer questions instead of just echoing input, hook up a tiny OpenAI helper. Run node index.js to see the prompt, type a query, watch the LLM response in the console, and hear the spoken audio through your speakers.

ElevenLabs also allows you to upload a brief 10-second sample of a target speaker to generate a custom voice ID. Using a curl request to https://api.elevenlabs.io/v1/voices/add with your xi-api-key, multipart form data containing name=MyClone, and the sample file files=@/path/to/sample.wav, you can create customized voices.

The API response returns a voice_id, which you can plug into the voiceId argument of your synthesize() function to make your custom voice speak the LLM output.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article