A Next.js application that provides real-time voice interaction using Google Cloud's Speech-to-Text, Vertex AI, and Text-to-Speech services.
- 🎤 Real-time voice recording
- 🗣️ Speech-to-Text transcription
- 🤖 AI-powered responses using Google Vertex AI
- 🔊 Text-to-Speech synthesis
- 🎨 Beautiful, responsive UI with dark mode support
- ⚡ Real-time status updates and progress indicators
- Frontend: Next.js 14, React 18, TypeScript, Tailwind CSS
- Backend: Next.js API Routes
- AI Services: Google Cloud Speech-to-Text, Vertex AI (Gemini), Text-to-Speech
- Deployment: Vercel
Before deploying, you need:
-
Google Cloud Project with the following APIs enabled:
- Speech-to-Text API
- Text-to-Speech API
- Vertex AI API
-
Service Account with appropriate permissions:
- Speech-to-Text User
- Text-to-Speech User
- Vertex AI User
-
Vercel Account for deployment
-
Clone the repository
git clone <your-repo-url> cd vapi-nextjs-app
-
Install dependencies
npm install
-
Set up environment variables Create a
.env.localfile:GOOGLE_CLOUD_PROJECT_ID=your-project-id GOOGLE_CLOUD_LOCATION=us-central1 GOOGLE_APPLICATION_CREDENTIALS=path/to/service-account-key.json
-
Run the development server
npm run dev
-
Open your browser Navigate to
http://localhost:3000
-
Create a service account key:
- Go to Google Cloud Console → IAM & Admin → Service Accounts
- Create a new service account or select existing one
- Create a new key (JSON format)
- Download the JSON file
-
Enable required APIs:
gcloud services enable speech.googleapis.com gcloud services enable texttospeech.googleapis.com gcloud services enable aiplatform.googleapis.com
-
Install Vercel CLI (optional):
npm i -g vercel
-
Deploy using Vercel Dashboard (Recommended):
- Push your code to GitHub/GitLab/Bitbucket
- Go to vercel.com
- Click "New Project"
- Import your repository
- Configure the following settings:
-
Set Environment Variables in Vercel:
- Go to your project settings in Vercel
- Navigate to "Environment Variables"
- Add the following variables:
GOOGLE_CLOUD_PROJECT_ID=your-project-id GOOGLE_CLOUD_LOCATION=us-central1 GOOGLE_APPLICATION_CREDENTIALS={"type":"service_account",...}
Important: For
GOOGLE_APPLICATION_CREDENTIALS, paste the entire content of your service account JSON file as a single line. -
Deploy:
- Click "Deploy"
- Vercel will automatically build and deploy your application
- Check the deployment logs for any errors
- Test the application by visiting your Vercel URL
- Check the function logs in Vercel dashboard if there are issues
| Variable | Description | Required |
|---|---|---|
GOOGLE_CLOUD_PROJECT_ID |
Your Google Cloud Project ID | Yes |
GOOGLE_CLOUD_LOCATION |
Google Cloud region (default: us-central1) | No |
GOOGLE_APPLICATION_CREDENTIALS |
Service account JSON credentials | Yes |
-
"Function timeout" errors:
- The API route is configured for 60 seconds max duration
- Check if your audio files are too large
- Ensure Google Cloud APIs are responding quickly
-
"Authentication failed" errors:
- Verify your service account has the correct permissions
- Check that the
GOOGLE_APPLICATION_CREDENTIALSis properly formatted - Ensure the APIs are enabled in your Google Cloud project
-
"Module not found" errors:
- The webpack configuration handles Google Cloud packages
- Ensure all dependencies are installed
- Check that the
next.config.jsis properly configured
-
Check Vercel Function Logs:
- Go to your Vercel dashboard
- Navigate to Functions tab
- Check the logs for
/api/voice
-
Test Locally First:
- Ensure everything works locally before deploying
- Use the same environment variables locally
-
Monitor Google Cloud:
- Check Google Cloud Console for API usage
- Monitor quotas and billing
vapi-nextjs-app/
├── app/
│ ├── api/voice/route.ts # Voice processing API
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main page
├── components/
│ └── ui/
│ ├── ai-voice-input.tsx # Voice input component
│ ├── aurora-background.tsx # Background component
│ └── aurora-background-demo.tsx
├── lib/
│ ├── error-handler.ts # Error handling utilities
│ ├── speech-to-text.ts # Speech-to-Text service
│ ├── text-to-speech.ts # Text-to-Speech service
│ ├── utils.ts # Utility functions
│ └── vertex-ai.ts # Vertex AI service
├── next.config.js # Next.js configuration
├── vercel.json # Vercel configuration
└── package.json # Dependencies
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
If you encounter any issues:
- Check the troubleshooting section above
- Review the Vercel and Google Cloud documentation
- Open an issue in the repository