transcript_helpers.ts

Pure helpers for transcripts: finding and reading sidecars, formatting times, and turning one into text to edit.

view source

Declarations
#

11 declarations

find_transcripts
#

transcript_helpers.ts view source

<T extends TranscriptCandidate>(files: Iterable<T>, source_path: string): FoundTranscript<T>[] import {find_transcripts} from '@fuzdev/zzz/transcript_helpers.js';

Finds the transcript sidecars of the audio file at source_path among files: the files beside it named <source name>.<model>.transcript.json whose content says they were made from it. Sorted by model name.

files

the files to look through

type Iterable<T, any, any>

source_path

the audio file's absolute path

type string

returns

FoundTranscript<T>[]

generics

find_transcripts<T extends TranscriptCandidate>
T

format_transcript_time
#

transcript_helpers.ts view source

(ms: number): string import {format_transcript_time} from '@fuzdev/zzz/transcript_helpers.js';

Formats a position in a recording as m:ss, or h:mm:ss from an hour up.

ms

the position in milliseconds

type number

returns

string

FoundTranscript
#

is_transcript_path
#

transcript_helpers.ts view source

(path: string): boolean import {is_transcript_path} from '@fuzdev/zzz/transcript_helpers.js';

Whether path is named like a transcript sidecar.

path

type string

returns

boolean

parse_transcript
#

transcript_helpers.ts view source

(content: string | null): { [x: string]: unknown; version: number; source: { [x: string]: unknown; name: string; blake3: string; size: number; duration_ms: number; }; tool: { [x: string]: unknown; backend: string; version: string | null; model: string; model_blake3: string; params: { ...; }; }; language: string | null; segments: { ...; }[]; } | null import {parse_transcript} from '@fuzdev/zzz/transcript_helpers.js';

Parses a transcript sidecar's content.

content

the file's text, or null when it isn't loaded

type string | null

returns

Transcript | null

the transcript, or null when the content isn't one

to_transcript_copy_path
#

transcript_helpers.ts view source

(source_path: string, is_taken: (path: string) => boolean): string import {to_transcript_copy_path} from '@fuzdev/zzz/transcript_helpers.js';

The path an editable copy of a sidecar's text is created at: the source's path plus .md, or .2.md, .3.md, … when that's taken.

source_path

the audio file's absolute path

type string

is_taken

whether a path is already a file

type (path: string) => boolean

returns

string

to_transcript_source_path
#

transcript_helpers.ts view source

(sidecar_path: string, transcript: { [x: string]: unknown; version: number; source: { [x: string]: unknown; name: string; blake3: string; size: number; duration_ms: number; }; tool: { [x: string]: unknown; backend: string; version: string | null; model: string; model_blake3: string; params: { ...; }; }; language: string | null; segments: { ...; }[]; }): string import {to_transcript_source_path} from '@fuzdev/zzz/transcript_helpers.js';

The path of the audio a sidecar was made from: the file its source.name names, beside it. The sidecar's own name can't say — a model's name has dots in it too. source.name is always a single path component (the Transcript schema refuses anything else), so this never leaves the sidecar's directory.

sidecar_path

the sidecar's absolute path

type string

transcript

the sidecar, parsed

returns

string

TRANSCRIPT_PARAGRAPH_PAUSE_MS
#

transcript_to_paragraphs
#

transcript_helpers.ts view source

(segments: readonly { start_ms: number | null; end_ms: number | null; text: string; words?: { start_ms: number; end_ms: number; text: string; p: number; }[] | undefined; }[], pause_ms?: number): string[] import {transcript_to_paragraphs} from '@fuzdev/zzz/transcript_helpers.js';

Joins a transcript's segments into paragraphs of plain text, starting a new one at each pause of pause_ms or more. Untimed segments never break.

segments

the transcript's segments, in order

type readonly TranscriptSegment[]

pause_ms

the shortest silence that starts a new paragraph

type number
default TRANSCRIPT_PARAGRAPH_PAUSE_MS

returns

string[]

transcript_to_text
#

transcript_helpers.ts view source

(transcript: { [x: string]: unknown; version: number; source: { [x: string]: unknown; name: string; blake3: string; size: number; duration_ms: number; }; tool: { [x: string]: unknown; backend: string; version: string | null; model: string; model_blake3: string; params: { ...; }; }; language: string | null; segments: { ...; }[]; }): string import {transcript_to_text} from '@fuzdev/zzz/transcript_helpers.js';

Makes the text of an editable copy of a transcript: a link to the audio beside it, then the speech as paragraphs split at pauses. The transcript itself is tool output and is never edited — this is what gets edited.

transcript

the transcript to copy

returns

string

TranscriptCandidate
#

transcript_helpers.ts view source

TranscriptCandidate import type {TranscriptCandidate} from '@fuzdev/zzz/transcript_helpers.js';

A file that might be a transcript sidecar: its path and loaded text.

path

type string

readonly

content

type string | null

readonly

Depends on
#

Imported by
#