Build a Voice Agent with JavaScript
Create a real-time voice agent using the Deepgram JavaScript SDK.
This tutorial walks you through building a basic voice agent using JavaScript and the Deepgram SDK. You will learn how to connect to the Agent API, configure its behavior, and stream audio for processing.
Prerequisites
Before you begin, ensure you have the following:
- A Deepgram API key. You can get one in the Deepgram Console.
- Node.js installed on your machine.
1. Set up your environment
Create a new directory for your project and initialize it.
Export your Deepgram API key as an environment variable.
2. Install the Deepgram SDK
Install the Deepgram JavaScript SDK and cross-fetch for audio streaming.
3. Create the Voice Agent
Open index.js and add the following code. This script connects to Deepgram, configures the agent, and streams a sample audio file.
4. Run the Voice Agent
Run your script using Node.js.
The agent will process the audio and generate responses. You can find the conversation transcript in chatlog.txt and the agent’s audio responses in output-*.wav files.
Next steps
Now that you have built a basic agent, you can customize its behavior:
- Configure the Voice Agent: Explore all available settings for models and voices.
- Build a Voice Agent: Return to the overview to see other language options.