--- title: YouTube Translator & Speaker emoji: 🎤 colorFrom: indigo colorTo: blue sdk: docker app_port: 7860 pinned: false --- # YouTube Translator & Speaker (Hugging Face — Docker Space) A fully automated YouTube translation and speech tool that: ✅ Extracts transcripts using YouTube captions ✅ Uses OpenAI Whisper if captions are missing (requires `OPENAI_API_KEY`) ✅ Translates into a selected language using OpenAI GPT ✅ Can optionally generate speech using `edge-tts` (no key required) --- ## 🚀 Deploy on Hugging Face (Docker) 1) Create a new Space → **Docker** 2) Upload these files: `Dockerfile`, `app.py`, `requirements.txt`, `README.md` 3) Go to **Settings → Repository secrets → Add new secret** - Name: `OPENAI_API_KEY` - Value: `sk-xxxxxxxxxxxxxxxxxxxxx` 4) Click **Restart/Build Space** --- ## ▶️ Use the App 1. Paste a **YouTube URL** or **11-char Video ID** 2. Select target language (`en`, `es`, `hi`, `ha`, etc.) 3. (Optional) Keep **Generate Speech** enabled 4. Click **Submit** → read translated text / play MP3 --- ## ⚠️ Common Issues | Issue | Cause | Solution | |------|------|---------| | Invalid video | Bad URL/ID | Use full URL or exact 11-char ID | | No captions & no key | Video lacks subtitles | Add `OPENAI_API_KEY` for Whisper fallback | | Translation failed | Key missing/expired | Re-add correct key in Secrets | | TTS failed | Network hiccup | Retry or uncheck speech | --- ## 💻 Local Run (optional) ```bash python -m venv .venv && source .venv/bin/activate pip install -r requirements.txt export OPENAI_API_KEY=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 python app.py