pub struct MtmdAudioGen<'ctx> { /* private fields */ }Expand description
Text-to-speech through an mmproj audio-generation pipeline.
This is the other direction of multimodal: where MtmdBitmap feeds
audio in, this drives a pipeline that emits it. The loop is explicitly
stateless on llama.cpp’s side, so it runs in two phases:
Self::set_input, thenSelf::step_promptuntil it returns0— the prompt is consumedn_batchtokens at a time.Self::step_genper frame until it reports stop.Self::outputfor the finished audio.
Wraps mtmd_helper_gen_audio_*.
Implementations§
Source§impl<'ctx> MtmdAudioGen<'ctx>
impl<'ctx> MtmdAudioGen<'ctx>
Sourcepub fn new(lctx: &mut LlamaContext<'_>, mctx: &'ctx MtmdContext) -> Result<Self>
pub fn new(lctx: &mut LlamaContext<'_>, mctx: &'ctx MtmdContext) -> Result<Self>
Attach a generator to a llama context and an mtmd context.
§Errors
Returns MtmdError::ContextCreateFailed if the mmproj has no
audio-generation pipeline.
Sourcepub fn set_input(
&mut self,
request: &MtmdAudioRequest,
speaker_ref: Option<&MtmdBitmap>,
) -> Result<()>
pub fn set_input( &mut self, request: &MtmdAudioRequest, speaker_ref: Option<&MtmdBitmap>, ) -> Result<()>
Set what to synthesize. speaker_ref is an optional voice reference for
pipelines that support cloning.
§Errors
Returns MtmdError::EvalError if llama.cpp rejects the request, or
MtmdError::InvalidPath if a string contains an interior NUL.
Sourcepub fn step_prompt(&mut self, n_batch: i32) -> Result<i32>
pub fn step_prompt(&mut self, n_batch: i32) -> Result<i32>
Consume up to n_batch prompt tokens.
Returns the number of prompt tokens still outstanding; call again until
it returns 0, then move on to Self::step_gen.
§Errors
Returns MtmdError::EvalError if llama.cpp reports a negative code.
Sourcepub fn step_gen(
&mut self,
sampled: Option<LlamaToken>,
h_state_in: Option<&[f32]>,
n_text_embd: usize,
) -> Result<(Option<Vec<f32>>, bool)>
pub fn step_gen( &mut self, sampled: Option<LlamaToken>, h_state_in: Option<&[f32]>, n_text_embd: usize, ) -> Result<(Option<Vec<f32>>, bool)>
Generate one audio frame.
sampled is the backbone token just sampled, or None for pipelines
with no discrete backbone token. h_state_in is the hidden state fed
back from the previous step.
Returns (hidden_state, stop). stop marks end-of-speech: the caller
must break the loop. The hidden state borrows generator memory that the
next step_gen or Self::reset invalidates, hence the &mut self
borrow being released before you can call again.
§Errors
Returns MtmdError::EvalError on a negative code.
Sourcepub fn output(&mut self) -> Result<(i32, Vec<u8>, i64)>
pub fn output(&mut self) -> Result<(i32, Vec<u8>, i64)>
Collect the generated audio.
Returns (sample_rate, bytes, n_samples). bytes is raw PCM or a
complete WAV file depending on the request’s
MtmdAudioOutType.
§Errors
Returns MtmdError::EvalError if nothing has been generated.