A text-to-speech request. Layer A serializable data.
iex> req = ALLM.SpeechRequest.new(input: "Hello.", voice: "alloy", format: :mp3)
iex> ALLM.Validate.speech_request(req)
:okFields
:input: the text to speak.""is constructible, andALLM.Validate.speech_request/1is what rejects it.:model:nilmeans late-resolved (the engine's speech model, then the adapter's default).:voice: a provider-shaped voice name, forwarded as given. ALLM keeps no voice catalogue, because valid names differ per provider and per model.nillets the adapter choose.:format: the audio file format to produce, one offormats/0, ornilfor the provider's default. The atoms name file formats, not any one provider's parameter. A provider that cannot produce a format refuses the request, and the atoms are protocol-legal rather than a promise that every provider accepts every one. The response reports the format that actually arrived (ALLM.SpeechResponse's:format).:ulawand:alaware headerless G.711 µ-law and A-law telephony audio, 8,000 Hz mono; of the bundled adapters onlyALLM.Providers.ElevenLabs.Speechproduces them, andALLM.Providers.OpenAI.Speechrefuses them with:unsupported_feature.:instructions: optional delivery guidance for models that accept it.:sample_rate: the sample rate in Hz of the audio to produce, ornilfor the adapter's default for the format. It matters most for:pcm, which is headerless: the bytes cannot be played without knowing the rate. The cross-provider default for:pcmis 24,000 Hz, so switching providers does not silently change the playback rate. The adapter contract is to accept its own set of rates per format, refuse any other with:unsupported_feature, and report the rate that arrived inALLM.SpeechResponse's:sample_rate(nilwhen the adapter cannot tell).:speed: optional playback speed. Only "a number greater than zero" is checked here, and each provider enforces its own range.:options: a raw provider-body passthrough for fields ALLM does not model. An adapter merges it under the fields it sets itself, so an option can never override:input,:modelor any other structural field, and fields that would change the response shape are dropped.:metadata: caller-owned. Use string keys when it will round-trip through JSON.
There is no :stream field. Streaming is a separate call, not a request
flag: the same request goes to ALLM.stream_synthesize/3, and
ALLM.stream_synthesize_input/3 takes one whose :input is ignored.
Construction
new/1 is a bare struct!/2 pass-through: unknown keys raise
KeyError, and nothing else is checked. new(sample_rate: -1) constructs,
and ALLM.Validate.speech_request/1 is what rejects it.
Summary
Functions
The closed list of :format values, and the single source for the
validator and every adapter's format mapping.
Build a %SpeechRequest{} from keyword opts.
Types
@type format() :: :mp3 | :opus | :aac | :flac | :wav | :pcm | :ulaw | :alaw
A synthesized audio file format.
Functions
@spec formats() :: [format()]
The closed list of :format values, and the single source for the
validator and every adapter's format mapping.
An exhaustive case over format/0 needs a clause for each. :ulaw
and :alaw (8 kHz G.711 telephony audio) were added after the first six.
Examples
iex> ALLM.SpeechRequest.formats()
[:mp3, :opus, :aac, :flac, :wav, :pcm, :ulaw, :alaw]
Build a %SpeechRequest{} from keyword opts.
Unknown keys raise KeyError via struct!/2. Call
ALLM.Validate.speech_request/1 to check the field rules.
Examples
iex> req = ALLM.SpeechRequest.new(input: "Hi.")
iex> {req.input, req.format, req.options}
{"Hi.", nil, %{}}