an.audio.tts#

TTS provider protocol + supporting dataclasses.

Classes

AudioClip([path, bytes_, duration, ...])

A rendered audio clip, on disk or in memory.

TTSProvider(*args, **kwargs)

Text-to-speech provider.

VoiceMeta(voice_id, name, provider[, ...])

Metadata for a TTS voice as exposed by a provider.

class an.audio.tts.AudioClip(path=None, bytes_=None, duration=0.0, sample_rate=44100, channels=1, voice_id=None, transcript=None, words=None, phones=None, phone_alphabet=None)[source]#

Bases: object

A rendered audio clip, on disk or in memory.

phone_alphabet: str | None#

The alphabet phones are in ("arpabet", "ipa"), as the take’s record states it (an#637, an#721); None when unknown, and a lip-sync provider then guesses from the labels (an#726).

phones: list[tuple[str, float, float]] | None#

The clip’s phone timings, (phone, start_s, end_s) from the clip’s start, when an aligner gave them (a TextGrid’s phones tier on a recorded take, an#491); None otherwise. A lip-sync provider that maps phones to mouth shapes can use them instead of spreading letters.

words: list[tuple[str, float, float]] | None#

The clip’s word timings — (word, start_s, end_s) from the clip’s start — when the provider knows them (a recorded take imported with a timed transcript: an.audio.recorded); None otherwise. A lip-sync provider that aligns from words prefers these to its own transcription, and the audio pipeline stamps them on the line.

class an.audio.tts.TTSProvider(*args, **kwargs)[source]#

Bases: Protocol

Text-to-speech provider.

list_voices()[source]#

Return all voices the provider exposes.

Return type:

Iterable[VoiceMeta]

synthesize(text, voice_id, **kw)[source]#

Render text in voice_id’s voice. Returns an AudioClip.

Return type:

AudioClip

class an.audio.tts.VoiceMeta(voice_id, name, provider, language='en', gender=None, extra=dict(), is_stock=None, accent=None, description=None, preview_url=None)[source]#

Bases: object

Metadata for a TTS voice as exposed by a provider.

The fields are the provider-neutral facts a host shows and filters on (an#712): is_stock is the provider’s own answer to “nobody designed this” — one of its stock voices (ElevenLabs’ premade voices, a system voice) rather than one an account designed, cloned, recorded or added from a shared voice library; accent, description and preview_url (a sample to hear before casting, an#666) are None where the provider has none, and is_stock is None where it does not say.

extra is the provider’s own detail, in its own words. Keys hosts read (a contract): ElevenLabs’s category and labels. Its description and preview_url keys repeat the fields for one more cycle (hosts read extra["preview_url"] since an#666): read the fields.

as_row() is the flat, JSON-ready view a host lists (an.audio.list_voices()).

>>> VoiceMeta("v1", "Rachel", "elevenlabs", is_stock=True, accent="american",
...     extra={"category": "premade", "labels": {"age": "young"}}).as_row()
...
{'voice_id': 'v1', 'name': 'Rachel', 'provider': 'elevenlabs',
 'language': 'en', 'gender': None, 'is_stock': True, 'accent': 'american',
 'description': None, 'preview_url': None, 'category': 'premade'}
as_row()[source]#

The voice as one flat, JSON-ready row: every field but extra, plus the provider’s own category word (kept for display; filter on is_stock).

Return type:

dict[str, Any]