transl8-srt 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -0
- package/dist/index.cjs +7469 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +7440 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
|
|
3
|
+
type SubtitleFormat = "srt" | "vtt";
|
|
4
|
+
interface Cue {
|
|
5
|
+
id: number;
|
|
6
|
+
startMs: number;
|
|
7
|
+
endMs: number;
|
|
8
|
+
text: string;
|
|
9
|
+
lines: string[];
|
|
10
|
+
}
|
|
11
|
+
interface ReconstructedSentence {
|
|
12
|
+
sentenceId: number;
|
|
13
|
+
text: string;
|
|
14
|
+
cueIds: number[];
|
|
15
|
+
charRatios: number[];
|
|
16
|
+
}
|
|
17
|
+
type SupportedLanguage = "en" | "fr" | "pt" | "es" | "de" | "it" | "yo" | "ig" | "ha" | "ar" | "sw" | "zu" | "am" | (string & {});
|
|
18
|
+
interface TranslationMeta {
|
|
19
|
+
/** Speaker / pastor name — will NOT be translated, kept as-is */
|
|
20
|
+
speakerName?: string;
|
|
21
|
+
/** Church or ministry name — will NOT be translated */
|
|
22
|
+
churchName?: string;
|
|
23
|
+
/** Recurring branded phrase, e.g. "The Grace Revolution" */
|
|
24
|
+
seriesTitle?: string;
|
|
25
|
+
/** Any extra glossary entries: source term → target term */
|
|
26
|
+
glossary?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
type ContentDomain = "sermon" | "general";
|
|
29
|
+
interface TranslateOptions {
|
|
30
|
+
/** Source language BCP-47 tag. Defaults to "en" */
|
|
31
|
+
sourceLang?: SupportedLanguage;
|
|
32
|
+
/** Target language BCP-47 tag — required */
|
|
33
|
+
targetLang: SupportedLanguage;
|
|
34
|
+
/** Domain unlocks pre-baked register + vocabulary. Defaults to "sermon" */
|
|
35
|
+
domain?: ContentDomain;
|
|
36
|
+
/** Proper nouns + glossary — replaces the primer call entirely */
|
|
37
|
+
meta?: TranslationMeta;
|
|
38
|
+
/** Sentences per batch (default 25). Tune down for long sermons on tight rate limits */
|
|
39
|
+
batchSize?: number;
|
|
40
|
+
/** Context overlap: N sentences from the prev batch prepended (default 4) */
|
|
41
|
+
contextOverlap?: number;
|
|
42
|
+
/** OpenAI model override. Defaults to gpt-4o for non-Latin scripts, gpt-4o-mini otherwise */
|
|
43
|
+
model?: "gpt-4o" | "gpt-4o-mini";
|
|
44
|
+
/** Max concurrent batch requests (default 8) */
|
|
45
|
+
concurrency?: number;
|
|
46
|
+
/** Enable AI primer call — for general/unknown content only */
|
|
47
|
+
primer?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface TranslatedCue extends Cue {
|
|
50
|
+
translatedText: string;
|
|
51
|
+
translatedLines: string[];
|
|
52
|
+
}
|
|
53
|
+
interface TranslationResult {
|
|
54
|
+
sourceLang: string;
|
|
55
|
+
targetLang: string;
|
|
56
|
+
cues: TranslatedCue[];
|
|
57
|
+
/** Render back to SRT string */
|
|
58
|
+
toSRT(): string;
|
|
59
|
+
/** Render back to VTT string */
|
|
60
|
+
toVTT(): string;
|
|
61
|
+
stats: TranslationStats;
|
|
62
|
+
}
|
|
63
|
+
interface TranslationStats {
|
|
64
|
+
totalCues: number;
|
|
65
|
+
totalSentences: number;
|
|
66
|
+
totalBatches: number;
|
|
67
|
+
inputTokens: number;
|
|
68
|
+
outputTokens: number;
|
|
69
|
+
estimatedCostUsd: number;
|
|
70
|
+
durationMs: number;
|
|
71
|
+
}
|
|
72
|
+
interface BatchPayload {
|
|
73
|
+
batchIndex: number;
|
|
74
|
+
sentences: ReconstructedSentence[];
|
|
75
|
+
contextSentences: ReconstructedSentence[];
|
|
76
|
+
}
|
|
77
|
+
interface BatchResult {
|
|
78
|
+
batchIndex: number;
|
|
79
|
+
translations: Record<number, string>;
|
|
80
|
+
inputTokens: number;
|
|
81
|
+
outputTokens: number;
|
|
82
|
+
}
|
|
83
|
+
declare class SubtitleTranslationError extends Error {
|
|
84
|
+
readonly code: "PARSE_ERROR" | "EMPTY_FILE" | "API_ERROR" | "BATCH_FAILED" | "REANCHOR_ERROR";
|
|
85
|
+
readonly cause?: unknown | undefined;
|
|
86
|
+
constructor(message: string, code: "PARSE_ERROR" | "EMPTY_FILE" | "API_ERROR" | "BATCH_FAILED" | "REANCHOR_ERROR", cause?: unknown | undefined);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare function translate(
|
|
90
|
+
/** Raw SRT or VTT file content */
|
|
91
|
+
fileContent: string, opts: TranslateOptions,
|
|
92
|
+
/** Pass your own OpenAI client (allows custom baseURL, auth, etc.) */
|
|
93
|
+
client?: OpenAI): Promise<TranslationResult>;
|
|
94
|
+
declare function translateFile(inputPath: string, outputPath: string, opts: TranslateOptions, client?: OpenAI): Promise<TranslationResult>;
|
|
95
|
+
|
|
96
|
+
export { type BatchPayload, type BatchResult, type ContentDomain, type Cue, type ReconstructedSentence, type SubtitleFormat, SubtitleTranslationError, type SupportedLanguage, type TranslateOptions, type TranslatedCue, type TranslationMeta, type TranslationResult, type TranslationStats, translate, translateFile };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
|
|
3
|
+
type SubtitleFormat = "srt" | "vtt";
|
|
4
|
+
interface Cue {
|
|
5
|
+
id: number;
|
|
6
|
+
startMs: number;
|
|
7
|
+
endMs: number;
|
|
8
|
+
text: string;
|
|
9
|
+
lines: string[];
|
|
10
|
+
}
|
|
11
|
+
interface ReconstructedSentence {
|
|
12
|
+
sentenceId: number;
|
|
13
|
+
text: string;
|
|
14
|
+
cueIds: number[];
|
|
15
|
+
charRatios: number[];
|
|
16
|
+
}
|
|
17
|
+
type SupportedLanguage = "en" | "fr" | "pt" | "es" | "de" | "it" | "yo" | "ig" | "ha" | "ar" | "sw" | "zu" | "am" | (string & {});
|
|
18
|
+
interface TranslationMeta {
|
|
19
|
+
/** Speaker / pastor name — will NOT be translated, kept as-is */
|
|
20
|
+
speakerName?: string;
|
|
21
|
+
/** Church or ministry name — will NOT be translated */
|
|
22
|
+
churchName?: string;
|
|
23
|
+
/** Recurring branded phrase, e.g. "The Grace Revolution" */
|
|
24
|
+
seriesTitle?: string;
|
|
25
|
+
/** Any extra glossary entries: source term → target term */
|
|
26
|
+
glossary?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
type ContentDomain = "sermon" | "general";
|
|
29
|
+
interface TranslateOptions {
|
|
30
|
+
/** Source language BCP-47 tag. Defaults to "en" */
|
|
31
|
+
sourceLang?: SupportedLanguage;
|
|
32
|
+
/** Target language BCP-47 tag — required */
|
|
33
|
+
targetLang: SupportedLanguage;
|
|
34
|
+
/** Domain unlocks pre-baked register + vocabulary. Defaults to "sermon" */
|
|
35
|
+
domain?: ContentDomain;
|
|
36
|
+
/** Proper nouns + glossary — replaces the primer call entirely */
|
|
37
|
+
meta?: TranslationMeta;
|
|
38
|
+
/** Sentences per batch (default 25). Tune down for long sermons on tight rate limits */
|
|
39
|
+
batchSize?: number;
|
|
40
|
+
/** Context overlap: N sentences from the prev batch prepended (default 4) */
|
|
41
|
+
contextOverlap?: number;
|
|
42
|
+
/** OpenAI model override. Defaults to gpt-4o for non-Latin scripts, gpt-4o-mini otherwise */
|
|
43
|
+
model?: "gpt-4o" | "gpt-4o-mini";
|
|
44
|
+
/** Max concurrent batch requests (default 8) */
|
|
45
|
+
concurrency?: number;
|
|
46
|
+
/** Enable AI primer call — for general/unknown content only */
|
|
47
|
+
primer?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface TranslatedCue extends Cue {
|
|
50
|
+
translatedText: string;
|
|
51
|
+
translatedLines: string[];
|
|
52
|
+
}
|
|
53
|
+
interface TranslationResult {
|
|
54
|
+
sourceLang: string;
|
|
55
|
+
targetLang: string;
|
|
56
|
+
cues: TranslatedCue[];
|
|
57
|
+
/** Render back to SRT string */
|
|
58
|
+
toSRT(): string;
|
|
59
|
+
/** Render back to VTT string */
|
|
60
|
+
toVTT(): string;
|
|
61
|
+
stats: TranslationStats;
|
|
62
|
+
}
|
|
63
|
+
interface TranslationStats {
|
|
64
|
+
totalCues: number;
|
|
65
|
+
totalSentences: number;
|
|
66
|
+
totalBatches: number;
|
|
67
|
+
inputTokens: number;
|
|
68
|
+
outputTokens: number;
|
|
69
|
+
estimatedCostUsd: number;
|
|
70
|
+
durationMs: number;
|
|
71
|
+
}
|
|
72
|
+
interface BatchPayload {
|
|
73
|
+
batchIndex: number;
|
|
74
|
+
sentences: ReconstructedSentence[];
|
|
75
|
+
contextSentences: ReconstructedSentence[];
|
|
76
|
+
}
|
|
77
|
+
interface BatchResult {
|
|
78
|
+
batchIndex: number;
|
|
79
|
+
translations: Record<number, string>;
|
|
80
|
+
inputTokens: number;
|
|
81
|
+
outputTokens: number;
|
|
82
|
+
}
|
|
83
|
+
declare class SubtitleTranslationError extends Error {
|
|
84
|
+
readonly code: "PARSE_ERROR" | "EMPTY_FILE" | "API_ERROR" | "BATCH_FAILED" | "REANCHOR_ERROR";
|
|
85
|
+
readonly cause?: unknown | undefined;
|
|
86
|
+
constructor(message: string, code: "PARSE_ERROR" | "EMPTY_FILE" | "API_ERROR" | "BATCH_FAILED" | "REANCHOR_ERROR", cause?: unknown | undefined);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare function translate(
|
|
90
|
+
/** Raw SRT or VTT file content */
|
|
91
|
+
fileContent: string, opts: TranslateOptions,
|
|
92
|
+
/** Pass your own OpenAI client (allows custom baseURL, auth, etc.) */
|
|
93
|
+
client?: OpenAI): Promise<TranslationResult>;
|
|
94
|
+
declare function translateFile(inputPath: string, outputPath: string, opts: TranslateOptions, client?: OpenAI): Promise<TranslationResult>;
|
|
95
|
+
|
|
96
|
+
export { type BatchPayload, type BatchResult, type ContentDomain, type Cue, type ReconstructedSentence, type SubtitleFormat, SubtitleTranslationError, type SupportedLanguage, type TranslateOptions, type TranslatedCue, type TranslationMeta, type TranslationResult, type TranslationStats, translate, translateFile };
|