Prerequisites
Before you begin, make sure you have:- Node.js 20 or higher
- An OpenAI API key with Realtime API access
- A package manager (npm, yarn, or pnpm)
NAVAI uses the OpenAI Realtime API for voice interactions. You’ll need an API key from OpenAI Platform.
Installation
Install the packages
Install the NAVAI packages you need. For a full-stack setup, install all three:
Choose packages based on your platform:
- Backend: All apps need
@navai/voice-backend - Web: Use
@navai/voice-frontendfor React web apps - Mobile: Use
@navai/voice-mobilefor React Native/Expo
Set up your backend
Create an Express server and register NAVAI routes. This mints secure client secrets and exposes function execution endpoints.This registers three routes:
server.ts
POST /navai/realtime/client-secret- Issues ephemeral tokensGET /navai/functions- Lists available backend functionsPOST /navai/functions/execute- Executes backend functions
Integrate voice in your frontend
Use the The agent now responds to voice commands like:
useWebVoiceAgent hook to add voice control to your React app.App.tsx
- “Navigate to settings”
- “Go to the home page”
- “Execute [your custom function]”
Test your voice agent
Start your backend and frontend, then click “Start Voice” and speak a command.Try saying:
- “Navigate to settings”
- “Show me the dashboard”
Troubleshooting common issues
Troubleshooting common issues
Microphone not working: Make sure your browser has microphone permissions enabled.Connection errors: Verify your backend is running and
NAVAI_API_URL points to the correct address.No voice response: Check that OPENAI_API_KEY is set correctly and has Realtime API access.CORS errors: Add your frontend origin to your backend’s CORS configuration.Next steps
Now that you have a working voice agent, explore advanced features:Create custom functions
Define backend and frontend functions that the voice agent can execute
Configure routes
Set up voice navigation for your application’s routes
Environment variables
Configure behavior with environment variables
Mobile integration
Add voice control to React Native and Expo apps