A Flask-based service that processes video files to generate subtitles in multiple languages. The service uses OpenAI's Whisper API for transcription and GPT-4o for translations.
- Video to text transcription using OpenAI's Whisper API
- Translation support for multiple languages:
- French (fr)
- Spanish (es)
- German (de)
- Automatic SRT file generation for original transcription and translations
- Unique process ID for each request to track outputs
- Python 3.x
- FFmpeg installed on your system
- OpenAI API key
- Clone the repository:
git clone [your-repo-url]
cd [your-repo-name]
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On macOS/Linux
# or
.\venv\Scripts\activate # On Windows
- Install dependencies:
pip install -r requirements.txt
- Create a
.env
file in the project root with the following variables:
OPENAI_API_KEY=your_openai_api_key
UPLOAD_FOLDER=uploads
TEMP_FOLDER=temp
OUTPUT_FOLDER=outputs
- Start the Flask server:
export FLASK_APP=app.py
export FLASK_ENV=development
python -m flask run -p 5001
- Send a POST request to process a video:
curl -X POST \
-F "video=@/path/to/your/video.mp4" \
-F "target_languages=french,spanish,german" \
http://localhost:5001/api/process-video
The response will include:
process_id
: Unique identifier for the processing joboriginal_srt
: Name of the original transcription filetranslations
: Object containing the status/filename for each requested language
.
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── src/
│ ├── config.py # Configuration management
│ ├── routes.py # API routes
│ └── services/ # Core services
│ ├── audio_service.py # Audio processing and transcription
│ └── subtitle_service.py # Subtitle translation
Process a video file and generate translations.
Parameters:
video
: Video file (multipart/form-data)target_languages
: Comma-separated list of target languages (e.g., "french,spanish,german")
Response:
{
"process_id": "unique-process-id",
"original_srt": "video_name.srt",
"translations": {
"french": "video_name_french.srt",
"spanish": "video_name_spanish.srt",
"german": "video_name_german.srt"
}
}
The service includes comprehensive error handling for:
- Invalid file types
- Missing video files
- Unsupported languages
- OpenAI API errors
- FFmpeg processing errors
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- OpenAI for Whisper and GPT APIs
- FFmpeg for video processing