This project demonstrates a voice AI agent that can manage Google Calendar events through natural conversation. It combines several cutting-edge technologies to create a seamless voice interaction experience.
Blog Post: How to Create a Google Calendar Voice Agent
- Natural voice conversations for calendar management
- Schedule, update, and cancel calendar events
- Check calendar availability
- Real-time voice processing with WebRTC
- Integration with Google Calendar API
- Voice Processing
- Daily.co for WebRTC audio calls
- Cartesia for Text-to-Speech
- Silero VAD for voice activity detection
- AI & Language Processing
- OpenAI GPT-4 for natural language understanding
- Custom calendar management tools
- Backend
- Python 3.12
- FastAPI
- Google Calendar API
- Infrastructure
- Docker containerization
- Poetry for dependency management
- Python 3.12
- Poetry package manager
- Docker (optional)
- API Keys:
- Cartesia API key for TTS
- Daily API key for WebRTC
- OpenAI API key
- Google Calendar API credentials:
- Client ID
- Client Secret
- Refresh Token
- Clone the repository
- Install dependencies:
poetry install
- Configure environment variables in
.env
:CARTESIA_API_KEY=your_key DAILY_API_KEY=your_key OPENAI_API_KEY=your_key GOOGLE_CLIENT_ID=your_client_id GOOGLE_CLIENT_SECRET=your_secret GOOGLE_REFRESH_TOKEN=your_token
poetry run python server.py
docker build -t calendar-assistant .
docker run -p 7860:7860 calendar-assistant
Access the application at http://localhost:7860
The application uses a pipeline architecture that processes:
- Audio input through Daily's WebRTC
- Voice activity detection with Silero
- Natural language processing with GPT-4
- Calendar operations through Google Calendar API
- Text-to-speech conversion with Cartesia
- Audio output back to the user
The assistant can:
- Create new calendar events (30-minute duration by default)
- Check free time slots between 9 AM and 5 PM
- Update existing calendar events (title, description, or time)
- Cancel/delete calendar events
- Handle multiple attendees for events
The voice interface provides:
- Real-time voice activity detection
- Natural conversation flow
- Interruption handling
- High-quality text-to-speech responses
- WebRTC-based audio streaming
The project uses:
- Poetry for dependency management
- Environment variables for configuration
- Async/await patterns for efficient I/O
- Logging with loguru
- Docker for containerization
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Calendar API:
- Navigate to "APIs & Services" > "Library"
- Search for "Google Calendar API"
- Click "Enable"
- Go to "APIs & Services" > "OAuth consent screen"
- Select "External" user type
- Fill in the required information:
- App name
- User support email
- Developer contact information
- Add scopes:
- Select "Google Calendar API"
- Add "./auth/calendar" and "./auth/calendar.events"
- Add test users (your Google email)
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Web application" as application type
- Name your client
- Add Authorized redirect URIs:
- Click "Create"
- Save your Client ID and Client Secret
- Create an authorization URL with these parameters:
https://accounts.google.com/o/oauth2/v2/auth ?client_id=YOUR_CLIENT_ID &redirect_uri=http://localhost:3000/callback &response_type=code &scope=https://www.googleapis.com/auth/calendar &access_type=offline &prompt=consent
- Open this URL in a browser
- Sign in with your Google account
- Approve the permissions
- You'll be redirected to your redirect URI with a code parameter
- Make a POST request to Google's token endpoint:
curl -X POST https://oauth2.googleapis.com/token \ -d "client_id=YOUR_CLIENT_ID" \ -d "client_secret=YOUR_CLIENT_SECRET" \ -d "code=YOUR_AUTH_CODE" \ -d "grant_type=authorization_code" \ -d "redirect_uri=http://localhost:3000/callback"
- The response will include your refresh token:
{ "access_token": "...", "refresh_token": "...", "scope": "https://www.googleapis.com/auth/calendar", "token_type": "Bearer", "expires_in": 3599 }
Add the credentials to your .env
file:
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_secret
GOOGLE_REFRESH_TOKEN=your_refresh_token
- The
access_type=offline
parameter is required to receive a refresh token - The
prompt=consent
parameter ensures you get a refresh token even if you've authenticated before - Refresh tokens don't expire unless explicitly revoked
- Store your refresh token securely - it grants long-term access to your calendar
- If you don't receive a refresh token:
- Ensure
access_type=offline
andprompt=consent
are included in the authorization URL - Revoke the application's access in Google Account settings and try again
- Ensure
- If you get authentication errors:
- Verify your redirect URI exactly matches what's configured in Google Cloud Console
- Check that all required scopes are included
- Ensure your client ID and secret are correct
- Verify your credentials are properly set in your
.env
file
This project is licensed under the MIT License - see the LICENSE file for details.