vtt

VTT I/O module.

Functions

seconds2timestamp

Converts floating point seconds into timestamp string.

timestamp2seconds

Converts timestamp string into floating point seconds.

Classes

VTTReader

Safe VTT subtitle reader.

VTTWriter

Safe VTT subtitle writer.

class VTTReader[source]

Bases: object

Safe VTT subtitle reader.

static check(path)[source]

Checks that a file has of the correct extension and exists.

Parameters:

path (Union[str, Path]) – Path to the file.

Returns:

static read(path, verbose=True)[source]

Reads and parses a VTT file.

Parameters:
  • path (Union[str, Path]) – Path to the file.

  • verbose (bool) – Verbosity of the method.

Return type:

Sequence[Dict[str, Union[str, float]]]

Returns:

Subtitle segments.

class VTTWriter[source]

Bases: object

Safe VTT subtitle writer.

static check(path, overwrite=False)[source]

Checks that a file has of the correct extension and verifies that we can overwrite it if it exists.

Parameters:
  • path (Union[str, Path]) – Path to the file.

  • overwrite (bool)

Returns:

static write(segments, path, overwrite=False, verbose=True)[source]

Writes transcribed audio segments into a VTT subtitle file.

Parameters:
  • segments (Sequence[Dict[str, Union[str, float]]]) – Transcribed audio segments.

  • path (Union[str, Path]) – Path to the file.

  • overwrite (bool) – Whether to overwrite, in case of an existing file.

  • verbose (bool) – Verbosity of the method.

Returns:

seconds2timestamp(seconds)[source]

Converts floating point seconds into timestamp string.

Parameters:

seconds (float) – Floating point seconds.

Return type:

str

Returns:

Timestamp string.

timestamp2seconds(timestamp)[source]

Converts timestamp string into floating point seconds.

Parameters:

timestamp (str) – Timestamp string.

Return type:

float

Returns:

Floating point seconds.