Next.js app with voice commands via WebRTC and OpenAI. Includes JavaScript SDK for website integration.
app/
- Next.js App Router codepage.tsx
- Entry point for the web applicationlayout.tsx
- Root layoutglobals.css
- Global stylesapi/
- Backend endpointslog/
- Application loggingsession/
- Session managementinternal/
- Internal API endpointslog/
- Internal loggingsession/
- Internal session management
v1/
- API endpoints for SDKauth/validate/
- Client validationsessions/
- Session managementvoice/token/
- Voice processing tokensvoice/text-log/
- Text log storage
components/
- React componentswebapp/
- Web application componentsChatGPT.tsx
- OpenAI voice processing component
hooks/
- Custom React hookslogger.ts
- Logging utilitieswebapp/
- Web application hooksuse-webrtc.ts
- Voice capture via WebRTC
lib/
- Utility librariessecurity.ts
- Client validationsessions.ts
- Session managementstorage/
- Storage providerssupabase-storage.ts
- Supabase storage implementationinterface.ts
- Storage provider interfaceindex.ts
- Storage factory
supabase.ts
- Supabase client
prompts/
- OpenAI prompt templatesagent-instructions.ts
- Instructions for the voice assistant
public/
- Static assetsfile.svg
,globe.svg
,next.svg
,vercel.svg
,window.svg
- UI iconssdk/
- Voice AI SDK filesdemo.html
- SDK demo pagevoice-ai-sdk.js
- Main SDKvoice-ai-sdk.min.js
- Minified SDKvoice-ai-styles.css
- SDK styles
scripts/
- Utility scriptsdeploy-sdk.sh
- SDK deployment scriptsimple-supabase-setup.sql
- SQL script for Supabase setup (required for tables and permissions)
tests/
- Test filesdist/
- Distribution files (in gitignore, but shown for reference)sdk/
- Compiled SDK filesREADME.md
- SDK documentationdemo.html
- SDK demo pageversion.json
- SDK version informationvoice-ai-sdk.min.js
- Minified SDKvoice-ai-styles.css
- SDK styles
.env.local
- Environment variables (not committed)NEXT_PUBLIC_OPENAI_API_KEY
- OpenAI API keyALLOWED_CLIENTS
- Authorized clientsCLIENT_*_DOMAINS
- Allowed domainsNEXT_PUBLIC_SUPABASE_URL
- Supabase URLNEXT_PUBLIC_SUPABASE_ANON_KEY
- Supabase anonymous key
next.config.ts
- Next.js configpackage.json
- Dependenciespostcss.config.mjs
- PostCSS configurationtailwind.config.ts
- Styling configtsconfig.json
- TypeScript configINTEGRATION.md
- SDK integration guideREADME.md
- Project documentation
page.tsx
→components/webapp/ChatGPT
component- WebRTC captures voice via
hooks/webapp/use-webrtc.ts
- ChatGPT processes commands using prompts from
prompts/agent-instructions.ts
- Voice assistant responds to user
- SDK enables integration on any website
Create .env.local
from .env.local.example
and add your API keys:
# OpenAI API Key
NEXT_PUBLIC_OPENAI_API_KEY=your_openai_api_key
# Supabase configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
IMPORTANT: This step is absolutely necessary before using ANY functionality in this repository. Both the main web application AND the analysis tools require these environment variables to be properly set.
- Create a Supabase project at supabase.com
- Get your project URL and anon key from the project settings
- Run the SQL script in
scripts/simple-supabase-setup.sql
in the Supabase SQL editor to create the necessary tables and indexes- This script creates the required tables (
text_logs
andsessions
) - Sets up indexes for efficient querying
- Configures Row Level Security (RLS) policies for proper access control
- Important: This step must be completed before using the application with Supabase
- This script creates the required tables (
npm install
npm run dev
Open http://localhost:3000 in your browser
This application is designed to be deployed on Vercel. The Supabase integration ensures that all data is stored in the database rather than the filesystem, making it compatible with Vercel's serverless environment.
- Push your code to a Git repository
- Connect the repository to Vercel
- Add the environment variables in the Vercel project settings
- Deploy the application
- Voice command processing via WebRTC
- Server-side OpenAI integration for enhanced security
- JavaScript SDK for easy integration into any website
- Customizable UI with multiple themes and positions
- Session management and client validation
- Comprehensive logging system
First, clone the repository and install dependencies:
git clone https://github.com/your-username/voice-ai.git
cd voice-ai
npm install
Create a .env.local
file based on the .env.local.example
template and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key
# Additional environment variables as specified in .env.local.example
Then, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3000 with your browser to see the result.
app/
- Next.js App Router codepage.tsx
- Entry point, renders ChatGPT componentlayout.tsx
- Root layoutglobals.css
- Global styleschatgpt.tsx
- OpenAI voice processingapi/
- Backend endpointslog/
- Application loggingsession/
- Session managementv1/
- API endpoints for SDKvoice/process/
- WebRTC offer processingauth/validate/
- Client validationsessions/
- Session management
hooks/
- Custom React hooksuse-webrtc.ts
- Voice capture via WebRTClogger.ts
- Logging utilities
lib/
- Utility librariessecurity.ts
- Client validation utilitiessessions.ts
- Session management utilitiesopenai-webrtc.ts
- Server-side OpenAI WebRTC integrationopenai-sessions.ts
- OpenAI session management
prompts/
- OpenAI prompt templatesagent-instructions.ts
- Instructions for the voice assistant
public/sdk/
- JavaScript SDK filesvoice-ai-sdk.js
- Main SDK filevoice-ai-sdk.min.js
- Minified SDK for productionvoice-ai-styles.css
- SDK stylesdemo.html
- Demo page for SDK
The Voice AI SDK can be easily integrated into any website. For detailed integration instructions, see the INTEGRATION.md file.
Basic integration example:
<!-- Include the SDK -->
<script src="https://your-domain.com/sdk/voice-ai-sdk.min.js"></script>
<link rel="stylesheet" href="https://your-domain.com/sdk/voice-ai-styles.css">
<!-- Initialize the SDK -->
<script>
document.addEventListener('DOMContentLoaded', function() {
window.VoiceAI.init({
clientId: 'your_client_id',
serverUrl: 'https://your-voice-ai-server.com',
position: 'bottom-right',
theme: 'light'
});
});
</script>
This project uses a server-side approach for OpenAI integration, which provides several benefits:
- Enhanced Security: The OpenAI API key is kept securely on the server and never exposed to the client.
- Centralized Control: All interactions with OpenAI are managed by the server, allowing for monitoring and logging.
- Simplified Client: The client SDK only needs to handle WebRTC connection setup and UI management.
For more details on the server-side integration, see SERVER_SIDE_INTEGRATION.md.
A demo page is available at http://localhost:3000/sdk/demo.html when running the development server. This demo showcases the SDK's features and allows you to test different configurations.
The project uses Jest for testing. To run the tests locally:
npm test
Tests are automatically run on GitHub Actions for every pull request and push to the main branch. The test status is displayed in the badge at the top of this README.
PREREQUISITE: Before using any analysis tools, make sure you have created the .env.local
file from .env.local.example
as described in the Setup section above. The analysis tools require access to the same environment variables.
- All Python dependencies must be added to
analysis/requirements.txt
, not installed globally
To learn more about the technologies used in this project:
- Next.js Documentation - learn about Next.js features and API
- WebRTC API - Web Real-Time Communication
- OpenAI API - OpenAI API reference