core: references for an audio generator -- a request's clips of a voice and their transcripts (RadAudioGenDecl::tmpl_ref, ref_item), decoded to mono at the model's rate and padded to whole frames, each frame a prompt row the plugin encodes in the PROMPT pass (RadAudioGenBatch::ref_audio, ref_cu, ref_frame); /v1/audio/speech's and the streaming session's references

This commit is contained in:
zivius committed 2026-10-21 01:00:13 +02:00
1 parent 4e750fed01
commit bdc5c5b063
13 files changed
+396 -24

No files matched your search

+25 -6
View File
@@ -974,6 +974,24 @@ typedef struct RadAudioGenDecl {
* text always is, so a caller can write the model's speaker tags. The plugin's
* rad_arch_text_prepare then refuses the control tokens a caller must not write. */
int32_t input_special;
/* References (voice cloning): with `tmpl_ref`, a request may carry up to `ref_max` of them,
* each a transcript and a clip of the voice saying it, which the plugin encodes into frames
* in the request's PROMPT pass (whole prompts only: `prompt_whole`). `tmpl_ref` is the prompt
* of a request with references, `{references}` each of them rendered from `ref_item` in turn
* and `{input}` as in `tmpl_plain`. `ref_item` is one reference: `{index}` its number from 1,
* `{text}` its transcript (rewritten by rad_arch_text_prepare as RAD_TEXT_REFERENCE) and
* `{audio}` its frames, one prompt row each (RadAudioGenBatch::ref_frame); the text before
* `{audio}` is tokenised as one segment with its special tokens (the transcript's own, which
* prepare() has limited to those a caller may write), and so is the text after it. A clip is
* mono f32 in [-1, 1] at `ref_rate`, right-padded with zeros to a whole number of `ref_hop`
* samples, each `ref_hop` samples one frame; a request's clips hold at most `ref_max_samples`
* samples together. NULL `tmpl_ref`: references are refused. */
const char* tmpl_ref;
const char* ref_item;
int64_t ref_rate;
int64_t ref_hop;
int64_t ref_max_samples;
int32_t ref_max;
} RadAudioGenDecl;
int rad_declare_audio_generator(RadBuilder* b, const RadAudioGenDecl* d);
@@ -1429,12 +1447,13 @@ const RadAudioFormat* rad_arch_audio_format(const RadModelMeta* meta);
* as given. Training data has conventions a client does not know -- section tags on lines of
* their own and lower case, no markdown in a description -- and only the plugin knows them.
*
* `field` is RAD_TEXT_*, `in` NUL-terminated UTF-8. Writes at most `cap` bytes, the NUL included,
* and returns the length the whole result needs without its NUL (call again with more room when
* it is >= cap), or a negative status for text the model cannot take, with the reason in `out`
* (NUL-terminated within `cap`) when it has one to give the caller. Called on HTTP threads, so it
* keeps no state. */
enum { RAD_TEXT_INSTRUCTIONS = 1, RAD_TEXT_INPUT = 2 };
* `field` is RAD_TEXT_*, `in` NUL-terminated UTF-8: the instructions, the input, or a
* reference's transcript (RadAudioGenDecl::ref_item's `{text}`). Writes at most `cap` bytes, the
* NUL included, and returns the length the whole result needs without its NUL (call again with
* more room when it is >= cap), or a negative status for text the model cannot take, with the
* reason in `out` (NUL-terminated within `cap`) when it has one to give the caller. Called on
* HTTP threads, so it keeps no state. */
enum { RAD_TEXT_INSTRUCTIONS = 1, RAD_TEXT_INPUT = 2, RAD_TEXT_REFERENCE = 3 };
int64_t rad_arch_text_prepare(int field, const char* in, char* out, int64_t cap);
/* The layout of a video generator's passes (rad_declare_video_generator), which only the model
+14
View File
@@ -475,6 +475,20 @@ typedef struct RadAudioGenBatch {
const int32_t* prev_slot;
const int32_t* prev_pos;
const int32_t* prev_used;
/* PROMPT of a request with references (RadAudioGenDecl::tmpl_ref; n_ref 0 without): its
* clips' samples end to end (`ref_samples` f32 on the device), the clips' bounds in samples
* ([n_ref + 1], each a whole number of RadAudioGenDecl::ref_hop), and for every row of the
* pass the frame of the clips it is or -1 for a token row ([n_tok]), frames counted over the
* clips in order, frame f the samples [f ref_hop, (f + 1) ref_hop). A frame's row stages
* token 0; the plugin embeds the frame there instead. */
int64_t n_ref;
int64_t ref_samples;
const float* ref_audio;
const int32_t* ref_cu;
const int32_t* ref_cu_h;
const int32_t* ref_frame;
const int32_t* ref_frame_h;
} RadAudioGenBatch;
/* A window entry's flags on a WINDOW pass. FIRST is RAD_GEN_F_FIRST's bit and the others are clear