Closed yhown589 closed 8 months ago
There is a method to convert the returned timeline JSON object to subtitles. It produces a string output, which you can then write to a file. It supports both SRT and. Here's the part from the API documentation about it:
timelineToSubtitles(timeline, options)
Converts a timeline to subtitles.
timeline
: Timeline objectoptions
: Subtitles configuration objectSubtitle file content, as a string.
thank u very much much, it works. But I have an other problem:
If I want to achieve the same configuration as the command line in js code and I want such an option to be set when generating json, how should I write the js option configuration?
subtitles.maxLineCount=1 --subtitles.mode="line"
The options
object mentioned in the API documentation, can accept these options, and many more, like { maxLineCount: 1, mode: "line" }
, etc.
Here is the TypeScript definition of the options
object, directly from the source code (if you are using TypeScript in VSCode it could autocomplete these options for you while editing your code):
export type SubtitlesMode = 'line' | 'segment' | 'sentence' | 'word' | 'phone' | 'word+phone'
export interface SubtitlesConfig {
format?: 'srt' | 'webvtt'
language?: string
mode?: SubtitlesMode
maxLineCount?: number
maxLineWidth?: number
minWordsInLine?: number
separatePhrases?: boolean
maxAddedDuration?: number
decimalSeparator?: ',' | '.'
includeCueIndexes?: boolean
includeHours?: boolean
lineBreakString?: '\n' | '\r\n'
originalText?: string
totalDuration?: number
}
I looked through your source and found this:
import { defaultSubtitlesBaseConfig } from "../subtitles/Subtitles.js";
and then, found the expectation of subtitles options I want
thank u
I try align() method, it return a promise object, it only can output the json string in the terminal. I haven't found a feature that can generate srt file according to my alignmentOptions. Although I know that can manually generated srt file through fs module using json string, but this json string generated by align() is fixed, I want to generate srt file through the configuration I set in advance. does feature exist?