foley.sources.elevenlabs.adapter#
ElevenLabs Sound Effects generate adapter — hosted Text-to-SFX v2 over HTTP.
Turns a natural-language prompt into a GeneratedClip
via the ElevenLabs POST /v1/sound-generation endpoint (report 02 §ElevenLabs).
The response is raw audio bytes (default MP3 44.1 kHz), stored by-value (the
generation flywheel) once the foley.sources.generate.generate() façade routes
it through ingest_one().
Two ElevenLabs-specific quirks the adapter handles:
``output_format`` is a URL query parameter, not a JSON body field; everything else (
text/model_id/prompt_influence/loop/duration_seconds) is the JSON body.No seed / negative-prompt / step control — generation is non-deterministic, so
generation_seedstaysNoneand those unified affordances warn-and-drop.
HTTP is dependency-injected (a Transport), so the
adapter is fully testable with no network and import foley stays dol-only; the
real requests lives only behind
requests_transport() (the foley[elevenlabs] extra).
The adapter performs NO storage/library access — it builds the audio + a generated
LicenseRecord and returns; the façade converges it on the
shared ingest pipeline.
Module Attributes
Registry convention (arioso): the loader imports |
Classes
Registry convention (arioso): the loader imports |
|
|
ElevenLabs Sound Effects generate adapter (a |
- foley.sources.elevenlabs.adapter.Adapter#
Registry convention (arioso): the loader imports
adapter.Adapter.
- class foley.sources.elevenlabs.adapter.ElevenLabsAdapter(config=None, *, api_key=None, http=None, plan=None)[source]#
Bases:
objectElevenLabs Sound Effects generate adapter (a
GenerateAdapter).- Parameters:
config (
Optional[dict]) – TheSOURCE_CONFIG(defaults to the module’s). Passed positionally by the registry’s lazy loader (the ariosoAdapter(config)convention).api_key (
Optional[str]) – The ElevenLabs token. Defaults to$ELEVENLABS_API_KEY.http (
Optional[Transport]) – The injectedTransport(defaults torequests_transport()); tests pass a fake.plan (
Optional[str]) – The ElevenLabs account plan ('elevenlabs-paid-plan'|'elevenlabs-free-plan'), which decides the generated sound’s licence. Defaults to$FOLEY_ELEVENLABS_PLAN; with neither,generaterefuses before calling the API (#56). When the key in use is a per-request one (bound, not passed asapi_key=), the plan is the one bound with it (using_source_accounts()), never this or the env’s (#98).
- account_id()[source]#
The account a call is made on, for the generations cache (
'operator'or a fingerprint).- Return type:
- property api_key: str#
The ElevenLabs token (constructor, else a bound key, else
$ELEVENLABS_API_KEY).
- generate(prompt, *, duration_s=None, model=None, prompt_influence=None, negative_prompt=None, steps=None, seed=None, loop=False, output_format='wav', sample_rate=None, provider_params=None, **kw)[source]#
Generate a sound effect for
prompt; return its bytes + provisional candidate.- Parameters:
prompt (
str) – The natural-language sound description (required).duration_s (
Optional[float]) – Seconds (clamped to the native0.5..30range).Nonelets the model auto-determine the length from the prompt.model (
Optional[str]) – The nativemodel_idto pin (eleven_text_to_sound_v2|eleven_text_to_sound_v3);Noneusesnative_defaults’. Recorded as the licence’sgenerator_model/generator_version.prompt_influence (
Optional[float]) –0..1(identity map to the native field; higher = closer to the prompt, less variety).None(default) omits it, so the API applies its own default.seed (
Optional[int]) – No ElevenLabs SFX equivalent — a non-default value warns-and-drops (recorded in the clip notes);generation_seedstaysNone.loop (
bool) – Produce a seamless-loopable clip (nativeloop; v2 default).output_format (
str) – Coarse foley token (wav|opus|mp3) translated to the native enum;wavis the losslesspcm_48000wrapped in a WAV header here, falling back to MP3 (with a note) if the account’s plan refuses PCM. Ingest re-archives to FLAC.sample_rate (
Optional[int]) – The rate (Hz) to ask for; it picks the native enum foroutput_format(wavat 22050 ispcm_22050). A rate the format lacks keeps its default rate, with a note.provider_params (
Optional[dict]) – Native request fields merged over the translated ones (#61): JSON body fields, exceptoutput_format, which replaces the native format sent as the URL query param. Recorded ingeneration_params.**kw – Extra/unknown affordances (warn-and-dropped).
- Return type:
- Returns:
A
GeneratedClip(origin=generated,license_id= the account plan,is_ai_generated=True), itsrawthe response’s status code and headers.- Raises:
RuntimeError – If the plan is unknown (before any API call).
- invoke_native(*, params, body)[source]#
POST native
params(URL query) andbody(JSON) to the SFX endpoint.The public entry below foley’s translation (#61): returns the transport’s response as is (
.contentholds the audio bytes,.headersthe metadata). No plan/licence check and no dispatch-layer gate (cost authorization, egress, the generations cache) runs here: a caller of this method owns them, and pays for the call.- Raises:
RuntimeError – On a non-200 (an
unbillederror carryingstatus_codeand the best-effortdetail).