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
The mall key of the transcripts store. |
|
The media type each transcript format is recorded under (and read back from). |
Functions
A transcripts store held in dicts: for tests, and a mall with no disk. |
|
|
Whether |
|
The transcript |
|
The transcript contents of |
|
The content digest a recorded reference pins ( |
|
Keep |
|
A filesystem transcripts store under |
Classes
|
A transcript read out of the store: its text, its format, and the reference that names it with its content ( |
Exceptions
A transcripts catalog record cannot be read: what it names is unknown, so nothing can be said to be named by nothing (an#607). |
|
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:
objectA 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:
TranscriptLinkErrorA 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:
ValueErrorA 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:
- an.stores.transcripts.is_artifact_ref(item)[source]#
Whether
itemnames a transcript artifact: anartifact:reference (lacing.ArtifactRefreads it) or alacing.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:
- an.stores.transcripts.linked_transcript(item, mall, *, store_name='transcripts')[source]#
The transcript
itemnames:artifact:[<store>/]<key>[@<sha256>](lacing.ArtifactRef: the first segment names a store ofmallthat holds the rest, else the whole name is a key ofstore_name), or alacing.Artifact(filed instore_name), read throughmall. A pinned reference (what a take’s provenance records) reads exactly those bytes, even after the key was recorded again or removed. RaisesTranscriptLinkErrorfor 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 whosemimeis 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:
- an.stores.transcripts.orphan_transcript_blobs(store, *, named=())[source]#
The transcript contents of
storethat no catalog record and nothing innamed(the pins a take’s provenance records, an#607) names: what re-recording a key left behind. RaisesTranscriptCatalogUnreadablewhen 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]) []
- an.stores.transcripts.pin_of(reference)[source]#
The content digest a recorded reference pins (
<store>/<key>@<sha256>, read bylacing.ArtifactRefwith or without itsartifact:prefix);Nonewhen 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
- 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 aPathto one; its format detected, a file’s suffix first, unlessfmtsays) instoreunderkey; return itslacing.Artifact.generated_byandattributed_toare its provenance (processor:<name>, who ran it),derived_fromthe sha256 of what it was made from (a recording).- Return type: