Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Subtitle Translator

Nest Logo

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.

Description

This project is a subtitle translation service built with NestJS that:

  • Reads .srt subtitle files from the data/input directory
  • Translates the subtitles to Bahasa Indonesia using OpenAI's API
  • Preserves the original subtitle format and timing
  • Saves translated subtitles to the data/output directory

The application runs as a worker service that automatically processes all .srt files found in the input directory when started.

Tech Stack

  • 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

Prerequisites

  • Node.js (v18 or higher recommended)
  • pnpm installed globally (npm install -g pnpm)
  • OpenAI API key (or compatible API endpoint)

Installation & Usage

1. Clone the repository

git clone https://github.com/juniardys/subtitle-translator.git

2. Install dependencies

pnpm install

3. Setup environment variables

Copy the .env.example file to .env and configure your environment variables:

cp .env.example .env

Edit the .env file and add your configuration:

LangSmith Configuration (Optional):

  • LANGSMITH_TRACING - Enable LangSmith tracing (default: true)
  • LANGSMITH_ENDPOINT - LangSmith API endpoint
  • LANGSMITH_API_KEY - Your LangSmith API key
  • LANGSMITH_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")

4. Add subtitle files

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/

5. Run the application

pnpm start

The application will:

  1. Scan the data/input directory for .srt files
  2. Process each file sequentially
  3. Translate the subtitles to Bahasa Indonesia
  4. Save the translated files to data/output directory
  5. Log the progress and completion status

Development

# development mode with hot reload
pnpm run start:dev

# production build
pnpm run build

# production mode
pnpm run start:prod

Testing

# unit tests
pnpm run test

# e2e tests
pnpm run test:e2e

# test coverage
pnpm run test:cov

Project Structure

youtube-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

License

MIT licensed

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages