npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-sub-translator

v1.2.1

Published

AI-powered subtitle translator using Google Gemini. Translates SRT subtitles to any language.

Downloads

727

Readme

ai-sub-translator

AI-powered subtitle translator using Google Gemini. Translates SRT subtitle files to any language.

Installation

npm install ai-sub-translator

Quick Start

import { translate } from 'ai-sub-translator';
import { readFileSync } from 'fs';

const srtContent = readFileSync('movie.srt', 'utf-8');

const result = await translate({
  text: srtContent,
  targetLanguage: 'French',
  apiKey: 'your-gemini-api-key',
  context: 'Breaking Bad S01E01',
  onProgress: (p) => console.log(`${Math.round(p * 100)}%`),
});

console.log(result.translatedText);

API

translate(options): Promise<TranslateResult>

Translates SRT subtitle content to a target language using Google Gemini.

Options

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | text | string | Yes | - | SRT subtitle content | | targetLanguage | string | Yes | - | Target language (e.g., "French", "Spanish") | | apiKey | string | Yes | - | Google Gemini API key | | model | string | No | gemini-2.0-flash | Gemini model to use | | batchSize | number | No | 50 | Subtitles per translation batch | | context | string | No | '' | Movie/show name for better translation | | onProgress | (progress: number) => void | No | - | Progress callback (0-1 range) | | signal | AbortSignal | No | - | Cancellation signal |

Returns TranslateResult

{
  translatedText: string;   // Full translated SRT content
  totalBatches: number;     // Total batches processed
  completedBatches: number; // Completed batches
}

parseSrt(text): SrtEntry[]

Parses SRT content into structured entries.

import { parseSrt } from 'ai-sub-translator';

const entries = parseSrt(srtContent);
// [{ index: 1, timestamp: '00:00:01,000 --> 00:00:05,000', text: 'Hello' }, ...]

formatSrt(entries): string

Formats structured entries back into SRT content.

import { formatSrt } from 'ai-sub-translator';

const srt = formatSrt(entries);

Types

interface SrtEntry {
  index: number;
  timestamp: string;
  text: string;
}

interface TranslateOptions {
  text: string;
  targetLanguage: string;
  apiKey: string;
  model?: string;
  batchSize?: number;
  context?: string;
  onProgress?: (progress: number) => void;
  signal?: AbortSignal;
}

interface TranslateResult {
  translatedText: string;
  totalBatches: number;
  completedBatches: number;
}

Supported Models

All models have a free tier available from Google AI Studio:

  • gemini-2.0-flash (default, recommended)
  • gemini-2.5-flash
  • gemini-1.5-flash
  • gemini-1.5-flash-8b

Cancellation

const controller = new AbortController();

const result = translate({
  text: srtContent,
  targetLanguage: 'French',
  apiKey: 'key',
  signal: controller.signal,
});

// Cancel after 30 seconds
setTimeout(() => controller.abort(), 30000);

License

MIT