an.stores.transcripts#

Transcripts as linked artifacts in the project store (an#493).

A transcript an earlier step produced (a speech-to-text pass, a script export, a hand-timed SRT) is kept in the mall’s transcripts store, a lacing.ArtifactStore (catalog/<key>.json + blobs/<sha256>, the layout of the shot cache), so a later step can name it instead of a file: an voices import <dir> takes/ --transcript artifact:transcripts/<key> (an.audio.recorded.import_recordings()), and the take’s provenance points at the artifact it was cut by, content included (transcripts/<key>@<sha256>: a key re-recorded later names other bytes). The transcript’s format rides in the record’s mime (FORMAT_MIME). A transcript is a document the takes are cut BY, before any take exists and often covering several, so it is its own store rather than a sidecar of a recording.

A reference is artifact:[<store>/]<key>[@<sha256>], the store TRANSCRIPTS_STORE when it names none: lacing.ArtifactRef parses and formats it and lacing.resolve_in_mall reads what it names (an#670), so the spelling is lacing’s, shared with reelee; this module only turns their refusals into the TranscriptLinkError that says which part is missing.

>>> store = in_memory_transcripts_store()
>>> art = record_transcript(store, "take1", "1\n00:00:00,000 --> 00:00:01,000\nHello.\n")
>>> art.mime, art.kind
('application/x-subrip', 'text')
>>> linked = linked_transcript("artifact:transcripts/take1", {"transcripts": store})
>>> linked.fmt, linked.ref == f"transcripts/take1@{art.asset_id}", linked.text.splitlines()[2]
('srt', True, 'Hello.')

Module Attributes

TRANSCRIPTS_STORE

The mall key of the transcripts store.

FORMAT_MIME

The media type each transcript format is recorded under (and read back from).

Functions

in_memory_transcripts_store()

A transcripts store held in dicts: for tests, and a mall with no disk.

is_artifact_ref(item)

Whether item names a transcript artifact: an artifact: reference (lacing.ArtifactRef reads it) or a lacing.Artifact.

linked_transcript(item, mall, *[, store_name])

The transcript item names: artifact:[<store>/]<key>[@<sha256>] (lacing.ArtifactRef: the first segment names a store of mall that holds the rest, else the whole name is a key of store_name), or a lacing.Artifact (filed in store_name), read through mall.

orphan_transcript_blobs(store, *[, named])

The transcript contents of store that no catalog record and nothing in named (the pins a take's provenance records, an#607) names: what re-recording a key left behind.

pin_of(reference)

The content digest a recorded reference pins (<store>/<key>@<sha256>, read by lacing.ArtifactRef with or without its artifact: prefix); None when it pins none or is not a reference.

record_transcript(store, key, text, *[, ...])

Keep text (a transcript, or a Path to one; its format detected, a file's suffix first, unless fmt says) in store under key; return its lacing.Artifact.

transcripts_store(root, *[, ensure])

A filesystem transcripts store under root (lacing's layout).

Classes

LinkedTranscript(text, fmt, ref)

A transcript read out of the store: its text, its format, and the reference that names it with its content (<store>/<key>@<sha256>).

Exceptions

TranscriptCatalogUnreadable

A transcripts catalog record cannot be read: what it names is unknown, so nothing can be said to be named by nothing (an#607).

TranscriptLinkError

A transcript artifact that cannot be found or read.

an.stores.transcripts.FORMAT_MIME: dict[str, str] = {'json': 'application/json', 'plain': 'text/plain', 'srt': 'application/x-subrip', 'textgrid': 'text/x-praat-textgrid', 'vtt': 'text/vtt'}#

The media type each transcript format is recorded under (and read back from).

class an.stores.transcripts.LinkedTranscript(text, fmt, ref)[source]#

Bases: object

A transcript read out of the store: its text, its format, and the reference that names it with its content (<store>/<key>@<sha256>).

an.stores.transcripts.TRANSCRIPTS_STORE: str = 'transcripts'#

The mall key of the transcripts store.

exception an.stores.transcripts.TranscriptCatalogUnreadable[source]#

Bases: TranscriptLinkError

A transcripts catalog record cannot be read: what it names is unknown, so nothing can be said to be named by nothing (an#607).

exception an.stores.transcripts.TranscriptLinkError[source]#

Bases: ValueError

A transcript artifact that cannot be found or read.

an.stores.transcripts.in_memory_transcripts_store()[source]#

A transcripts store held in dicts: for tests, and a mall with no disk.

Return type:

Any

an.stores.transcripts.is_artifact_ref(item)[source]#

Whether item names a transcript artifact: an artifact: reference (lacing.ArtifactRef reads it) or a lacing.Artifact.

>>> is_artifact_ref("artifact:transcripts/t"), is_artifact_ref("take.srt")
(True, False)
>>> is_artifact_ref("artifact: Hello there.")   # a plain transcript's speaker
False
Return type:

bool

an.stores.transcripts.linked_transcript(item, mall, *, store_name='transcripts')[source]#

The transcript item names: artifact:[<store>/]<key>[@<sha256>] (lacing.ArtifactRef: the first segment names a store of mall that holds the rest, else the whole name is a key of store_name), or a lacing.Artifact (filed in store_name), read through mall. A pinned reference (what a take’s provenance records) reads exactly those bytes, even after the key was recorded again or removed. Raises TranscriptLinkError for text that is not a reference, a store the mall has not, one that is not an artifact store, a key or content it does not hold, bytes that do not match their pin, or a record whose mime is not a transcript format.

>>> mall = {"transcripts": in_memory_transcripts_store()}
>>> linked_transcript("artifact:transcripts/nope", mall)
Traceback (most recent call last):
...
an.stores.transcripts.TranscriptLinkError: 'artifact:transcripts/nope': no transcript 'nope' in the 'transcripts' store
Return type:

LinkedTranscript

an.stores.transcripts.orphan_transcript_blobs(store, *, named=())[source]#

The transcript contents of store that no catalog record and nothing in named (the pins a take’s provenance records, an#607) names: what re-recording a key left behind. Raises TranscriptCatalogUnreadable when a record cannot be read, since its blob might be the one it names.

>>> store = in_memory_transcripts_store()
>>> first = record_transcript(store, "k", "carl: Hello.")
>>> _ = record_transcript(store, "k", "carl: Hello there.")
>>> orphan_transcript_blobs(store) == [first.asset_id]
True
>>> orphan_transcript_blobs(store, named=[first.asset_id])
[]
Return type:

list[str]

an.stores.transcripts.pin_of(reference)[source]#

The content digest a recorded reference pins (<store>/<key>@<sha256>, read by lacing.ArtifactRef with or without its artifact: prefix); None when it pins none or is not a reference.

>>> pin_of("transcripts/k@" + "a" * 64) == "a" * 64, pin_of("transcripts/k")
(True, None)
>>> pin_of("transcripts/my take@" + "A" * 64) == "a" * 64  # an older an's key
True
Return type:

str | None

an.stores.transcripts.record_transcript(store, key, text, *, fmt=None, generated_by='processor:an.stores.transcripts', attributed_to='an', derived_from=())[source]#

Keep text (a transcript, or a Path to one; its format detected, a file’s suffix first, unless fmt says) in store under key; return its lacing.Artifact. generated_by and attributed_to are its provenance (processor:<name>, who ran it), derived_from the sha256 of what it was made from (a recording).

Return type:

Any

an.stores.transcripts.transcripts_store(root, *, ensure=False)[source]#

A filesystem transcripts store under root (lacing’s layout).

Its folders are made on the first write, a missing one reading as empty (an#696); ensure=True lays them out at once (an init).

Return type:

Any