Add real-time voice to your own LLM-backed agent: a Speech Engine WebSocket server streams OpenAI responses to ElevenLabs, and a Next.js client starts WebRTC voice sessions.
-
Copy the environment file and add your credentials:
cp .env.example .env
Then edit
.envand set:ELEVENLABS_API_KEY— create one in the dashboardOPENAI_API_KEY— for the assistant LLM in the Speech Engine serverPUBLIC_WS_URL— publicwss://URL for your Speech Engine WebSocket (see step 2)
-
Expose port 3001 with ngrok (run this before creating the Speech Engine resource):
ngrok http 3001
Set
PUBLIC_WS_URLto your forwarding URL with/wsappended, for examplewss://abc123.ngrok-free.app/ws. -
Install dependencies:
pnpm install
-
Create the Speech Engine resource and enable client first-message overrides:
pnpm run speech-engine:create pnpm run speech-engine:enable-first-message
Copy the printed Speech Engine ID into
.envasELEVENLABS_SPEECH_ENGINE_ID.
Three processes must run together:
- ngrok —
ngrok http 3001 - Speech Engine server —
pnpm run speech-engine:server(port 3001) - Next.js app —
pnpm run dev(port 3000)
Open http://localhost:3000 in your browser.
- Click Start conversation and allow microphone access when prompted.
- Speak naturally; the agent responds with streamed speech. With
debug: trueon the server, transcripts and responses log to the terminal. - Click End conversation to stop the session.
- The agent greets first using
overrides.agent.firstMessage(requiresspeech-engine:enable-first-messageonce per Speech Engine ID).