an.audio.voice_listing#
The voices a TTS provider offers, as rows a host can show and filter (an#712).
A host that lets a user cast a voice (reelee’s character voices) needs the same
few facts from every provider: an id, a name, a language, a gender, an accent,
a description, a sample to hear, and whether the voice is one of the provider’s
stock voices that nobody designed (is_stock) or one an account designed,
cloned, recorded or added from a shared voice library. Those facts are fields of
VoiceMeta, which each provider fills in its own
list_voices; a row is its flat view, as_row()
(VoiceRow). So a host filters on a field rather than on a provider’s
category string, and a new provider adds itself by filling VoiceMeta.
Two listings, two shapes: list_voices() (an.audio.list_voices) returns
rows, for a host; browse_voices() and a provider’s own list_voices
return VoiceMeta.
>>> rows = list_voices("offline")
>>> [(r["voice_id"], r["provider"], r["is_stock"]) for r in rows]
[('default', 'offline', True)]
Functions
|
The voices |
|
The voices |
Classes
The keys of |
- class an.audio.voice_listing.VoiceRow[source]#
Bases:
TypedDictThe keys of
VoiceMeta.as_row(), typed for hosts (a plaindictat runtime); a test pins them to the dataclass.
- an.audio.voice_listing.browse_voices(provider='elevenlabs', *, search=None, api_key=None, make=<function make_tts>)[source]#
The voices
providerexposes, optionally filtered bysearch.A provider whose
list_voicestakessearch(ElevenLabs) filters on its server; for the others the filter is a case-insensitive substring over the id, name, accent, description and labels.makeis the provider seam:make(name), ormake(name, api_key=api_key)only when a key was given (so amakethat takes no key serves every keyless call); defaultan.audio.providers.make_tts().api_key=Nonemeans the provider’s own default (ElevenLabs: the environment’s key); an empty key is refused (ValueError) rather than read as “none”.>>> class Fake: ... name = "fake" ... def list_voices(self): ... return [VoiceMeta("v1", "Ada", "fake"), ... VoiceMeta("v2", "Bob", "fake", description="adenoidal")] >>> [v.name for v in browse_voices("fake", search="ad", make=lambda _: Fake())] ['Ada', 'Bob']
- an.audio.voice_listing.list_voices(provider, *, api_key=None, search=None, make=<function make_tts>)[source]#
The voices
provideroffers, as rows (an#712):browse_voices()throughVoiceMeta.as_row().api_keyis a host’s own key for a provider that takes one (an.audio.providers.listable_providers());Nonemeans the environment’s key, and""is refused (ValueError), so a host that forwards a guest’s absent key never lists the server’s own account. A provider that cannot be asked at all (itscheck_available()fails: no key anywhere) raises its own typed error (ElevenLabs:ElevenLabsUnavailableError) rather than answering[], so an empty listing means “no voices”.searchandmakeare as inbrowse_voices(). An unknown provider is aValueErrornaming the known ones.