A NestJS-based application that automatically translates YouTube subtitle files (.srt) to Bahasa Indonesia using OpenAI's API. The application processes subtitle files from an input directory and saves the translated versions to an output directory.
This project is a subtitle translation service built with NestJS that:
- Reads
.srtsubtitle files from thedata/inputdirectory - Translates the subtitles to Bahasa Indonesia using OpenAI's API
- Preserves the original subtitle format and timing
- Saves translated subtitles to the
data/outputdirectory
The application runs as a worker service that automatically processes all .srt files found in the input directory when started.
- NestJS - Progressive Node.js framework for building efficient server-side applications
- TypeScript - Typed superset of JavaScript
- OpenAI SDK - Official OpenAI API client for Node.js
- LangChain - Framework for developing applications powered by language models
- Node.js - JavaScript runtime environment
- pnpm - Fast, disk space efficient package manager
- Node.js (v18 or higher recommended)
- pnpm installed globally (
npm install -g pnpm) - OpenAI API key (or compatible API endpoint)
git clone https://github.com/juniardys/subtitle-translator.gitpnpm installCopy the .env.example file to .env and configure your environment variables:
cp .env.example .envEdit the .env file and add your configuration:
LangSmith Configuration (Optional):
LANGSMITH_TRACING- Enable LangSmith tracing (default:true)LANGSMITH_ENDPOINT- LangSmith API endpointLANGSMITH_API_KEY- Your LangSmith API keyLANGSMITH_PROJECT- LangSmith project name
OpenAI Configuration:
OPENAI_API_KEY- Your OpenAI API key (required)OPENAI_BASE_URL- Custom OpenAI API base URL (default:https://openrouter.ai/api/v1)OPENAI_MODEL- Model to use (default:openai/gpt-5-mini)
Translation Configuration:
TARGET_LANGUAGE- Target language for translation (default:"Bahasa Indonesia")
Place your .srt subtitle files in the data/input directory:
# Create the input directory if it doesn't exist
mkdir -p data/input
# Copy your .srt files to the input directory
cp /path/to/your/subtitle.srt data/input/pnpm startThe application will:
- Scan the
data/inputdirectory for.srtfiles - Process each file sequentially
- Translate the subtitles to Bahasa Indonesia
- Save the translated files to
data/outputdirectory - Log the progress and completion status
# development mode with hot reload
pnpm run start:dev
# production build
pnpm run build
# production mode
pnpm run start:prod# unit tests
pnpm run test
# e2e tests
pnpm run test:e2e
# test coverage
pnpm run test:covyoutube-subtitle-translator/
├── data/
│ ├── input/ # Place your .srt files here
│ └── output/ # Translated files will be saved here
├── src/
│ ├── worker/ # Worker module for subtitle translation
│ ├── app.module.ts # Main application module
│ └── main.ts # Application entry point
└── package.json