foley.sources.fal.adapter#
The fal generate adapter — one class for every fal-hosted SFX endpoint, run through falaw.
Each fal source (fal_stable_audio_3, fal_elevenlabs, fal_sonilo,
fal_mmaudio, the video-to-audio and the edit endpoints; see
foley.sources.fal.config) gets its own instance of FalAdapter, built
from its own config. A media input (a video to sound, an edit’s source audio)
is sent as a URL (a local path or bytes uploaded) and recorded by its content key. The
adapter:
builds the native request from the already-translated affordances with the same
foley.sources._dispatch.native_request()that keys the generations cache, sothe request sent and the request cached cannot drift, then adds the prompt, the endpoint’s default duration when none was asked for, and its
fixed_arguments;calls the endpoint through the injected
runner(defaultfalaw_runner():falaw.cached_call_fal+falaw.materialize_asset, under the key foley resolved). The runner always asks falaw to skip its cache read: replaying a paid request is foley’s generations cache’s job (reuse_cached=), and a second replay layer underneath would turnreuse_cached=Falseinto a silent replay;returns a
GeneratedClipwhose licence comes from the config’s licence row (fail-closed), with the native request, the seed the endpoint reports having used, and the fal endpoint id recorded as provenance.
No storage access here (the façade ingests). The runner seam is how tests stay
offline: they pass a fake that returns canned bytes, and a call the fake does not know
is an error, never a fall-through to the network.
Module Attributes
The credential name falaw binds a fal key under ( |
|
The env vars falaw reads a fal key from, in order. |
|
|
|
Registry convention (arioso): the loader imports |
Functions
|
The URL of the audio in a fal response: |
|
Every audio URL in a fal response, in order: one per sample for an endpoint that answers a list (Mirelo's |
|
Call a fal endpoint through falaw and return |
|
A fal-fetchable URL for the local file at |
|
The vendor's watermark as this response reports it (#77), or |
Classes
Registry convention (arioso): the loader imports |
|
|
A fal-hosted generate adapter (a |
|
A runner's |
- foley.sources.fal.adapter.Adapter#
Registry convention (arioso): the loader imports
adapter.Adapter.
- foley.sources.fal.adapter.FAL_CREDENTIAL = 'fal'#
The credential name falaw binds a fal key under (
falaw.using_fal_credentials).
- foley.sources.fal.adapter.FAL_KEY_ENV_VARS = ('FAL_KEY', 'FAL_API_KEY')#
The env vars falaw reads a fal key from, in order.
- class foley.sources.fal.adapter.FalAdapter(config, *, api_key=None, runner=None, uploader=None, demux=None, http=None)[source]#
Bases:
objectA fal-hosted generate adapter (a
GenerateAdapter).- Parameters:
config (
dict) – This source’s config (one ofSOURCE_CONFIGS), passed positionally by the registry’s lazy loader.api_key (
Optional[str]) – The fal key. Defaults to a key bound for this source (foley.using_source_accounts(<source>=key)), else one bound for fal itself (falaw.using_fal_credentials(key), orfal=inocracy.kit.using_credentials: one binding covers every fal source), else$FAL_KEY, else$FAL_API_KEY.runner (
Optional[Callable[...,tuple[bytes,dict] |FalAnswer]]) – The transport seam (defaultfalaw_runner()); tests pass a fake.uploader (
Optional[Callable[...,str]]) –(path, *, api_key) -> url, how a localvideo=oraudio=(a path or bytes) reaches fal (defaultfalaw_uploader()); tests pass a fake.demux (
Optional[Callable[[bytes],bytes]]) –(container bytes) -> audio bytes, for an endpoint that answers with a video (output.container == 'video'; defaultfoley.sources.video.audio_track(), which needs ffmpeg).http – Accepted and ignored: the registry passes a resilient HTTP transport to external sources, but this adapter’s transport is falaw (which retries and classifies errors itself).
- account_id()[source]#
The account a call is made on, for the generations cache (
'operator'or a fingerprint).- Return type:
- demuxer()[source]#
How to take the audio out of this endpoint’s answer, or
None(audio already).- Raises:
SourceConfigurationError – If the endpoint answers with a video and no ffmpeg can open it (before any call, so nothing is paid for).
- Return type:
- generate(prompt, *, provider_params=None, **affordances)[source]#
Generate a sound for
prompton this source’s fal endpoint.affordancesare the canonical ones the dispatch layer kept (translated, clamped, noted); seefoley.sources._dispatch.plan_generation().provider_params(#61) are native endpoint arguments merged over the translated ones and recorded ingeneration_params. The clip’srawis the endpoint’s response (its audio is a URL, not the bytes).- Raises:
SourceConfigurationError – If no fal key is available (before any call).
- Return type:
- generate_takes(prompt, n, *, provider_params=None, **affordances)[source]#
ntakes ofpromptfrom one call, through the endpoint’s batch knob (native_defaults['batch']: Mirelo’snum_samples, #210).As
generate(), but the request asks fornsamples, and each answered sample is its own clip: its own seed when the endpoint reports one per sample (seed_fielda list), else none and a note; each carries its share of the call’s actual cost. Theseedsent is the first sample’s.- Raises:
ValueError – If
nexceeds the endpoint’s batch maximum (before any call).SourceConfigurationError – If no fal key is available (before any call).
- Return type:
- invoke_native(arguments)[source]#
Call this source’s fal endpoint with native
arguments; return(media, response).mediais the bytes at the response’soutput.audio_field: the audio, or for an endpoint that answers with a video (output.container), the video.The public entry below foley’s translation (#61):
argumentsare sent as is (no fixed arguments or default duration are added). No licence record is built 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:
SourceConfigurationError – If no fal key is available (before any call).
- Return type:
- class foley.sources.fal.adapter.FalAnswer(media, response, metrics=None)[source]#
Bases:
tupleA runner’s
(media, response), with fal’s runmetricsbeside it.Still the two-tuple every runner answers (
media, response = answer), so a caller that does not know about metrics is unchanged;.metricsis fal’sCompleted.metrics(inference_time), orNone.
- foley.sources.fal.adapter.Runner#
runner(endpoint_id, arguments, *, api_key, audio_field) -> (audio_bytes, response), or aFalAnswer(that two-tuple, with fal’s run.metrics, #186).alias of
Callable[[…],tuple[bytes, dict] | FalAnswer]
- foley.sources.fal.adapter.audio_url(response, field='audio')[source]#
The URL of the audio in a fal response:
{field: {url}}or{field: [{url}, ...]}.>>> audio_url({"audio": {"url": "https://x/a.wav"}}) 'https://x/a.wav' >>> audio_url({"audio": [{"url": "https://x/b.wav"}]}) 'https://x/b.wav' >>> audio_url({"audio_file": {"url": "https://x/c.wav"}}, "audio_file") 'https://x/c.wav'
- foley.sources.fal.adapter.audio_urls(response, field='audio')[source]#
Every audio URL in a fal response, in order: one per sample for an endpoint that answers a list (Mirelo’s
audio, #210).>>> audio_urls({"audio": [{"url": "u1"}, {"url": "u2"}]}) ['u1', 'u2'] >>> audio_urls({"audio": {"url": "u"}}), audio_urls({}) (['u'], [])
- foley.sources.fal.adapter.falaw_runner(endpoint_id, arguments, *, api_key, audio_field='audio', all_audio=False)[source]#
Call a fal endpoint through falaw and return
(audio bytes, raw response).all_audio=True(a batch call, #210) answers(list of audio bytes, raw response): every sample the response lists, in order. A runner that serves a batch takes this keyword; one that never does need not.A
FalAnswer: its.metricsare fal’sCompleted.metrics(inference_time: the seconds the runner spent), which falaw carries on itsdoneevent (falaw#125);Nonewhen fal reported none (or an older falaw dropped them).refresh=Trueskips falaw’s cache read and keeps its write (see the module docstring: foley’s generations cache owns replay). The audio is downloaded byfalaw.materialize_asset, which content-addresses it in falaw’s store.- Raises:
SourceConfigurationError – For a refusal before anything was billed (the fal client is not installed, the key is refused, the account has no funds, an argument cannot be sent), so the run’s budget reservation is released.
RuntimeError – If the response carries no audio URL.
- Return type:
- foley.sources.fal.adapter.falaw_uploader(path, *, api_key)[source]#
A fal-fetchable URL for the local file at
path(falaw.upload: content-addressed, so an unchanged file is not uploaded twice).- Return type:
- foley.sources.fal.adapter.reported_watermark(response, stated, native_defaults)[source]#
The vendor’s watermark as this response reports it (#77), or
None.Only for an endpoint whose config names the response field (
native_defaults['watermark_field']: Sonilo’swatermark), and only when the response carries it: an absent field is no report (fal’s schema does not list it), so the config’s statement stands. The config’s own statement (stated) is kept beside the report.>>> reported_watermark({"watermark": "sonilo-v1"}, None, {"watermark_field": "watermark"}) {'present': True, 'statement': None, 'reported_by': 'response', 'detail': 'sonilo-v1'} >>> reported_watermark({}, None, {"watermark_field": "watermark"}) is None True >>> reported_watermark({"watermark": "x"}, None, {}) is None True