an.audio.recorded#
Recorded voices: a performer’s takes as the voice of a character (an#490).
A production that records its actors has the voices already; nothing should be synthesized, billed, or approximated. This module makes a recording a first-class input, through the seams the audio pipeline already has:
The take is a voice.
RecordedTTSis aTTSProvidernamedrecordedwhose “synthesis” is a lookup in the project’srecordingsstore (RecordingsStore). A voice document that declaresprovider: recordedis spoken by it (an#305), so takes, effects, leveling, captions, the shot cache andan renderwork unchanged, and nothing is billed: the provider declaresbilled = Falseandrepeatable = True. Itssynthesis_optionshook keys each line by the digest of the take it has for it, so a re-recorded line is a new audio key, never a stale cache hit.The words travel with the clip. A take imported with a timed transcript (or transcribed) knows its word timings; they are stored with it, handed to the pipeline on
words, and a lip-sync provider that aligns from words (cutan’s) uses them instead of its own transcription — the mouth follows the performance.Import (
import_recordings(),an voices import): one or more audio files — a whole take with several lines, or one file per line — with an optional transcript (SRT, WebVTT, TextGrid, word JSON or plain text:an.audio.transcripts). Each line of the recording is cut out, matchedto the scene’s dialogue by its words (a line the scene does not have yet is added to the shot you name), and stored with its provenance: who recorded it, under which licence or permission, from which file and span. The speaker’s character is bound to the recorded voice; the gap heard between two lines becomes the next line’s
pause, so the shot’s timing follows the recording.
Seams, each one keyword argument of import_recordings():
transcribe: a callablepath -> segmentsfor a take that comes with no timed transcript; the default is scribed’s facade (pip install "an[recorded]", then a backend of your choice — words and, where the backend has it, speakers). Not needed for one file per line or a timed transcript: those paths run with no model at all.denoise: off; a strategy name runs the matching ffmpeg filter (DENOISE_FILTERS) before anything else;voxy.refprep.conditionis the fuller conditioning when you want more.Speaker attribution:
speaker(one performer),speakers(a label → character map, for a diarizer’s or a transcript’s labels and file stems), the transcript’s ownspeaker:prefixes, the file’s stem, or the scene line the words match.
>>> from an.audio.tts import AudioClip
>>> tts = RecordedTTS()
>>> tts.name, tts.billed, tts.repeatable
('recorded', False, True)
>>> normalize_key_text("Hello, there!") == normalize_key_text("hello there")
True
Module Attributes
what a voice document's |
|
The mall store the takes live in ( |
|
The |
|
The shape of a record in the store; raised when a field changes meaning. |
|
The voice document a speaker's takes are bound to, when |
|
How alike ( |
|
|
|
The strategy a bare request for denoising means. |
Functions
|
Import a performer's recording(s) as the voice of their lines (an#490). |
|
Put a take (WAV |
|
The newest take of |
|
The take whose audio has |
|
|
|
A readable, unique store key: |
|
The form a line's text is matched by: |
|
The audio files |
|
The default transcriber: scribed's facade with word timestamps (and speaker labels when |
|
|
|
The frames of |
|
The length of a PCM WAV, seconds. |
Classes
|
The |
|
One take the import stored, and where it went. |
|
What |
Exceptions
An import, or a lookup of a take, that cannot proceed; the message says what to do. |
|
An import that went ahead in a weaker form than asked; the message says what was lost and what to do (an#716). |
|
A line spoken by a recorded voice has no take in the store. |
|
A take needs transcribing and no transcriber can run here. |
- an.audio.recorded.DENOISE_FILTERS: dict[str, str] = {'afftdn': 'afftdn', 'anlmdn': 'anlmdn'}#
denoisestrategies → the ffmpeg filter that runs (voxy.refprep’s table).
- an.audio.recorded.DFLT_MATCH_THRESHOLD: float = 0.75#
How alike (
difflibratio over normalized words) a take’s words and a scene line must be for the take to be that line’s.
- class an.audio.recorded.ImportReport(takes=list(), voices=list(), warnings=list())[source]#
Bases:
objectWhat
import_recordings()did;str()is the CLI’s output.
- class an.audio.recorded.ImportedTake(key, speaker, voice, text, duration, source_file, span, words, line, added=False, pause=None)[source]#
Bases:
objectOne take the import stored, and where it went.
- an.audio.recorded.PROVIDER_NAME: str = 'recorded'#
what a voice document’s
providersays.- Type:
The TTS provider’s name
- an.audio.recorded.RECORDED_VOICE_SUFFIX: str = '_recorded'#
The voice document a speaker’s takes are bound to, when
voicenames none.
- an.audio.recorded.RECORDINGS_STORE: str = 'recordings'#
The mall store the takes live in (
assets/recordings/<key>/).
- an.audio.recorded.RECORDING_OPTION: str = 'recording'#
The
synthesizekeyword (and audio-key option) naming the take by digest.
- an.audio.recorded.RECORD_VERSION: int = 1#
The shape of a record in the store; raised when a field changes meaning.
- class an.audio.recorded.RecordedTTS(*, recordings=None)[source]#
Bases:
objectThe
recordedTTS provider: a line’s audio is the take imported for it.Built by
an.audio.providers.make_tts()with the project mall, so it readsmall["recordings"]; the pipeline hands it each line’s text and voice throughsynthesis_options()(which keys the line by its take’s digest) andsynthesize(). A line with no take raisesRecordingMissingErrorbefore anything else is touched — a recorded voice never falls back to a synthesized one.>>> RecordedTTS().check_available() Traceback (most recent call last): ... an.audio.recorded.RecordedVoicesError: the recorded provider has no recordings store ...
- synthesis_options(voice_doc, *, emotion=None, direction=None, text=None, voice_id=None)[source]#
{"recording": <digest>}of the take this line has — the audio key follows the take, so a re-recorded line is new audio. A take with phones adds{"timings": <digest>}of its words, phones (an#491) and their alphabet when stored (an#759): the same audio imported again with new timings is new audio to the caches, so the lip-sync sees them. (Only then: a take without phones keys as before.)A line with no take is refused HERE, when the pipeline resolves every line’s request before the first synthesis: nothing of the scene is produced for a recorded voice that is missing a take. Without a line (
an validateasks about the voice alone) there is nothing to refuse.
- synthesize(text, voice_id='default', *, recording=None, **kw)[source]#
The take of
textinvoice_id(byrecordingdigest when given), with its words.- Return type:
- exception an.audio.recorded.RecordedVoicesError[source]#
Bases:
RuntimeErrorAn import, or a lookup of a take, that cannot proceed; the message says what to do.
- exception an.audio.recorded.RecordedVoicesWarning[source]#
Bases:
UserWarningAn import that went ahead in a weaker form than asked; the message says what was lost and what to do (an#716).
- exception an.audio.recorded.RecordingMissingError[source]#
Bases:
RecordedVoicesErrorA line spoken by a recorded voice has no take in the store.
Bases:
RecordedVoicesErrorA take needs transcribing and no transcriber can run here.
- an.audio.recorded.add_recording(store, *, voice, speaker, text, audio, source, words=None, imported_at=None, phones=None, phone_alphabet=None)[source]#
Put a take (WAV
audioofspeakersayingtext, spoken forvoice) instorewith its provenance;(key, record).sourceis required: a recording with no recorded origin is exactly the assetan creditscannot vouch for.
- an.audio.recorded.audio_paths(audio)[source]#
The audio files
audionames: a file, a directory (its audio files, sorted), a glob, a comma-separated list, or a sequence of those.>>> audio_paths([]) []
- an.audio.recorded.cut_wav(wav, start, end)[source]#
The frames of
wavbetweenstartandendseconds, as a WAV of the same format.>>> import struct >>> buf = io.BytesIO() >>> with wave.open(buf, "wb") as w: ... w.setnchannels(1); w.setsampwidth(2); w.setframerate(100) ... w.writeframes(struct.pack("<100h", *range(100))) >>> round(wav_seconds(cut_wav(buf.getvalue(), 0.25, 0.5)), 2) 0.25
- Return type:
- an.audio.recorded.find_recording(store, voice, text)[source]#
The newest take of
textforvoiceinstore, as(key, record);Noneif none.Texts are compared normalized (case and punctuation aside), so a comma added in
scene.mddoes not orphan the take.
- an.audio.recorded.import_recordings(project, audio, *, transcript=None, speaker=None, speakers=None, shot=None, voice=None, denoise=None, license=None, recorded_by=None, transcribe=None, transcriber=None, diarize=False, align=None, rough_timing=True, overlap_tolerance_s=0.05, match_threshold=0.75, write=True, scene_file='scene.md')[source]#
Import a performer’s recording(s) as the voice of their lines (an#490).
audionames the takes (a file, several, a directory, a glob): a whole take holding several lines, or one file per line.transcriptis optional: SRT, WebVTT, TextGrid or word JSON time the lines so nothing is transcribed; a plain transcript (speaker: textlines) pairs one line per file, or is timed againsttranscribe’s words for a whole take; with no transcript at all the take is transcribed and its segments are the lines.Each line is cut out, matched to the scene’s dialogue by its words (
match_threshold), stored inmall["recordings"]with its provenance (licenseis required: the code you vouch for;recorded_bynames the performer), and the speaker’s character is bound to a recorded voice document (voice, default<speaker>_recorded). Takes matching no line are added toshot(or the first shot of a scene with no dialogue). The gap heard between two lines of one file becomes the later line’spause.denoise("afftdn"/"anlmdn") cleans each file first, through ffmpeg.transcribeis the transcriber seam (path -> segments); its default isscribed_transcriber()withtranscriberas the backend anddiarizefor speaker labels, built only when a take needs it.alignis the forced-aligner seam ((path, text) -> segments, e.g.mfa_aligner(), an#637): with a plain transcript it times the lines instead of a transcriber, and gives their phones, as a TextGrid would. Several lines in one take are first timed roughly by the transcriber (transcribe, elsetranscriber: a billed backend named there is billed for this pass too), and each is aligned within its own interval (an#716);rough_timing=Falsenever transcribes and aligns the whole text as one utterance, which drifts on a long take. With no transcriber to run, the import falls back to that one utterance, with aRecordedVoicesWarning. Two lines of a take overlapping by more thanoverlap_tolerance_sseconds are refused, naming both (an#739): two voices at once cannot be cut apart.write=Falseruns everything but writes nothing (a dry run).scene_fileimports into another scene of the project (scene.studio.md, an#554).- Return type:
- an.audio.recorded.load_wav(path, *, denoise=None)[source]#
pathas 16-bit PCM WAV bytes: a PCM WAV is taken as it is; anything else (MP3, M4A, a video’s audio) is decoded with ffmpeg to mono atIMPORT_SAMPLE_RATE;denoise(a key ofDENOISE_FILTERS) runs that filter first, which also goes through ffmpeg.- Return type:
- an.audio.recorded.normalize_key_text(text)[source]#
The form a line’s text is matched by:
normalize_text().- Return type:
- an.audio.recorded.read_recording(store, key)[source]#
(record, wav_bytes)forkey, the bytes checked against the record’s digest.The licence is attached to the digest: different bytes under the key are a take nobody vouched for, and are refused.
- an.audio.recorded.recording_by_digest(store, sha256, *, text=None)[source]#
The take whose audio has
sha256, as(key, record);Noneif none.The same bytes may be stored under two records (a take re-imported with its text corrected):
textpicks the record whose text it is, so the line gets its own words.
- an.audio.recorded.recording_key(speaker, text, sha256)[source]#
A readable, unique store key:
<speaker>--<words>--<digest prefix>.>>> recording_key("carl", "Hello, there!", "1a2b3c4d5e6f") 'carl--hello-there--1a2b3c4d'
- Return type: