Transform any topic into gentle, educational songs for preschoolers (ages 3-5)
Built for EmoryHack 2024 | Powered by AI | Designed for Learning
- Overview
- Key Features
- Architecture
- Tech Stack
- System Flow
- Project Structure
- Quick Start
- Detailed Setup
- API Documentation
- Frontend Features
- Deployment
- Contributing
- License
12Tree is an AI-powered educational platform that generates custom songs for preschool children. Simply enter any topic (like "sun", "butterfly", or "friendship"), and our system creates:
- β Gentle, age-appropriate lyrics that teach concepts
- β Professional singing vocals via ElevenLabs AI
- β Custom background music perfectly synced
- β Beautiful karaoke-style player
- β Personal library to save favorites
Perfect for:
- πΆ Parents teaching their toddlers
- π¨βπ« Preschool teachers creating lesson content
- π Educational content creators
- π Homeschooling families
- Instant Song Generation: Create custom educational songs in 30-60 seconds
- User Authentication: Secure sign-up/login with password hashing (bcrypt)
- Personal Library: Save and organize your favorite songs
- Beautiful UI: Colorful, kid-friendly interface with smooth animations
- Karaoke Mode: Display all lyrics while song plays
- Multi-User Support: Each user has their own private library
- Smart Lyrics: Gemini 2.5 Flash generates meaningful, educational content
- Realistic Singing: ElevenLabs TTS with singing voice configuration
- Custom Music: Randomly selected background tracks trimmed to vocal length
- Audio Mixing: Professional-quality mixing with fade-outs
- Caching System: Instant replay of previously generated songs
- Async Processing: Real-time progress updates during generation
- Age-Appropriate: Gentle, soothing content for 3-5 year olds
- Meaningful Lyrics: Each line teaches something about the topic
- Natural Language: Simple words kids already know
- Safe Content: No harsh words, pirate exclamations, or inappropriate themes
- Clear Pronunciation: Optimized for learning and sing-along
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 12Tree Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
β β β Backend Layer β
β React Frontend βββββββββββΊβ FastAPI + Celery + Redis β
β (TypeScript) β REST β β
β β API β ββββββββββββββββββββββββββ β
β - Login/Signup β β β Core Services: β β
β - Music Mode β β β - User Auth (bcrypt) β β
β - Library β β β - Lyrics (Gemini) β β
β - Karaoke UI β β β - Vocals (ElevenLabs) β β
β β β β - Audio Mixing β β
ββββββββββββββββββββ β β - Background Music β β
β ββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββ β
β β Task Queue: β β
β β - Celery Workers β β
β β - Redis Broker β β
β ββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data & Storage β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β MongoDB Atlas β
β - Users (authentication) β
β - UserLibrary (saved songs per user) β
β - SongCache (generated songs) β
β - Jobs (task status) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β External APIs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π€ Gemini 2.5 Flash β Lyrics Generation β
β ποΈ ElevenLabs TTS β Singing Voice Synthesis β
β π΅ Custom Music Files β Background Instrumentals β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Technology | Version | Purpose |
|---|---|---|
| React | 18.x | UI framework |
| TypeScript | 5.x | Type safety |
| Vite | 5.x | Build tool & dev server |
| Tailwind CSS | 3.x | Styling |
| React Router | 6.x | Navigation |
| Technology | Version | Purpose |
|---|---|---|
| FastAPI | 0.104+ | REST API framework |
| Python | 3.10+ | Backend language |
| Celery | 5.3+ | Async task queue |
| Redis | 5.0+ | Message broker |
| Pydantic | 2.5+ | Data validation |
| bcrypt | 4.1+ | Password hashing |
| Technology | Version | Purpose |
|---|---|---|
| MongoDB | 6.0+ | Primary database |
| Beanie | 1.24+ | Async ODM |
| Motor | 3.3+ | Async MongoDB driver |
| Technology | Version | Purpose |
|---|---|---|
| Gemini API | 2.5 Flash | Lyrics generation |
| ElevenLabs | 1.5+ | TTS singing vocals |
| Bark | Latest | Fallback TTS |
| pydub | 0.25+ | Audio processing |
| librosa | 0.10+ | Audio analysis |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Song Generation Flow β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. USER INPUT
β
βββΊ User enters topic (e.g., "butterfly")
β
βΌ
2. RHYME GENERATION
β
βββΊ pronouncing library finds kid-friendly rhyming words
βββΊ Filters out pirate/harsh words
β
βΌ
3. LYRICS CREATION (Gemini AI)
β
βββΊ Prompt: "Create gentle, educational song about [topic]"
βββΊ Requirements: 4-6 lines, age-appropriate, meaningful
βββΊ Safety filter: Remove any pirate exclamations
βββΊ Output: Clean, educational lyrics
β
βΌ
4. VOCAL SYNTHESIS (ElevenLabs)
β
βββΊ Format: "[singing gently and sweetly like a lullaby]"
βββΊ Settings: style=0.8, stability=0.3 for singing
βββΊ Voice: Child-friendly preset
βββΊ Output: High-quality singing vocals (.mp3)
β
βΌ
5. BACKGROUND MUSIC
β
βββΊ Select random track from 4 custom tracks
βββΊ Trim to exact vocal duration
βββΊ Apply 1-second fade-out
β
βΌ
6. AUDIO MIXING
β
βββΊ Load vocals and background
βββΊ Mix: vocals (100%) + instrumental (40%)
βββΊ Export final song (.mp3, 192kbps)
β
βΌ
7. METADATA & CACHING
β
βββΊ Calculate BPM, duration
βββΊ Generate timings for karaoke
βββΊ Save to MongoDB SongCache
βββΊ Return to user (instant on replay!)
β
βΌ
8. USER LIBRARY
β
βββΊ User can save to personal library
βββΊ Stored in MongoDB with user_id
SIGNUP LOGIN
β β
βββΊ Username + Email + Password β
βββΊ Validate (unique, length) βββΊ Username + Password
βββΊ Hash password (bcrypt) βββΊ Find user in MongoDB
βββΊ Save to MongoDB Users βββΊ Verify password
βββΊ Auto-login βββΊ Update last_login
β β
ββββββββββββββββββ¬βββββββββββββββ
β
βΌ
Store in localStorage
β
βΌ
User can access library
EmoryHack/
β
βββ Frontend/ # React Frontend
β βββ 12Tree-frontend/
β βββ src/
β β βββ api/
β β β βββ index.ts # API client, auth functions
β β βββ components/
β β β βββ FullScreenPlayer.tsx # Karaoke player
β β β βββ MusicMode.tsx # Song generation UI
β β β βββ LibrarySongItem.tsx # Library items
β β β βββ Toast.tsx # Notifications
β β βββ pages/
β β β βββ Login.tsx # Login page
β β β βββ Signup.tsx # Signup page
β β β βββ Library.tsx # User's saved songs
β β β βββ Learn.tsx # Main dashboard
β β βββ context/
β β β βββ AppContext.tsx # Global state (user)
β β βββ hooks/
β β β βββ useSongs.ts # Fetch user library
β β βββ main.tsx # App entry point
β βββ package.json
β βββ vite.config.ts
β
βββ app/ # FastAPI Backend
β βββ main.py # FastAPI application
β βββ config.py # Settings (env variables)
β βββ database.py # MongoDB connection
β βββ models.py # Beanie models
β β # - User
β β # - Job
β β # - SongCache
β β # - UserLibrary
β βββ tasks.py # Celery background tasks
β βββ services/
β βββ rhyme_service.py # Rhyme generation
β βββ lyrics_service.py # Gemini lyrics AI
β βββ vocal_service.py # ElevenLabs/Bark TTS
β βββ background_music_service.py # Music track manager
β βββ beat_generator.py # Fallback beat generator
β βββ audio_service.py # Audio mixing utilities
β
βββ background_music/ # Custom Music Tracks
β βββ track1.mp3
β βββ track2.mp3
β βββ track3.mp3
β βββ track4.mp3
β βββ README.md
β
βββ outputs/ # Generated songs
βββ temp/ # Temporary files
βββ Docs/ # Documentation
β βββ QUICKSTART.md
β βββ CUSTOM_MUSIC_SETUP.md
β βββ OPTIMIZATION_GUIDE.md
β βββ ...
β
βββ requirements.txt # Python dependencies
βββ .env # Environment variables
βββ .env.example # Template
βββ README.md # This file
Ensure you have the following installed:
- Node.js 18+ and npm
- Python 3.10+
- MongoDB (local or Atlas)
- Redis (local or cloud)
git clone <your-repo-url>
cd EmoryHack# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment variables
cp .env.example .env
nano .env # Add your API keysRequired Environment Variables:
# .env file
GEMINI_API_KEY=your_gemini_api_key_here
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
MONGODB_URL=your_mongodb_connection_string
REDIS_URL=redis://localhost:6379/0
# Optional
USE_CUSTOM_BACKGROUND_MUSIC=True
TTS_PROVIDER=elevenlabscd Frontend/12Tree-frontend
# Install dependencies
npm install
# Configure API URL (if needed)
echo "VITE_API_URL=http://localhost:8000" > .env
# Build for production (optional)
npm run buildPlace your 4 MP3 tracks in background_music/:
background_music/
βββ track1.mp3
βββ track2.mp3
βββ track3.mp3
βββ track4.mp3Terminal 1 - Redis:
redis-serverTerminal 2 - MongoDB:
mongod # If running locally
# Or use MongoDB Atlas (cloud)Terminal 3 - Celery Worker:
cd EmoryHack
source venv/bin/activate
celery -A app.tasks worker --loglevel=infoTerminal 4 - FastAPI Backend:
cd EmoryHack
source venv/bin/activate
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Terminal 5 - React Frontend:
cd Frontend/12Tree-frontend
npm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
Option 1: Local MongoDB
# Install MongoDB
# Ubuntu/Debian:
sudo apt-get install mongodb
# macOS:
brew install mongodb-community
# Start MongoDB
mongodOption 2: MongoDB Atlas (Recommended)
- Go to https://www.mongodb.com/cloud/atlas
- Create free M0 cluster
- Get connection string
- Add to
.env:MONGODB_URL=mongodb+srv://...
Option 1: Local Redis
# Ubuntu/Debian:
sudo apt-get install redis-server
# macOS:
brew install redis
# Start Redis
redis-serverOption 2: Redis Cloud (Recommended)
- Go to https://redis.com/try-free/
- Create free 30MB database
- Get connection URL
- Add to
.env:REDIS_URL=redis://...
Gemini API (Free):
- Visit https://ai.google.dev/
- Click "Get API Key"
- Create new key
- Add to
.env:GEMINI_API_KEY=...
ElevenLabs API:
- Visit https://elevenlabs.io/
- Sign up for free account (10,000 characters/month)
- Get API key from settings
- Add to
.env:ELEVENLABS_API_KEY=...
POST /api/auth/signup
Content-Type: application/json
{
"username": "john_doe",
"email": "[email protected]",
"password": "secure123"
}Response:
{
"message": "Account created successfully",
"user": {
"username": "john_doe",
"email": "[email protected]"
}
}POST /api/auth/login
Content-Type: application/json
{
"username": "john_doe",
"password": "secure123"
}Response:
{
"message": "Login successful",
"user": {
"username": "john_doe",
"email": "[email protected]"
}
}POST /api/generate
Content-Type: application/json
{
"word": "butterfly"
}Response:
{
"job_id": "abc-123-def-456",
"status": "processing",
"progress": 0
}GET /api/jobs/{job_id}Response (Processing):
{
"job_id": "abc-123",
"status": "processing",
"progress": 45,
"error": null
}Response (Completed):
{
"job_id": "abc-123",
"status": "completed",
"progress": 100,
"result": {
"word": "butterfly",
"lyrics": "The butterfly is soft and light\nIt dances in the air...",
"audio_url": "/outputs/song_abc123.mp3",
"timings": [
{"word": "The", "start": 0.0, "end": 0.2},
{"word": "butterfly", "start": 0.2, "end": 0.8}
],
"duration": 25.5,
"bpm": 95.0
}
}POST /api/library/songs
Content-Type: application/json
{
"userId": "john_doe",
"title": "The Butterfly Song",
"lyrics": "...",
"audioUrl": "/outputs/song_abc.mp3",
"timings": [...],
"duration": 25.5,
"bpm": 95.0
}GET /api/library/songs?user_id=john_doeResponse:
{
"songs": [
{
"id": "507f1f77bcf86cd799439011",
"title": "The Butterfly Song",
"lyrics": "...",
"audioUrl": "/outputs/song_abc.mp3",
"timings": [...],
"duration": 25.5,
"bpm": 95.0,
"addedAt": "2024-11-15T12:00:00"
}
]
}DELETE /api/library/songs/{song_id}GET /api/cache/{word}DELETE /api/cache/{word}-
Login / Signup
- Secure authentication with validation
- Password confirmation
- Auto-login after signup
-
Music Mode
- Topic input with instant validation
- Real-time progress bar (0-100%)
- Full-screen karaoke player
- Add to library button
-
Library
- Display all saved songs
- Play songs instantly (from cache)
- Delete songs
- Empty state UI
-
Karaoke Player
- Full-screen gradient background
- Display all lyrics at once (no line-by-line)
- Play/pause, skip Β±5s controls
- Progress bar with seek
- Beautiful animations
- Responsive Design: Works on desktop, tablet, mobile
- Smooth Animations: Tailwind transitions and transforms
- Toast Notifications: Success/error messages
- Loading States: Skeletons and spinners
- Error Handling: User-friendly error messages
- Persistent Auth: localStorage for staying logged in
- Railway (Recommended):
# Install Railway CLI
npm install -g @railway/cli
# Login
railway login
# Deploy
railway up-
Environment Variables:
- Add all
.envvariables to Railway dashboard - Set
MONGODB_URLto Atlas connection string - Set
REDIS_URLto Redis Cloud URL
- Add all
-
Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORTVercel:
# Install Vercel CLI
npm install -g vercel
# Deploy
cd Frontend/12Tree-frontend
vercel --prodBuild Settings:
- Build Command:
npm run build - Output Directory:
dist - Environment Variable:
VITE_API_URL=https://your-backend.railway.app
- Create M0 free cluster
- Add IP whitelist (0.0.0.0/0 for development)
- Create database user
- Get connection string
- Replace in
.env
- Create 30MB free database at https://redis.com/try-free/
- Get connection URL
- Replace in
.env
# Simplified pseudocode
def generate_song(word: str):
# 1. Find rhymes (5-10%)
rhymes = get_kid_friendly_rhymes(word)
# 2. Generate lyrics (15-25%)
lyrics = gemini.create_gentle_educational_song(
topic=word,
rhymes=rhymes,
style="gentle, educational, lullaby-like"
)
# 3. Clean lyrics (30%)
lyrics = remove_pirate_exclamations(lyrics)
lyrics = remove_structure_labels(lyrics)
# 4. Generate vocals (40-60%)
vocals = elevenlabs.text_to_speech(
text=f"[singing gently and sweetly like a lullaby]\n{lyrics}",
voice="child_friendly",
settings={"style": 0.8, "stability": 0.3}
)
# 5. Select background music (65-70%)
track = random.choice(background_tracks)
duration = get_audio_duration(vocals)
background = trim_and_fade(track, duration)
# 6. Mix audio (75-90%)
final = mix(
vocals=vocals,
background=background,
vocals_volume=1.0,
background_volume=0.4
)
# 7. Generate metadata (95-100%)
bpm = detect_bpm(final)
timings = generate_karaoke_timings(vocals, lyrics)
# 8. Cache and return
cache.save(word, final, lyrics, timings, bpm)
return {
"lyrics": lyrics,
"audio_url": final.url,
"timings": timings,
"duration": duration,
"bpm": bpm
}- β Password Hashing: bcrypt with salt
- β Input Validation: Pydantic models
- β SQL Injection Prevention: NoSQL (MongoDB)
- β CORS Protection: Configured origins
- β Rate Limiting: Celery task limits
- β User Isolation: Per-user libraries
- β
Environment Variables: Sensitive data in
.env
# Install pytest
pip install pytest pytest-asyncio
# Run tests
pytest tests/# Install testing library
npm install --save-dev @testing-library/react
# Run tests
npm test| Metric | Value |
|---|---|
| Song Generation Time | 30-60 seconds |
| Cached Song Load | < 1 second |
| API Response Time | < 100ms |
| Frontend Load Time | < 2 seconds |
| Database Query Time | < 50ms |
We welcome contributions! Here's how:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- Python: Follow PEP 8, use black formatter
- TypeScript: Follow ESLint rules, use prettier
- Commits: Use conventional commits (feat:, fix:, docs:)
This project is created for EmoryHack 2024 hackathon.
For educational and demonstration purposes only.
- Google Gemini - Free, powerful AI for lyrics generation
- ElevenLabs - Professional TTS with singing capabilities
- Suno Bark - Open-source fallback TTS
- MongoDB Atlas - Free cloud database
- Redis Cloud - Free cache and task queue
- FastAPI - Modern, fast Python web framework
- React - Powerful UI library
- Tailwind CSS - Beautiful styling system
Built with β€οΈ by the 12Tree Team for EmoryHack 2024
- Issues: Open an issue on GitHub
- Questions: Check the
/Docsfolder - Demo: Live Demo Link (if deployed)
# 1. Clone
git clone <repo-url>
cd EmoryHack
# 2. Setup Backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # Add your API keys!
# 3. Setup Frontend
cd Frontend/12Tree-frontend
npm install
# 4. Start Everything
# Terminal 1: redis-server
# Terminal 2: celery -A app.tasks worker --loglevel=info
# Terminal 3: uvicorn app.main:app --reload
# Terminal 4: npm run dev
# 5. Visit http://localhost:5173That's it! Start creating educational songs! π΅
Made with π for preschool learners everywhere
β Star this repo if you found it helpful!