Voice audio works perfectly in local development but fails in production hosted environment. Text displays correctly, but no audio playback occurs.
Audio Pipeline:
- User sends message → LLM generates response
- Backend generates TTS audio via ElevenLabs API
- Audio converted to base64 and sent via WebSocket
- Frontend receives base64 audio and plays through HTML5 Audio API
Backend (chat.py:244-256):
- ✅ TTS service generates MP3 audio (ElevenLabs)
- ✅ Audio converted to base64
- ✅ Sent via WebSocket as
audiomessage type - ✅ Uses
/tmpdirectory for Railway deployment
Frontend (ChatInterface.tsx:50-61):
- ✅
playAudio()function receives base64 audio - ✅ Sets audio source as data URL
- ✅ Calls
.play()on audio element - ✅ FIXED: Browser autoplay policy handled (lines 36-47, 190, 286)
Environment Configuration:
- ✅ ElevenLabs API key present in
.env ⚠️ Production URLs not configured (still showing placeholders)⚠️ .env.localuses localhost URLs
Issue: Frontend .env.local still points to localhost
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
NEXT_PUBLIC_WS_URL=ws://localhost:8000/api/v1/chat/ws/chat
Impact: Frontend may not be connecting to production backend correctly
Fix Required:
- Set production environment variables in Vercel
- Update to actual Railway backend URLs (wss:// for WebSocket)
Issue: Modern browsers block autoplay on HTTPS without user interaction
Fix Applied: Commit 0004f13 implemented:
- Silent audio playback on first user interaction
audioEnabledstate tracking- Triggered on message send or call start
Status: Should be working, but verify deployment has latest code
Issue: If WebSocket isn't connecting properly, audio messages won't arrive
Indicators to Check:
- Console errors about WebSocket connection
type: 'audio'messages not being received- Network tab showing failed WebSocket upgrade
Issue: Backend CORS_ORIGINS may not include production frontend URL
Current Setting:
CORS_ORIGINS=http://localhost:3000,https://your-app.vercel.appFix Required: Update with actual Vercel deployment URL
Issue: Backend may not have ElevenLabs API key in Railway environment
Fix Required: Verify Railway has ELEVENLABS_API_KEY set
Vercel Dashboard:
- Verify
NEXT_PUBLIC_API_URLpoints to Railway URL - Verify
NEXT_PUBLIC_WS_URLuseswss://protocol - Redeploy after setting variables
Railway Dashboard:
- Verify
ELEVENLABS_API_KEYis set - Verify
CORS_ORIGINSincludes Vercel URL - Check deployment logs for TTS errors
Open Production Site → Browser DevTools:
- Check Console for WebSocket connection errors
- Check Console for audio playback errors
- Look for "Audio enabled successfully" message
- Check Network tab for WebSocket messages
Railway Logs:
# Look for these log messages:
- "Generating TTS for response"
- "TTS generated successfully"
- "Audio message sent to client"
- Any "TTS generation failed" errorsBrowser Console:
// Check if audio messages are being received
// Look for: {type: "audio", audio_base64: "..."}Vercel (Frontend):
- Get actual Railway backend URL (e.g.,
https://vera-api.up.railway.app) - Set environment variables in Vercel dashboard:
NEXT_PUBLIC_API_URL=https://[your-railway-url]/api/v1 NEXT_PUBLIC_WS_URL=wss://[your-railway-url]/api/v1/chat/ws/chat - Redeploy frontend
Railway (Backend):
- Get actual Vercel frontend URL (e.g.,
https://vera.vercel.app) - Set environment variables in Railway dashboard:
ELEVENLABS_API_KEY=sk_YOUR_ELEVENLABS_API_KEY_HERE CORS_ORIGINS=https://[your-vercel-url] - Redeploy backend
Check:
- Latest commit (
0004f13or later) deployed to production -
enableAudio()function exists in production bundle - Console shows "Audio enabled successfully" on first interaction
If issue persists, add logging to production:
Backend enhancement (chat.py:244-261):
# Add more detailed logging
print(f"TTS API Key present: {bool(settings.ELEVENLABS_API_KEY)}")
print(f"Audio base64 length: {len(audio_base64)} bytes")Frontend enhancement (ChatInterface.tsx:89-96):
case 'audio':
console.log('Audio message received:', {
hasAudioData: !!data.audio_base64,
audioLength: data.audio_base64?.length,
audioEnabled: audioEnabled,
audioRefExists: !!audioRef.current
});If audio continues to fail silently, notify user:
// In ChatInterface.tsx playAudio function
.catch((error) => {
console.error('Audio playback failed:', error);
// Add user-visible notification
alert('Audio playback is unavailable. Please check browser settings.');
});- Audio works in development mode
- WebSocket connects successfully
- Console shows "Audio enabled successfully"
- Console shows "Audio message sent to client"
- Frontend connects to backend WebSocket
- CORS allows connection
- Audio messages received in browser
- Audio plays after first user interaction
- No console errors related to audio
- Browser DevTools Network tab shows WebSocket with audio messages
┌─────────────────────┐
│ Vercel (Frontend) │
│ vera.vercel.app │
│ │
│ - Next.js App │
│ - WebSocket Client │
│ - HTML5 Audio │
└──────────┬──────────┘
│ wss://
▼
┌─────────────────────┐
│ Railway (Backend) │
│ vera-api.railway │
│ │
│ - FastAPI │
│ - WebSocket Server │
│ - TTS Service │
└──────────┬──────────┘
│ HTTPS API
▼
┌─────────────────────┐
│ ElevenLabs API │
│ Text-to-Speech │
└─────────────────────┘
Cause: Frontend trying to connect to localhost in production
Fix: Set correct NEXT_PUBLIC_WS_URL in Vercel
Cause: CORS blocking connection or wrong protocol (ws:// vs wss://)
Fix: Use wss:// for production, add origin to CORS_ORIGINS
Cause: Browser autoplay policy blocking audio
Fix: Already fixed in commit 0004f13, verify deployed
Cause: Backend TTS failing silently
Fix: Check Railway logs, verify ELEVENLABS_API_KEY set
Cause: Audio element not rendered
Fix: Verify <audio ref={audioRef}> exists in DOM
- Production site loads without console errors
- WebSocket connects (check Network tab)
- User can send message successfully
- VERA responds with streaming text
- Console shows "Audio message sent to client" (backend logs)
- Console shows "Received audio message: Audio data present" (frontend)
- Audio plays automatically after first user interaction
- No "Audio playback failed" errors
- Immediate: Check Vercel and Railway environment variables
- Immediate: Get actual production URLs and update configs
- Quick: Verify latest code deployed to both platforms
- Quick: Check Railway logs for TTS errors
- If needed: Add enhanced debugging logging
- If needed: Test with different browsers
- Future: Add user-visible audio status indicator
Backend:
- vera-api/app/api/endpoints/chat.py:244-261 - TTS generation
- vera-api/app/services/tts_service.py - ElevenLabs integration
- vera-api/app/core/config.py - Environment config
Frontend:
- vera-frontend/components/ChatInterface.tsx:35-47 - Audio enablement
- vera-frontend/components/ChatInterface.tsx:50-61 - Audio playback
- vera-frontend/components/ChatInterface.tsx:89-96 - Audio message handling
- vera-frontend/hooks/useWebSocket.ts - WebSocket connection
Configuration:
- Railway environment variables
- Vercel environment variables
- vera-api/railway.toml - Railway config
- Railway Dashboard: Check deployment logs and environment variables
- Vercel Dashboard: Check deployment status and environment variables
- Browser DevTools: Console + Network tab for debugging
- ElevenLabs Dashboard: Check API usage and quota