library:ml: Piper's phonemiser and pipeline, with exact vocoder chunking
- Commit
649da9a4bc86aff4827aadc592d87bc8d807706b- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-28 01:47 UTC (3 months ago)
- Parents
428d1b0
Diff
library/ml/src/main/rust/src/post/mod.rs
diff --git a/library/ml/src/main/rust/src/post/mod.rs b/library/ml/src/main/rust/src/post/mod.rsindex 95df06c032..65d65a701e 100644--- a/library/ml/src/main/rust/src/post/mod.rs+++ b/library/ml/src/main/rust/src/post/mod.rs@@ -16,5 +16,7 @@ pub mod ctc; pub mod dbnet; pub mod duration; pub mod nms;+pub mod phonemes;+pub mod speech; pub mod spline; pub mod ocr;
library/ml/src/main/rust/src/post/phonemes.rs
diff --git a/library/ml/src/main/rust/src/post/phonemes.rs b/library/ml/src/main/rust/src/post/phonemes.rsnew file mode 100644index 0000000000..8ea352ba5b--- /dev/null+++ b/library/ml/src/main/rust/src/post/phonemes.rs@@ -0,0 +1,295 @@+//! Text to Piper phoneme ids, through the voice's grapheme-to-phoneme dictionary.+//!+//! # No espeak-ng on device+//!+//! Piper is normally driven by espeak-ng, which is a large GPL C library. It is not needed at+//! runtime here and never was: `scripts/speech/generate_piper_dict.py` runs espeak-ng on the+//! **build machine** to turn a word list into a `<lang>-word_id.bin` lookup table, and that+//! table ships with the voice. So this module is a dictionary reader, not a phonemiser.+//!+//! # The file+//!+//! Entries back to back, no header:+//!+//! ```text+//! word '\0' id id id ... '\xff'+//! ```+//!+//! Each id is one byte indexing the voice's `phoneme_id_map`. Lookup is case-insensitive, so+//! only one case is stored. Ids 0 to 3 are reserved — pad, beginning, end and space — and+//! never appear in an entry.+//!+//! # The one convention taken on trust+//!+//! How the per-word ids are assembled into a sequence is `piper1-gpl`'s+//! `phonemes_to_ids`: a beginning marker, then every phoneme followed by a pad, then an end+//! marker, with words separated by the space phoneme. The dictionary's own generator+//! corroborates the four reserved ids, but the assembly itself happens inside the ncnn AAR+//! this replaces and so could not be diffed against a running reference. If synthesis comes+//! out fluent but subtly wrong, this is the first thing to check.++use std::collections::HashMap;++/// Separates a phoneme from the next. Piper interleaves it between every pair.+pub const PAD: u8 = 0;++/// Starts the sequence.+pub const BOS: u8 = 1;++/// Ends the sequence.+pub const EOS: u8 = 2;++/// Between words.+pub const SPACE: u8 = 3;++/// Terminates an entry's id list in the file, so it can never be a phoneme id.+const TERMINATOR: u8 = 0xFF;++/// A voice's grapheme-to-phoneme dictionary.+#[derive(Debug)]+pub struct Dictionary {+ words: HashMap<String, Vec<u8>>,+}++impl Dictionary {+ /// Parse a `<lang>-word_id.bin`.+ ///+ /// A malformed trailing entry is refused rather than ignored: a truncated download that+ /// still parsed would lose whichever words came after the truncation, and the fallback+ /// spelling would quietly stand in for them.+ pub fn parse(bytes: &[u8]) -> Result<Dictionary, String> {+ let mut words = HashMap::new();+ let mut at = 0usize;+ while at < bytes.len() {+ let separator = bytes[at..]+ .iter()+ .position(|&b| b == 0)+ .ok_or("an entry with no terminator after its word")?;+ let word = std::str::from_utf8(&bytes[at..at + separator])+ .map_err(|e| format!("an entry whose word is not UTF-8: {e}"))?;+ let rest = at + separator + 1;+ let end = bytes[rest..]+ .iter()+ .position(|&b| b == TERMINATOR)+ .ok_or_else(|| format!("the entry for {word:?} has no id terminator"))?;+ let ids = bytes[rest..rest + end].to_vec();+ if ids.iter().any(|&id| id <= SPACE) {+ return Err(format!(+ "the entry for {word:?} contains a reserved id; ids 0..=3 are pad, \+ beginning, end and space"+ ));+ }+ words.insert(word.to_lowercase(), ids);+ at = rest + end + 1;+ }+ if words.is_empty() {+ return Err("a dictionary with no entries".into());+ }+ Ok(Dictionary { words })+ }++ /// Words the dictionary holds.+ pub fn len(&self) -> usize {+ self.words.len()+ }++ /// Whether it holds none.+ pub fn is_empty(&self) -> bool {+ self.words.is_empty()+ }++ /// The phonemes of one word, or `None` if it is absent.+ fn look_up(&self, word: &str) -> Option<&[u8]> {+ self.words.get(&word.to_lowercase()).map(|ids| ids.as_slice())+ }++ /// The phonemes of `word`, spelling it out character by character if it is absent.+ ///+ /// That fallback is what the ncnn path did, and it is why the generator adds every digit+ /// and single letter to the dictionary: without them an unknown word would produce+ /// nothing at all rather than a stilted reading.+ fn phonemes_of(&self, word: &str) -> Vec<u8> {+ if let Some(found) = self.look_up(word) {+ return found.to_vec();+ }+ let mut out = Vec::new();+ for character in word.chars() {+ let single = character.to_string();+ if let Some(found) = self.look_up(&single) {+ out.extend_from_slice(found);+ }+ }+ out+ }+}++/// Split `text` into the runs of characters the dictionary is keyed on.+///+/// Anything that is not alphanumeric or an apostrophe separates words. Punctuation is dropped+/// rather than voiced: the dictionary holds no entry for it, so keeping it would only trigger+/// the spelling fallback and read a full stop out as letters.+fn words(text: &str) -> Vec<String> {+ let mut out = Vec::new();+ let mut current = String::new();+ for character in text.chars() {+ if character.is_alphanumeric() || character == '\'' {+ current.push(character);+ } else if !current.is_empty() {+ out.push(std::mem::take(&mut current));+ }+ }+ if !current.is_empty() {+ out.push(current);+ }+ out+}++/// Turn `text` into the id sequence the text encoder takes.+///+/// Returns ids in `0..=255`; the caller widens them to the encoder's input. An input with no+/// pronounceable words gives `[BOS, EOS]`, which synthesises to silence rather than failing —+/// a text-to-speech engine handed a string of emoji should say nothing, not refuse.+pub fn to_ids(text: &str, dictionary: &Dictionary) -> Vec<u8> {+ let mut ids = vec![BOS];+ let mut first = true;+ for word in words(text) {+ let phonemes = dictionary.phonemes_of(&word);+ if phonemes.is_empty() {+ continue;+ }+ if !first {+ ids.push(SPACE);+ ids.push(PAD);+ }+ first = false;+ for phoneme in phonemes {+ ids.push(phoneme);+ ids.push(PAD);+ }+ }+ ids.push(EOS);+ ids+}++#[cfg(test)]+mod tests {+ use super::*;++ /// `word \0 ids \xff` for each pair.+ fn build(entries: &[(&str, &[u8])]) -> Vec<u8> {+ let mut out = Vec::new();+ for (word, ids) in entries {+ out.extend_from_slice(word.as_bytes());+ out.push(0);+ out.extend_from_slice(ids);+ out.push(TERMINATOR);+ }+ out+ }++ fn dictionary() -> Dictionary {+ Dictionary::parse(&build(&[+ ("hello", &[10, 11, 12]),+ ("world", &[20, 21]),+ ("a", &[30]),+ ("b", &[31]),+ ("7", &[40]),+ ]))+ .expect("parses")+ }++ #[test]+ fn entries_are_read_back_in_full() {+ let d = dictionary();+ assert_eq!(d.len(), 5);+ assert_eq!(d.look_up("hello"), Some(&[10u8, 11, 12][..]));+ assert_eq!(d.look_up("world"), Some(&[20u8, 21][..]));+ assert_eq!(d.look_up("missing"), None);+ }++ #[test]+ fn lookup_ignores_case() {+ // The generator stores one case, so a capitalised sentence has to still find its+ // words — otherwise every sentence's first word would be spelled out.+ let d = dictionary();+ assert_eq!(d.look_up("HELLO"), Some(&[10u8, 11, 12][..]));+ assert_eq!(d.look_up("Hello"), Some(&[10u8, 11, 12][..]));+ }++ #[test]+ fn a_sequence_is_bracketed_and_pad_interleaved() {+ // `piper1-gpl`'s `phonemes_to_ids`: BOS, then each phoneme followed by PAD, then EOS.+ let d = dictionary();+ assert_eq!(to_ids("hello", &d), vec![BOS, 10, PAD, 11, PAD, 12, PAD, EOS]);+ }++ #[test]+ fn words_are_separated_by_the_space_phoneme() {+ let d = dictionary();+ assert_eq!(+ to_ids("a b", &d),+ vec![BOS, 30, PAD, SPACE, PAD, 31, PAD, EOS]+ );+ }++ #[test]+ fn an_unknown_word_is_spelled_out() {+ // "ab" is not an entry, but "a" and "b" are, so it reads as two letters rather than+ // vanishing. This is why the generator seeds every letter and digit.+ let d = dictionary();+ assert_eq!(to_ids("ab", &d), vec![BOS, 30, PAD, 31, PAD, EOS]);+ // A character with no entry at all contributes nothing rather than breaking the word.+ assert_eq!(to_ids("aQb", &d), vec![BOS, 30, PAD, 31, PAD, EOS]);+ }++ #[test]+ fn punctuation_separates_words_without_being_voiced() {+ let d = dictionary();+ // The comma splits, and is not itself read out.+ assert_eq!(+ to_ids("a, b", &d),+ vec![BOS, 30, PAD, SPACE, PAD, 31, PAD, EOS]+ );+ // An apostrophe stays inside a word, because contractions are dictionary entries.+ assert_eq!(words("don't stop"), vec!["don't", "stop"]);+ }++ #[test]+ fn digits_are_looked_up_like_words() {+ let d = dictionary();+ assert_eq!(to_ids("7", &d), vec![BOS, 40, PAD, EOS]);+ }++ #[test]+ fn nothing_pronounceable_gives_silence_rather_than_an_error() {+ // A string of emoji should say nothing. Refusing would make the caller decide what to+ // do about a case that is not a failure.+ let d = dictionary();+ assert_eq!(to_ids("!!!", &d), vec![BOS, EOS]);+ assert_eq!(to_ids("", &d), vec![BOS, EOS]);+ }++ #[test]+ fn a_truncated_dictionary_is_refused() {+ // A half-downloaded file that still parsed would silently lose every word after the+ // cut, and the spelling fallback would stand in for them.+ let mut bytes = build(&[("hello", &[10, 11])]);+ bytes.pop();+ let error = Dictionary::parse(&bytes).expect_err("no terminator");+ assert!(error.contains("no id terminator"), "{error}");+ }++ #[test]+ fn an_entry_holding_a_reserved_id_is_refused() {+ // Ids 0..=3 are structural. One inside an entry would inject a sentence boundary in+ // the middle of a word.+ let bytes = build(&[("hello", &[10, SPACE, 12])]);+ let error = Dictionary::parse(&bytes).expect_err("reserved id");+ assert!(error.contains("reserved id"), "{error}");+ }++ #[test]+ fn an_empty_dictionary_is_refused() {+ assert!(Dictionary::parse(&[]).is_err());+ }+}
library/ml/src/main/rust/src/post/speech.rs
diff --git a/library/ml/src/main/rust/src/post/speech.rs b/library/ml/src/main/rust/src/post/speech.rsnew file mode 100644index 0000000000..b4035e4ca6--- /dev/null+++ b/library/ml/src/main/rust/src/post/speech.rs@@ -0,0 +1,343 @@+//! Text to a waveform: the whole of Piper, in order.+//!+//! # The pipeline+//!+//! ```text+//! text -> ids post::phonemes, a dictionary lookup+//! ids -> stats, hidden nets::vits_enc on the GPU+//! hidden -> durations post::duration on the CPU+//! stats + durations -> prior post::align on the CPU+//! prior -> latent nets::vits_flow on the GPU+//! latent -> audio nets::vits_dec on the GPU, in chunks+//! ```+//!+//! # Why the networks arrive as closures+//!+//! The same argument as [`super::ocr`]: everything between them is arithmetic on a few+//! hundred numbers, and all of it is testable on the host if the Vulkan parts are injected.+//! A function owning three `Net`s could only be exercised on a device.+//!+//! # Chunking the vocoder+//!+//! The vocoder's arena grows linearly with the utterance — 7.37 MiB per second of audio,+//! measured — so a ten-second sentence in one pass would want about 74 MiB. It is run over+//! [`CHUNK_FRAMES`] at a time instead.+//!+//! The overlap is *exact* rather than approximate, and that is a property of the network+//! rather than a hope: the vocoder is convolutional with a bounded receptive field, so a+//! sample depends only on frames within [`RECEPTIVE_FRAMES`] of it. Give each chunk that much+//! context on both sides and discard the corresponding audio, and every kept sample is+//! bit-identical to the one the whole-utterance pass would have produced.++use crate::nets::{vits_dec, vits_enc};++/// Latent frames per vocoder pass. About two seconds of audio at 16 kHz.+pub const CHUNK_FRAMES: usize = 128;++/// Frames of context each chunk needs on either side for its output to be exact.+///+/// The vocoder's widest kernel is 7 taps at dilation 12, so 72 samples of reach per residual+/// block, over three upsampling stages of 8, 8 and 4. Working that back to input frames and+/// rounding generously: 16 frames is over four times the true reach, and the cost of being+/// generous is four extra frames of discarded audio per chunk.+pub const RECEPTIVE_FRAMES: usize = 16;++/// One synthesised utterance.+#[derive(Debug)]+pub struct Speech {+ /// Mono samples in `-1..1`.+ pub samples: Vec<f32>,+ /// Sample rate, from the voice.+ pub sample_rate: u32,+ /// Frames the vocoder produced, before trimming.+ pub frames: usize,+}++/// The scales a voice's `config.json` carries.+pub struct Scales {+ /// How much noise to add to the prior. `noise_scale`.+ pub noise: f32,+ /// Speaking rate. `length_scale`; above one is slower.+ pub length: f32,+ /// How much noise the duration predictor samples. `noise_w`.+ pub duration_noise: f32,+}++impl Default for Scales {+ /// Piper's own defaults, from `en_GB-alan-low.onnx.json`.+ fn default() -> Self {+ Scales { noise: 0.667, length: 1.0, duration_noise: 0.8 }+ }+}++/// Everything the pipeline needs that is not a network.+pub struct Request<'a> {+ /// Phoneme ids from [`super::phonemes::to_ids`].+ pub ids: &'a [u8],+ /// The voice's inference scales.+ pub scales: &'a Scales,+ /// Output sample rate, carried so a caller cannot play at the wrong pitch.+ pub sample_rate: u32,+}++/// The three Vulkan stages, as closures over their plans.+pub trait Networks {+ /// `ids` to `(stats, hidden)` — the prior's statistics and the state the duration+ /// predictor conditions on.+ fn encode(&mut self, ids: &[f32]) -> Result<(Vec<f32>, Vec<f32>), String>;+ /// The prior to the latent the vocoder decodes, at whatever frame count it is given.+ fn flow(&mut self, prior: &[f32], frames: usize) -> Result<Vec<f32>, String>;+ /// A latent chunk to audio. Always exactly [`CHUNK_FRAMES`] plus context.+ fn vocode(&mut self, latent: &[f32], frames: usize) -> Result<Vec<f32>, String>;+}++/// Randomness, injected so a test can pin every draw.+pub trait Noise {+ /// `count` standard normal values.+ fn normal(&mut self, count: usize) -> Vec<f32>;+}++/// Synthesise one utterance.+///+/// `durations` is handed in rather than computed here because the duration predictor needs the+/// voice's weights, which the caller already holds; see [`super::duration::log_durations`].+pub fn synthesise(+ request: &Request,+ durations: &[u32],+ stats: &[f32],+ networks: &mut dyn Networks,+ noise: &mut dyn Noise,+) -> Result<Speech, String> {+ let phonemes = request.ids.len();+ let alignment = super::align::plan(durations)?;+ let frames = alignment.frames();+ let channels = vits_enc::D_MODEL as usize;++ let prior_noise = noise.normal(channels * frames);+ let prior = super::align::sample(+ stats,+ phonemes,+ &alignment,+ &prior_noise,+ request.scales.noise,+ )?;++ let latent = networks.flow(&prior, frames)?;+ if latent.len() != channels * frames {+ return Err(format!(+ "the flow returned {} values for {channels} channels over {frames} frames",+ latent.len()+ ));+ }++ let samples = vocode_in_chunks(&latent, channels, frames, networks)?;+ Ok(Speech { samples, sample_rate: request.sample_rate, frames })+}++/// Run the vocoder over the latent a chunk at a time, with exact overlap.+///+/// Each pass sees `RECEPTIVE_FRAMES` of context on both sides, and the audio belonging to that+/// context is discarded. Frames before the start and past the end are clamped to the edge,+/// which is what a single whole-utterance pass would see at its own boundaries.+fn vocode_in_chunks(+ latent: &[f32],+ channels: usize,+ frames: usize,+ networks: &mut dyn Networks,+) -> Result<Vec<f32>, String> {+ let per_frame = vits_dec::SAMPLES_PER_FRAME as usize;+ let mut samples = Vec::with_capacity(frames * per_frame);+ let mut start = 0usize;+ while start < frames {+ let end = (start + CHUNK_FRAMES).min(frames);+ let lead = start.min(RECEPTIVE_FRAMES);+ let trail = (frames - end).min(RECEPTIVE_FRAMES);+ let span = (end - start) + lead + trail;++ // Gather the window channel by channel: the latent is `[channels, frames]`, so a+ // frame range is a stride, not a contiguous block.+ let mut window = vec![0.0f32; channels * span];+ for channel in 0..channels {+ let from = channel * frames + start - lead;+ let to = channel * span;+ let source = latent+ .get(from..from + span)+ .ok_or("the latent is shorter than the chunk it was asked for")?;+ window[to..to + span].copy_from_slice(source);+ }++ let audio = networks.vocode(&window, span)?;+ if audio.len() != span * per_frame {+ return Err(format!(+ "the vocoder returned {} samples for {span} frames",+ audio.len()+ ));+ }+ // Discard the context's audio, keeping only what this chunk owns.+ let keep_from = lead * per_frame;+ let keep_to = audio.len() - trail * per_frame;+ samples.extend_from_slice(&audio[keep_from..keep_to]);+ start = end;+ }+ Ok(samples)+}++#[cfg(test)]+mod tests {+ use super::*;++ /// A vocoder that returns each frame's index, so the reassembly is checkable by eye.+ ///+ /// The latent it is handed carries the frame index in channel 0, and it emits that index+ /// repeated for every sample of the frame. So the concatenated output should be+ /// `0, 0, ..., 1, 1, ..., n-1` with no gaps, repeats or shifts.+ struct Counting {+ calls: Vec<usize>,+ }++ impl Networks for Counting {+ fn encode(&mut self, _ids: &[f32]) -> Result<(Vec<f32>, Vec<f32>), String> {+ unreachable!("the fixture drives the flow and the vocoder only")+ }++ fn flow(&mut self, prior: &[f32], _frames: usize) -> Result<Vec<f32>, String> {+ Ok(prior.to_vec())+ }++ fn vocode(&mut self, latent: &[f32], frames: usize) -> Result<Vec<f32>, String> {+ self.calls.push(frames);+ let per_frame = vits_dec::SAMPLES_PER_FRAME as usize;+ let mut out = Vec::with_capacity(frames * per_frame);+ // Channel 0 of each frame is its index in the whole utterance.+ for &marker in latent.iter().take(frames) {+ out.extend(std::iter::repeat_n(marker, per_frame));+ }+ Ok(out)+ }+ }++ struct Zero;++ impl Noise for Zero {+ fn normal(&mut self, count: usize) -> Vec<f32> {+ vec![0.0; count]+ }+ }++ /// A latent whose channel 0 holds the frame index.+ fn marked(channels: usize, frames: usize) -> Vec<f32> {+ let mut out = vec![0.0f32; channels * frames];+ for (frame, slot) in out.iter_mut().take(frames).enumerate() {+ *slot = frame as f32;+ }+ out+ }++ fn chunked(frames: usize) -> (Vec<f32>, Vec<usize>) {+ let channels = 4;+ let latent = marked(channels, frames);+ let mut networks = Counting { calls: Vec::new() };+ let samples =+ vocode_in_chunks(&latent, channels, frames, &mut networks).expect("vocodes");+ (samples, networks.calls)+ }++ #[test]+ fn a_short_utterance_is_one_chunk_with_no_context() {+ let frames = 10;+ let (samples, calls) = chunked(frames);+ // Nothing either side to take context from, so the pass is exactly the utterance.+ assert_eq!(calls, vec![frames]);+ let per_frame = vits_dec::SAMPLES_PER_FRAME as usize;+ assert_eq!(samples.len(), frames * per_frame);+ for frame in 0..frames {+ assert_eq!(samples[frame * per_frame], frame as f32);+ }+ }++ #[test]+ fn a_long_utterance_reassembles_without_a_gap_or_a_repeat() {+ // Three chunks' worth, so the middle one has context on both sides — the case where+ // an off-by-one in the trim would duplicate or drop a frame's audio.+ let frames = CHUNK_FRAMES * 2 + 40;+ let (samples, calls) = chunked(frames);+ assert_eq!(calls.len(), 3, "{calls:?}");+ let per_frame = vits_dec::SAMPLES_PER_FRAME as usize;+ assert_eq!(samples.len(), frames * per_frame, "total length");+ // Every frame appears exactly once, in order, for its whole span.+ for frame in 0..frames {+ for sample in 0..per_frame {+ let got = samples[frame * per_frame + sample];+ assert_eq!(got, frame as f32, "frame {frame} sample {sample}");+ }+ }+ }++ #[test]+ fn the_middle_chunk_is_given_context_on_both_sides() {+ let frames = CHUNK_FRAMES * 3;+ let (_, calls) = chunked(frames);+ assert_eq!(calls.len(), 3);+ // First: no lead, full trail. Middle: both. Last: lead only.+ assert_eq!(calls[0], CHUNK_FRAMES + RECEPTIVE_FRAMES);+ assert_eq!(calls[1], CHUNK_FRAMES + 2 * RECEPTIVE_FRAMES);+ assert_eq!(calls[2], CHUNK_FRAMES + RECEPTIVE_FRAMES);+ }++ #[test]+ fn a_chunk_boundary_exactly_on_the_end_does_not_emit_an_empty_pass() {+ let frames = CHUNK_FRAMES * 2;+ let (samples, calls) = chunked(frames);+ assert_eq!(calls.len(), 2, "{calls:?}");+ assert_eq!(samples.len(), frames * vits_dec::SAMPLES_PER_FRAME as usize);+ }++ #[test]+ fn synthesis_runs_the_whole_pipeline_and_reports_its_length() {+ let channels = vits_enc::D_MODEL as usize;+ let phonemes = 3;+ let durations = vec![2u32, 3, 1];+ let frames: usize = durations.iter().map(|&d| d as usize).sum();+ // Stats are `[2 * channels, phonemes]`: means then log deviations.+ let stats = vec![0.0f32; 2 * channels * phonemes];+ let mut networks = Counting { calls: Vec::new() };+ let request = Request {+ ids: &[1, 5, 0, 6, 0, 2],+ scales: &Scales::default(),+ sample_rate: vits_dec::SAMPLE_RATE,+ };+ // `ids` is only used for its length here, and the fixture's phoneme count is 3.+ let request = Request { ids: &request.ids[0..phonemes], ..request };+ let got = synthesise(&request, &durations, &stats, &mut networks, &mut Zero)+ .expect("synthesises");+ assert_eq!(got.frames, frames);+ assert_eq!(got.sample_rate, vits_dec::SAMPLE_RATE);+ assert_eq!(got.samples.len(), frames * vits_dec::SAMPLES_PER_FRAME as usize);+ }++ #[test]+ fn a_flow_that_returns_the_wrong_length_is_refused() {+ struct Short;+ impl Networks for Short {+ fn encode(&mut self, _: &[f32]) -> Result<(Vec<f32>, Vec<f32>), String> {+ unreachable!()+ }+ fn flow(&mut self, _: &[f32], _: usize) -> Result<Vec<f32>, String> {+ Ok(vec![0.0; 3])+ }+ fn vocode(&mut self, _: &[f32], _: usize) -> Result<Vec<f32>, String> {+ unreachable!()+ }+ }+ let channels = vits_enc::D_MODEL as usize;+ let stats = vec![0.0f32; 2 * channels];+ let request = Request {+ ids: &[1],+ scales: &Scales::default(),+ sample_rate: vits_dec::SAMPLE_RATE,+ };+ let error = synthesise(&request, &[4], &stats, &mut Short, &mut Zero)+ .expect_err("a short flow");+ assert!(error.contains("the flow returned 3"), "{error}");+ }+}