LocalAI TTS support has been successfully added to the Two-AIs application. This allows users to connect to their own LocalAI server (via ngrok) and use it for text-to-speech generation, providing a free, self-hosted alternative to cloud TTS services.
- Updated
TTSProviderInfointerface to include'localai'as a valid provider ID - Added LocalAI provider to
AVAILABLE_TTS_PROVIDERSarray with dynamic model/voice discovery
setLocalAIModels(models: string[])
// Dynamically sets available LocalAI TTS models from the user's endpoint
setLocalAIVoices(modelId: string, voices: string[])
// Dynamically sets available voices for a specific LocalAI model
getLocalAIModels(): TTSModelDetail[]
// Returns currently available LocalAI models
getLocalAIVoicesForModel(modelId: string): TTSVoice[]
// Returns voices for a specific LocalAI model- Added collapsible LocalAI setup section between Ollama and InvokeAI sections
- Includes:
- LocalAI logo display
- ngrok URL verification form with helper toggle
- Model discovery and display
- Error handling and status messages
- All necessary state variables were already present:
localaiEndpoint,localaiSubdomaincustomLocalaiAvailable,customLocalaiLoadinglocalaiVerifyError,localaiHelperEnabledlocalaiModelNames
- Now calls
setLocalAIModels()to update the global TTS provider registry - Properly handles model discovery and error states
- Added
setLocalAIModelsandsetLocalAIVoicesimports fromtts_models.ts
handleVerifyLocalAI: Now updates global TTS models registrydiscoverLocalAIVoices: Now updates global TTS voices registry for specific models
The SessionSetupForm already had comprehensive LocalAI TTS UI including:
- LocalAI endpoint verification section
- Model selection dropdown
- Voice discovery button
- Voice selection dropdown
- Integration with conversation start logic
The following API routes were already implemented:
/api/localai/verify- Verifies LocalAI endpoint connectivity/api/localai/tts- Proxies TTS generation requests/api/localai/voices- Discovers available voices for a model
src/hooks/useLocalAITTSGen.ts - Handles automatic TTS generation for LocalAI during conversations
-
Landing Page Setup
- User enters their ngrok forwarding URL for LocalAI
- Clicks "Verify" to test connection
- Available models are discovered and displayed
- Models are registered in the global TTS provider registry
-
Session Configuration
- User navigates to session setup
- Verifies LocalAI endpoint again (if needed)
- Selects a TTS model from dropdown
- Clicks "Discover" to find available voices for that model
- Selects a voice for each agent
- Voices are registered in the global TTS provider registry
-
During Conversation
- As agents respond,
useLocalAITTSGenhook monitors messages - For each paragraph, it calls
/api/localai/ttsto generate audio - Audio is stored in Firebase Storage
- Audio URLs are attached to message paragraphs
- User can play audio with auto-scroll support
- As agents respond,
User Input (ngrok URL)
↓
/api/localai/verify
↓
setLocalAIModels(models)
↓
AVAILABLE_TTS_PROVIDERS updated
↓
User selects model
↓
/api/localai/voices
↓
setLocalAIVoices(modelId, voices)
↓
AVAILABLE_TTS_PROVIDERS updated
↓
User starts conversation
↓
useLocalAITTSGen monitors messages
↓
/api/localai/tts generates audio
↓
Audio stored in Firebase
↓
User plays audio
- Models and voices are discovered at runtime from the user's LocalAI endpoint
- No hardcoded model/voice lists needed
- Adapts to whatever the user has installed
- Supports ngrok forwarding URLs for remote access
- Helper toggle for easy URL construction
- Proper error handling for common ngrok issues (403 Forbidden)
- Audio is generated per paragraph, not per full message
- Enables better auto-scrolling during playback
- Allows for lookahead generation while user listens
- Audio files are stored in Firebase Storage
- Enables playback of historical conversations
- Works even when LocalAI is offline (for past conversations)
src/lib/tts_models.ts- Added LocalAI provider and helper functionssrc/components/LandingPage.tsx- Updated verification handlersrc/components/session/SessionSetupForm.tsx- Updated verification and voice discovery
src/app/api/localai/verify/route.tssrc/app/api/localai/tts/route.tssrc/app/api/localai/voices/route.tssrc/hooks/useLocalAITTSGen.tspublic/localai.svg- Logo file
- Build succeeds without errors
- Landing page displays LocalAI setup section
- LocalAI endpoint verification works
- Models are discovered and displayed
- Session setup shows LocalAI as TTS option
- Voice discovery works for selected model
- Conversation starts with LocalAI TTS enabled
- Audio is generated during conversation
- Audio playback works
- Auto-scroll works with LocalAI audio
- Historical conversations play LocalAI audio
-
Voice Discovery: LocalAI backends may not always return voice lists reliably. The
/api/localai/voicesroute attempts to extract voices from error messages as a fallback. -
Language Support: LocalAI models don't report supported languages, so language filtering is not available for LocalAI TTS.
-
Model Metadata: LocalAI doesn't provide detailed model information (pricing, limits, etc.), so generic defaults are used.
- Voice Preview: Add preview functionality for LocalAI voices (similar to Browser TTS)
- Model Caching: Cache discovered models/voices to reduce API calls
- Better Error Messages: More specific error messages for common LocalAI issues
- Model Metadata: If LocalAI adds metadata endpoints, integrate them
- Streaming Support: Investigate streaming TTS for lower latency
LocalAI TTS support is now fully integrated into the Two-AIs application. Users can connect their self-hosted LocalAI servers and use them for free, high-quality text-to-speech generation. The implementation follows the existing patterns for Ollama and InvokeAI, providing a consistent user experience across all self-hosted services.