Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[ensu] Run transcription directly with ort

laurenspriem4840fb61b513
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index a10103296f..d2c96d7898 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -1892,38 +1892,14 @@ dependencies = [
"syn 2.0.117",
]
-[[package]]
-name = "darling"
-version = "0.20.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
-dependencies = [
- "darling_core 0.20.11",
- "darling_macro 0.20.11",
-]
-
[[package]]
name = "darling"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d"
dependencies = [
- "darling_core 0.23.0",
- "darling_macro 0.23.0",
-]
-
-[[package]]
-name = "darling_core"
-version = "0.20.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
-dependencies = [
- "fnv",
- "ident_case",
- "proc-macro2",
- "quote",
- "strsim",
- "syn 2.0.117",
+ "darling_core",
+ "darling_macro",
]
[[package]]
@@ -1939,24 +1915,13 @@ dependencies = [
"syn 2.0.117",
]
-[[package]]
-name = "darling_macro"
-version = "0.20.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
-dependencies = [
- "darling_core 0.20.11",
- "quote",
- "syn 2.0.117",
-]
-
[[package]]
name = "darling_macro"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d"
dependencies = [
- "darling_core 0.23.0",
+ "darling_core",
"quote",
"syn 2.0.117",
]
@@ -2065,37 +2030,6 @@ dependencies = [
"syn 1.0.109",
]
-[[package]]
-name = "derive_builder"
-version = "0.20.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947"
-dependencies = [
- "derive_builder_macro",
-]
-
-[[package]]
-name = "derive_builder_core"
-version = "0.20.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
-dependencies = [
- "darling 0.20.11",
- "proc-macro2",
- "quote",
- "syn 2.0.117",
-]
-
-[[package]]
-name = "derive_builder_macro"
-version = "0.20.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c"
-dependencies = [
- "derive_builder_core",
- "syn 2.0.117",
-]
-
[[package]]
name = "derive_more"
version = "2.1.1"
@@ -2549,7 +2483,7 @@ dependencies = [
"ente-photos",
"ente-photos-export",
"ente-test-support",
- "env_logger 0.11.11",
+ "env_logger",
"futures-util",
"keyring",
"mockito",
@@ -2646,7 +2580,6 @@ dependencies = [
"tempfile",
"thiserror 2.0.21",
"tokio",
- "transcribe-rs",
"url",
"uuid",
"zeroize",
@@ -3153,19 +3086,6 @@ dependencies = [
"regex",
]
-[[package]]
-name = "env_logger"
-version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580"
-dependencies = [
- "humantime",
- "is-terminal",
- "log",
- "regex",
- "termcolor",
-]
-
[[package]]
name = "env_logger"
version = "0.11.11"
@@ -4288,12 +4208,6 @@ version = "1.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec9d92d097f4749b64e8cc33d924d9f40a2d4eb91402b458014b781f5733d60f"
-[[package]]
-name = "hound"
-version = "3.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
-
[[package]]
name = "hpke"
version = "0.14.1"
@@ -4384,12 +4298,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
-[[package]]
-name = "humantime"
-version = "2.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
-
[[package]]
name = "hybrid-array"
version = "0.4.14"
@@ -8755,7 +8663,7 @@ version = "3.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84d57bc0c8b9a17920c178daa6bb924850d54a9c97ab45194bb8c17ad66bb660"
dependencies = [
- "darling 0.23.0",
+ "darling",
"proc-macro2",
"quote",
"syn 2.0.117",
@@ -10338,26 +10246,6 @@ dependencies = [
"valuable",
]
-[[package]]
-name = "transcribe-rs"
-version = "0.3.11"
-source = "git+https://github.com/cjpais/transcribe-rs.git?rev=efc66111d519a434e28d51d94740008a7ce29360#efc66111d519a434e28d51d94740008a7ce29360"
-dependencies = [
- "base64 0.22.1",
- "derive_builder",
- "env_logger 0.10.2",
- "hound",
- "log",
- "ndarray",
- "once_cell",
- "ort",
- "regex",
- "rustfft",
- "serde",
- "serde_json",
- "thiserror 2.0.21",
-]
-
[[package]]
name = "transpose"
version = "0.2.3"
diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.toml
index 4b0e3e9dd1..9d1c5e360f 100644
--- a/rust/crates/ensu/Cargo.toml
+++ b/rust/crates/ensu/Cargo.toml
@@ -7,7 +7,7 @@ ente-assets.workspace = true
ente-core.workspace = true
ente-ensu-crypto.workspace = true
ente-image.workspace = true
-ort = { workspace = true, optional = true }
+ort = { workspace = true, features = ["std", "api-27", "download-binaries", "tls-native", "copy-dylibs", "tracing"], optional = true }
regex.workspace = true
rubato = { version = "5.0.0", optional = true }
rusqlite = { workspace = true, default-features = true, optional = true }
@@ -16,7 +16,6 @@ serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["rt", "time"] }
-transcribe-rs = { git = "https://github.com/cjpais/transcribe-rs.git", rev = "efc66111d519a434e28d51d94740008a7ce29360", default-features = false, features = ["onnx"], optional = true }
url.workspace = true
uuid = { workspace = true, features = ["v4", "rng-getrandom"] }
zeroize.workspace = true
@@ -58,7 +57,6 @@ transcription = [
"dep:ort",
"dep:ort-sys",
"dep:rubato",
- "dep:transcribe-rs",
]
[lints]
diff --git a/rust/crates/ensu/src/transcription/audio.rs b/rust/crates/ensu/src/transcription/audio.rs
index 059da6020d..47ea14c4f5 100644
--- a/rust/crates/ensu/src/transcription/audio.rs
+++ b/rust/crates/ensu/src/transcription/audio.rs
@@ -1,9 +1,9 @@
use std::path::Path;
use std::time::Duration;
+use super::vad::{SpeechGate, Vad};
use rubato::audioadapter_buffers::direct::InterleavedSlice;
use rubato::{Fft, FixedSync, Resampler, WindowFunction};
-use transcribe_rs::vad::{SmoothedVad, Vad};
use crate::transcription::{Result, SileroV4Vad, TranscriptionError};
@@ -56,7 +56,7 @@ fn extract_speech(
return Err(TranscriptionError::VadNotDownloaded);
}
let silero = SileroV4Vad::new(vad_model_path, 0.5)?;
- let mut vad = SmoothedVad::new(
+ let mut vad = SpeechGate::new(
Box::new(silero),
VAD_PREFILL_FRAMES,
VAD_HANGOVER_FRAMES,
@@ -94,7 +94,7 @@ fn extract_speech_with_vad(
resampler.push(samples, &mut emit)?;
resampler.finish(&mut emit)?;
if let Some(error) = vad_error {
- return Err(error.into());
+ return Err(error);
}
vad.reset();
@@ -231,15 +231,12 @@ mod tests {
fn frame_size(&self) -> usize {
480
}
- fn is_speech(
- &mut self,
- _: &[f32],
- ) -> std::result::Result<bool, transcribe_rs::TranscribeError> {
+ fn is_speech(&mut self, _: &[f32]) -> Result<bool> {
self.frames += 1;
if self.frames == 1 {
Ok(true)
} else {
- Err(transcribe_rs::TranscribeError::Inference(
+ Err(TranscriptionError::Transcribe(
"injected VAD failure".into(),
))
}
diff --git a/rust/crates/ensu/src/transcription/graph_cache.rs b/rust/crates/ensu/src/transcription/graph_cache.rs
index 2443e98427..3a532143bb 100644
--- a/rust/crates/ensu/src/transcription/graph_cache.rs
+++ b/rust/crates/ensu/src/transcription/graph_cache.rs
@@ -95,7 +95,7 @@ impl GraphCache {
};
let recipe = digest_bytes(
format!(
- "schema={SCHEMA};upstream=efc66111;ort-api={};os={};arch={};device={};{runtime_configuration}",
+ "schema={SCHEMA};backend=ensu-parakeet-v1;ort-api={};os={};arch={};device={};{runtime_configuration}",
ort::MINOR_VERSION,
std::env::consts::OS,
std::env::consts::ARCH,
diff --git a/rust/crates/ensu/src/transcription/live.rs b/rust/crates/ensu/src/transcription/live.rs
index d821a6cbab..0bae994caa 100644
--- a/rust/crates/ensu/src/transcription/live.rs
+++ b/rust/crates/ensu/src/transcription/live.rs
@@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, TryRecvError};
use std::time::Duration;
-use transcribe_rs::vad::Vad;
+use super::vad::Vad;
use super::{StreamNormalizer, Transcriber};
use crate::voice::{
@@ -344,8 +344,8 @@ impl LiveTranscription {
#[cfg(test)]
mod tests {
+ use super::super::vad::EnergyVad;
use super::*;
- use transcribe_rs::vad::EnergyVad;
fn stream() -> LiveTranscription {
LiveTranscription::new(CaptureFormat {
@@ -531,7 +531,6 @@ mod tests {
#[test]
fn model_initialization_failures_preserve_causes_and_close_capture() {
use super::super::TranscriptionError;
- use transcribe_rs::TranscribeError;
for (error, expected) in [
(TranscriptionError::NotDownloaded, VoiceError::NotDownloaded),
@@ -540,19 +539,21 @@ mod tests {
VoiceError::VadNotDownloaded,
),
(
- TranscribeError::Io(std::io::ErrorKind::StorageFull.into()).into(),
+ std::io::Error::from(std::io::ErrorKind::StorageFull).into(),
VoiceError::StorageFull,
),
(
- TranscribeError::Io(std::io::Error::other("injected I/O failure")).into(),
+ std::io::Error::other("injected I/O failure").into(),
VoiceError::Io("Load transcription model: injected I/O failure".into()),
),
(
- TranscribeError::Audio("injected audio failure".into()).into(),
+ TranscriptionError::InvalidAudio("injected audio failure".into()),
VoiceError::InvalidAudio("Load transcription model: injected audio failure".into()),
),
(
- TranscribeError::Inference("injected initialization failure".into()).into(),
+ TranscriptionError::Transcribe(
+ "inference error: injected initialization failure".into(),
+ ),
VoiceError::ProcessingFailed(
"Load transcription model: inference error: injected initialization failure"
.into(),
diff --git a/rust/crates/ensu/src/transcription/mod.rs b/rust/crates/ensu/src/transcription/mod.rs
index 8be3b041e3..d16f78e628 100644
--- a/rust/crates/ensu/src/transcription/mod.rs
+++ b/rust/crates/ensu/src/transcription/mod.rs
@@ -2,6 +2,7 @@ mod audio;
mod graph_cache;
mod live;
mod normalize;
+mod parakeet;
mod recorded;
mod session;
mod text;
@@ -44,17 +45,6 @@ impl From<std::io::Error> for TranscriptionError {
}
}
-impl From<transcribe_rs::TranscribeError> for TranscriptionError {
- fn from(value: transcribe_rs::TranscribeError) -> Self {
- match value {
- transcribe_rs::TranscribeError::ModelNotFound(_) => Self::NotDownloaded,
- transcribe_rs::TranscribeError::Audio(detail) => Self::InvalidAudio(detail),
- transcribe_rs::TranscribeError::Io(error) => error.into(),
- error => Self::Transcribe(error.to_string()),
- }
- }
-}
-
impl<R> From<ort::Error<R>> for TranscriptionError {
fn from(value: ort::Error<R>) -> Self {
Self::Transcribe(value.to_string())
diff --git a/rust/crates/ensu/src/transcription/parakeet.rs b/rust/crates/ensu/src/transcription/parakeet.rs
new file mode 100644
index 0000000000..af674bf203
--- /dev/null
+++ b/rust/crates/ensu/src/transcription/parakeet.rs
@@ -0,0 +1,332 @@
+use std::path::Path;
+
+use ort::{
+ inputs,
+ session::{Session, SessionOutputs, builder::GraphOptimizationLevel},
+ value::{DynValue, TensorRef},
+};
+
+use super::{Result, TranscriptionError};
+
+const SAMPLE_RATE: usize = 16000;
+const LEADING_SAMPLES: usize = SAMPLE_RATE / 4;
+const FRAME_SECONDS: f32 = 0.08;
+const ENCODER_CHANNELS: usize = 1024;
+const STATE_SHAPE: [usize; 3] = [2, 1, 640];
+const STATE_ELEMENTS: usize = 1280;
+const MAX_SYMBOLS_PER_FRAME: usize = 10;
+const DURATION_CLASSES: usize = 5;
+
+#[derive(Debug, Default)]
+pub(super) struct Transcript {
+ pub text: String,
+ pub words: Vec<TimedWord>,
+}
+
+#[derive(Debug)]
+pub(super) struct TimedWord {
+ pub text: String,
+ pub start: f32,
+ pub end: f32,
+}
+
+pub(super) struct Parakeet {
+ features: Session,
+ encoder: Session,
+ decoder: Session,
+ vocabulary: Vec<String>,
+ blank: usize,
+}
+
+struct Emission {
+ token: usize,
+ frame: usize,
+}
+
+impl Parakeet {
+ pub fn load(directory: &Path) -> Result<Self> {
+ let vocabulary = read_vocabulary(&std::fs::read_to_string(directory.join("vocab.txt"))?)?;
+ let blank = vocabulary
+ .iter()
+ .position(|token| token == "<blk>")
+ .ok_or_else(|| invalid_model("vocabulary has no blank token"))?;
+ Ok(Self {
+ features: load_session(&directory.join("nemo128.onnx"))?,
+ encoder: load_session(&directory.join("encoder-model.int8.onnx"))?,
+ decoder: load_session(&directory.join("decoder_joint-model.int8.onnx"))?,
+ vocabulary,
+ blank,
+ })
+ }
+
+ pub fn transcribe(&mut self, samples: &[f32]) -> Result<Transcript> {
+ if samples.is_empty() {
+ return Ok(Transcript::default());
+ }
+ if samples.iter().any(|value| !value.is_finite()) {
+ return Err(TranscriptionError::InvalidAudio(
+ "Recognition requires finite samples at 16 kHz".into(),
+ ));
+ }
+ let mut waveform = vec![0.0; LEADING_SAMPLES];
+ waveform.extend_from_slice(samples);
+ let waveform_length = [waveform.len() as i64];
+ let features = self.features.run(inputs![
+ "waveforms" => TensorRef::from_array_view(([1, waveform.len()], waveform.as_slice()))?,
+ "waveforms_lens" => TensorRef::from_array_view(([1], waveform_length.as_slice()))?,
+ ])?;
+ let (feature_shape, feature_values) =
+ output(&features, "features")?.try_extract_tensor::<f32>()?;
+ let (_, feature_lengths) =
+ output(&features, "features_lens")?.try_extract_tensor::<i64>()?;
+ if feature_shape.len() != 3
+ || feature_shape[0] != 1
+ || feature_shape[1] != 128
+ || feature_lengths.len() != 1
+ {
+ return Err(invalid_model("invalid audio features"));
+ }
+ let encoded = self.encoder.run(inputs![
+ "audio_signal" => TensorRef::from_array_view((feature_shape.clone(), feature_values))?,
+ "length" => TensorRef::from_array_view(([1], feature_lengths))?,
+ ])?;
+ let (encoded_shape, encoded_values) =
+ output(&encoded, "outputs")?.try_extract_tensor::<f32>()?;
+ let (_, encoded_lengths) =
+ output(&encoded, "encoded_lengths")?.try_extract_tensor::<i64>()?;
+ if encoded_shape.len() != 3
+ || encoded_shape[0] != 1
+ || encoded_shape[1] != ENCODER_CHANNELS as i64
+ || encoded_lengths.len() != 1
+ || encoded_lengths[0] < 0
+ || encoded_lengths[0] > encoded_shape[2]
+ {
+ return Err(invalid_model("invalid encoder output"));
+ }
+ let emissions = decode(
+ &mut self.decoder,
+ encoded_values,
+ encoded_shape[2] as usize,
+ encoded_lengths[0] as usize,
+ self.vocabulary.len(),
+ self.blank,
+ )?;
+ Ok(render(&emissions, &self.vocabulary))
+ }
+}
+
+fn load_session(path: &Path) -> Result<Session> {
+ Ok(Session::builder()?
+ .with_optimization_level(GraphOptimizationLevel::Level3)?
+ .with_parallel_execution(true)?
+ .with_execution_providers([ort::ep::CPU::default().build()])?
+ .commit_from_file(path)?)
+}
+
+fn read_vocabulary(text: &str) -> Result<Vec<String>> {
+ let mut vocabulary = Vec::new();
+ for line in text.lines() {
+ let (token, index) = line
+ .rsplit_once(' ')
+ .ok_or_else(|| invalid_model("invalid vocabulary entry"))?;
+ if index.parse::<usize>().ok() != Some(vocabulary.len()) || token.is_empty() {
+ return Err(invalid_model("vocabulary indices must be contiguous"));
+ }
+ vocabulary.push(token.to_owned());
+ }
+ Ok(vocabulary)
+}
+
+fn decode(
+ decoder: &mut Session,
+ encoded: &[f32],
+ stride: usize,
+ frames: usize,
+ vocabulary_size: usize,
+ blank: usize,
+) -> Result<Vec<Emission>> {
+ let mut hidden = vec![0.0_f32; STATE_ELEMENTS];
+ let mut cell = vec![0.0_f32; STATE_ELEMENTS];
+ let mut embedding = vec![0.0_f32; ENCODER_CHANNELS];
+ let target_length = [1_i32];
+ let mut target = [blank as i32];
+ let mut emissions = Vec::new();
+ let mut frame = 0;
+ let mut symbols = 0;
+ while frame < frames {
+ for (channel, value) in embedding.iter_mut().enumerate() {
+ *value = encoded[channel * stride + frame];
+ }
+ let decoded = decoder.run(inputs![
+ "encoder_outputs" => TensorRef::from_array_view(([1, ENCODER_CHANNELS, 1], embedding.as_slice()))?,
+ "targets" => TensorRef::from_array_view(([1, 1], target.as_slice()))?,
+ "target_length" => TensorRef::from_array_view(([1], target_length.as_slice()))?,
+ "input_states_1" => TensorRef::from_array_view((STATE_SHAPE, hidden.as_slice()))?,
+ "input_states_2" => TensorRef::from_array_view((STATE_SHAPE, cell.as_slice()))?,
+ ])?;
+ let (_, logits) = output(&decoded, "outputs")?.try_extract_tensor::<f32>()?;
+ if logits.len() != vocabulary_size + DURATION_CLASSES {
+ return Err(invalid_model("invalid decoder logits"));
+ }
+ let token = argmax(&logits[..vocabulary_size])?;
+ if token != blank {
+ emissions.push(Emission { token, frame });
+ target[0] = token as i32;
+ let (_, next_hidden) =
+ output(&decoded, "output_states_1")?.try_extract_tensor::<f32>()?;
+ let (_, next_cell) =
+ output(&decoded, "output_states_2")?.try_extract_tensor::<f32>()?;
+ if next_hidden.len() != STATE_ELEMENTS || next_cell.len() != STATE_ELEMENTS {
+ return Err(invalid_model("invalid decoder state"));
+ }
+ hidden.copy_from_slice(next_hidden);
+ cell.copy_from_slice(next_cell);
+ }
+ symbols += 1;
+ if token == blank || symbols >= MAX_SYMBOLS_PER_FRAME {
+ frame += 1;
+ symbols = 0;
+ }
+ }
+ Ok(emissions)
+}
+
+fn argmax(values: &[f32]) -> Result<usize> {
+ if values.is_empty() {
+ return Err(invalid_model("empty decoder logits"));
+ }
+ let mut best = 0;
+ for (index, &value) in values.iter().enumerate() {
+ if !value.is_finite() {
+ return Err(invalid_model("non-finite decoder logits"));
+ }
+ if value >= values[best] {
+ best = index;
+ }
+ }
+ Ok(best)
+}
+
+fn render(emissions: &[Emission], vocabulary: &[String]) -> Transcript {
+ let mut transcript = Transcript::default();
+ for (index, emission) in emissions.iter().enumerate() {
+ let piece = vocabulary[emission.token].replace('▁', " ");
+ let start = emission.frame as f32 * FRAME_SECONDS;
+ let end = emissions
+ .get(index + 1)
+ .map_or(start + 0.05, |next| next.frame as f32 * FRAME_SECONDS);
+ transcript.text.push_str(&piece);
+ if piece.trim().is_empty() {
+ continue;
+ }
+ if piece.starts_with(' ') || transcript.words.is_empty() {
+ transcript.words.push(TimedWord {
+ text: piece.trim().to_owned(),
+ start,
+ end,
+ });
+ } else if let Some(word) = transcript.words.last_mut() {
+ word.text.push_str(&piece);
+ word.end = end;
+ }
+ }
+ transcript.text = transcript
+ .text
+ .split_whitespace()
+ .collect::<Vec<_>>()
+ .join(" ");
+ for word in &mut transcript.words {
+ word.start = (word.start - 0.25).max(0.0);
+ word.end = (word.end - 0.25).max(0.0);
+ }
+ transcript
+}
+
+fn invalid_model(detail: &str) -> TranscriptionError {
+ TranscriptionError::Transcribe(format!("Parakeet: {detail}"))
+}
+
+fn output<'a>(outputs: &'a SessionOutputs<'_>, name: &str) -> Result<&'a DynValue> {
+ outputs
+ .get(name)
+ .ok_or_else(|| invalid_model(&format!("missing {name} output")))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn vocabulary_requires_ordered_indices_and_nonempty_tokens() {
+ assert_eq!(
+ read_vocabulary("▁Hello 0\nη•Œ 1\n<blk> 2\n").unwrap(),
+ ["▁Hello", "η•Œ", "<blk>"]
+ );
+ for invalid in ["word", "word 1", "word 0\nnext 0", " 0"] {
+ assert!(read_vocabulary(invalid).is_err(), "{invalid}");
+ }
+ }
+
+ #[test]
+ fn word_boundaries_keep_unicode_punctuation_and_remove_leading_padding() {
+ let vocabulary = vec![
+ "▁Hello".into(),
+ ",".into(),
+ "▁世".into(),
+ "η•Œ".into(),
+ "!".into(),
+ ];
+ let emissions = vec![
+ Emission { token: 0, frame: 1 },
+ Emission { token: 1, frame: 4 },
+ Emission { token: 2, frame: 5 },
+ Emission { token: 3, frame: 5 },
+ Emission { token: 4, frame: 9 },
+ ];
+ let transcript = render(&emissions, &vocabulary);
+ assert_eq!(transcript.text, "Hello, δΈ–η•Œ!");
+ assert_eq!(transcript.words.len(), 2);
+ assert_eq!(transcript.words[0].text, "Hello,");
+ assert_eq!(transcript.words[0].start, 0.0);
+ assert_eq!(transcript.words[0].end, 5.0 * FRAME_SECONDS - 0.25);
+ assert_eq!(transcript.words[1].text, "δΈ–η•Œ!");
+ assert_eq!(transcript.words[1].start, 5.0 * FRAME_SECONDS - 0.25);
+ assert_eq!(transcript.words[1].end, 9.0 * FRAME_SECONDS + 0.05 - 0.25);
+ assert!(render(&[], &vocabulary).words.is_empty());
+ }
+
+ #[test]
+ fn decoder_logits_require_finite_values() {
+ assert_eq!(argmax(&[-3.0, 2.0, 2.0]).unwrap(), 2);
+ assert!(argmax(&[]).is_err());
+ assert!(argmax(&[0.0, f32::NAN]).is_err());
+ assert!(argmax(&[f32::INFINITY]).is_err());
+ }
+
+ #[test]
+ fn standalone_word_markers_do_not_emit_empty_words_or_double_spaces() {
+ let vocabulary = vec!["▁Hello".into(), "▁".into(), "β–δΈ–η•Œ".into(), "!".into()];
+ let emissions: Vec<_> = (0..4)
+ .map(|token| Emission {
+ token,
+ frame: token + 4,
+ })
+ .collect();
+ let transcript = render(&emissions, &vocabulary);
+ assert_eq!(transcript.text, "Hello δΈ–η•Œ!");
+ assert_eq!(transcript.words.len(), 2);
+ assert_eq!(transcript.words[0].end, 5.0 * FRAME_SECONDS - 0.25);
+ assert_eq!(transcript.words[1].start, 6.0 * FRAME_SECONDS - 0.25);
+ assert_eq!(transcript.words[1].end, 7.0 * FRAME_SECONDS + 0.05 - 0.25);
+ let trailing = render(&emissions[..2], &vocabulary);
+ assert_eq!(trailing.text, "Hello");
+ assert_eq!(trailing.words.len(), 1);
+ assert_eq!(trailing.words[0].end, 5.0 * FRAME_SECONDS - 0.25);
+ let vocabulary = vec!["▁Hello".into(), "▁".into(), "δΈ–η•Œ".into(), "!".into()];
+ let continuation = render(&emissions, &vocabulary);
+ assert_eq!(continuation.text, "Hello δΈ–η•Œ!");
+ assert_eq!(continuation.words.len(), 1);
+ assert_eq!(continuation.words[0].text, "HelloδΈ–η•Œ!");
+ assert_eq!(continuation.words[0].end, 7.0 * FRAME_SECONDS + 0.05 - 0.25);
+ }
+}
diff --git a/rust/crates/ensu/src/transcription/parity.rs b/rust/crates/ensu/src/transcription/parity.rs
new file mode 100644
index 0000000000..05d8b8b4de
--- /dev/null
+++ b/rust/crates/ensu/src/transcription/parity.rs
@@ -0,0 +1,195 @@
+use super::*;
+
+use std::collections::BTreeMap;
+
+#[derive(serde::Deserialize)]
+struct ExpectedWord {
+ text: String,
+ start: f32,
+ end: f32,
+}
+#[derive(serde::Deserialize)]
+struct Legacy {
+ rate: u32,
+ text: String,
+ speech_samples: usize,
+ speech_sha256: String,
+}
+#[derive(serde::Deserialize)]
+struct Case {
+ file: String,
+ sha256: String,
+ samples: usize,
+ text: String,
+ words: Vec<ExpectedWord>,
+ legacy: Vec<Legacy>,
+}
+#[derive(serde::Deserialize)]
+struct Fixture {
+ models: BTreeMap<String, String>,
+ vad_sha256: String,
+ cases: Vec<Case>,
+}
+
+fn checksum(path: &Path) -> String {
+ use std::io::Read;
+ let mut file = std::fs::File::open(path).unwrap();
+ let mut hasher = ente_ensu_crypto::Sha256Hasher::new();
+ let mut buffer = vec![0; 64 * 1024];
+ loop {
+ let length = file.read(&mut buffer).unwrap();
+ if length == 0 {
+ break;
+ }
+ hasher.update(&buffer[..length]);
+ }
+ hasher
+ .finalize()
+ .iter()
+ .map(|byte| format!("{byte:02x}"))
+ .collect()
+}
+
+fn check(transcriber: &Transcriber, corpus: &Path, cases: &[Case]) {
+ for case in cases {
+ let path = corpus.join(&case.file);
+ assert_eq!(checksum(&path), case.sha256, "{} input", case.file);
+ let pcm = std::fs::read(path).unwrap();
+ let samples = super::super::audio::pcm16_samples(&pcm).unwrap();
+ assert_eq!(samples.len(), case.samples);
+ let result = transcriber
+ .lock()
+ .as_mut()
+ .unwrap()
+ .transcribe(&samples)
+ .unwrap();
+ assert_eq!(result.text, case.text, "{} text", case.file);
+ assert_eq!(result.words.len(), case.words.len(), "{} words", case.file);
+ for (actual, expected) in result.words.iter().zip(&case.words) {
+ assert_eq!(actual.text, expected.text, "{} word", case.file);
+ assert_eq!(
+ actual.start, expected.start,
+ "{} {} start",
+ case.file, expected.text
+ );
+ assert_eq!(
+ actual.end, expected.end,
+ "{} {} end",
+ case.file, expected.text
+ );
+ }
+ let aligned = if samples.len() <= crate::voice::MAX_WINDOW_SAMPLES {
+ transcriber.transcribe_window(&samples, || false).unwrap()
+ } else {
+ transcriber.transcribe_tail(&pcm, || false).unwrap()
+ };
+ assert_eq!(
+ aligned.len(),
+ case.words.len(),
+ "{} aligned words",
+ case.file
+ );
+ for (actual, expected) in aligned.iter().zip(&case.words) {
+ assert_eq!(actual.text, expected.text, "{} aligned text", case.file);
+ assert_eq!(
+ actual.start,
+ (expected.start.max(0.0) * 16000.0).round() as u64,
+ "{} aligned start",
+ case.file
+ );
+ assert_eq!(
+ actual.end,
+ ((expected.end.max(0.0) * 16000.0).round() as u64).min(samples.len() as u64),
+ "{} aligned end",
+ case.file
+ );
+ }
+ }
+}
+
+fn check_legacy(transcriber: &Transcriber, corpus: &Path, vad: &Path, cases: &[Case]) {
+ for case in cases {
+ let pcm = std::fs::read(corpus.join(&case.file)).unwrap();
+ let input: Vec<_> = pcm
+ .as_chunks::<2>()
+ .0
+ .iter()
+ .map(|pair| i16::from_le_bytes(*pair))
+ .collect();
+ for expected in &case.legacy {
+ let rate = expected.rate as usize;
+ let length = input.len() * rate / 16000;
+ let bytes: Vec<_> = (0..length)
+ .flat_map(|index| input[index * 16000 / rate].to_le_bytes())
+ .collect();
+ let speech =
+ super::super::audio::extract_speech_from_pcm16(vad, expected.rate, &bytes).unwrap();
+ assert_eq!(
+ speech.len(),
+ expected.speech_samples,
+ "{} {} Hz speech",
+ case.file,
+ rate
+ );
+ let floats: Vec<_> = speech
+ .iter()
+ .flat_map(|sample| sample.to_le_bytes())
+ .collect();
+ let hash: String = ente_ensu_crypto::sha256(&floats)
+ .iter()
+ .map(|byte| format!("{byte:02x}"))
+ .collect();
+ assert_eq!(
+ hash, expected.speech_sha256,
+ "{} {} Hz samples",
+ case.file, rate
+ );
+ assert_eq!(
+ transcriber.transcribe(expected.rate, &bytes).unwrap(),
+ expected.text,
+ "{} {} Hz text",
+ case.file,
+ rate
+ );
+ }
+ }
+}
+
+#[test]
+#[ignore = "requires ENSU_TEST_TRANSCRIPTION_MODEL, ENSU_TEST_TRANSCRIPTION_CORPUS and ENSU_TEST_VAD_MODEL"]
+fn real_model_text_and_word_timestamps_match_reference() {
+ let fixture: Fixture =
+ serde_json::from_str(include_str!("../../tests/data/parakeet-parity.json")).unwrap();
+ let model_dir = PathBuf::from(std::env::var("ENSU_TEST_TRANSCRIPTION_MODEL").unwrap());
+ let corpus = PathBuf::from(std::env::var("ENSU_TEST_TRANSCRIPTION_CORPUS").unwrap());
+ for (name, expected) in &fixture.models {
+ assert_eq!(checksum(&model_dir.join(name)), *expected, "{name} model");
+ }
+ let vad = PathBuf::from(std::env::var("ENSU_TEST_VAD_MODEL").unwrap());
+ assert_eq!(checksum(&vad), fixture.vad_sha256, "Silero model");
+ let transcriber = Transcriber::new(&model_dir, &vad);
+ transcriber.load_model().unwrap();
+ check(&transcriber, &corpus, &fixture.cases);
+ check_legacy(&transcriber, &corpus, &vad, &fixture.cases);
+ transcriber.unload_model();
+
+ let directory = tempfile::tempdir().unwrap();
+ let cache = GraphCache::new(directory.path().to_path_buf(), "test-device".into());
+ for cached in [false, true] {
+ let model = cache
+ .load(&model_dir, ort::info(), true, |plan| {
+ match &plan {
+ LoadPlan::Source { save_to } => {
+ assert!(!cached);
+ assert!(save_to.is_some());
+ }
+ LoadPlan::Cached { .. } => assert!(cached),
+ }
+ load_plan(&model_dir, plan)
+ })
+ .unwrap();
+ *transcriber.lock() = Some(model);
+ check(&transcriber, &corpus, &fixture.cases);
+ transcriber.unload_model();
+ }
+}
diff --git a/rust/crates/ensu/src/transcription/recorded.rs b/rust/crates/ensu/src/transcription/recorded.rs
index d076e2f51a..ac57abf4bf 100644
--- a/rust/crates/ensu/src/transcription/recorded.rs
+++ b/rust/crates/ensu/src/transcription/recorded.rs
@@ -1,7 +1,7 @@
use std::ops::Range;
use std::time::Duration;
-use transcribe_rs::vad::Vad;
+use super::vad::Vad;
use super::{LiveControl, LiveEvent, LiveTranscription, StreamNormalizer, Transcriber};
use crate::voice::{AlignedWord, RecognitionUpdate, Result, TranscriptBoundary, VoiceError};
@@ -291,9 +291,9 @@ impl LiveTranscription {
#[cfg(test)]
mod tests {
+ use super::super::vad::EnergyVad;
use super::*;
use crate::voice::CaptureFormat;
- use transcribe_rs::vad::EnergyVad;
#[test]
fn recorded_decoding_bounds_windows_preserves_tails_and_stops_on_cancel() {
diff --git a/rust/crates/ensu/src/transcription/transcriber.rs b/rust/crates/ensu/src/transcription/transcriber.rs
index 2c7329ec33..06d553102a 100644
--- a/rust/crates/ensu/src/transcription/transcriber.rs
+++ b/rust/crates/ensu/src/transcription/transcriber.rs
@@ -1,23 +1,21 @@
use std::path::{Path, PathBuf};
use std::sync::{Mutex, MutexGuard, PoisonError};
-use transcribe_rs::onnx::Quantization;
-use transcribe_rs::onnx::parakeet::{ParakeetModel, ParakeetParams, TimestampGranularity};
-use transcribe_rs::{OrtAccelerator, TranscriptionResult, get_ort_accelerator};
-
use super::graph_cache::{GRAPHS, GraphCache, LoadPlan, SOURCES};
+use super::parakeet::{Parakeet, Transcript};
+use super::vad::Vad;
use crate::transcription::audio::extract_speech_from_pcm16;
use crate::transcription::{Result, TranscriptionError};
pub struct Transcriber {
model_dir: PathBuf,
vad_model_path: PathBuf,
- loaded: Mutex<Option<ParakeetModel>>,
+ loaded: Mutex<Option<Parakeet>>,
graph_cache: Option<GraphCache>,
}
impl Transcriber {
- pub(crate) fn live_vad(&self) -> crate::voice::Result<Box<dyn transcribe_rs::vad::Vad>> {
+ pub(crate) fn live_vad(&self) -> crate::voice::Result<Box<dyn Vad>> {
let metadata = std::fs::metadata(&self.vad_model_path).map_err(|error| {
if error.kind() == std::io::ErrorKind::NotFound {
crate::voice::VoiceError::VadNotDownloaded
@@ -29,7 +27,7 @@ impl Transcriber {
return Err(crate::voice::VoiceError::VadNotDownloaded);
}
super::SileroV4Vad::new(&self.vad_model_path, 0.3)
- .map(|vad| Box::new(vad) as Box<dyn transcribe_rs::vad::Vad>)
+ .map(|vad| Box::new(vad) as Box<dyn Vad>)
.map_err(|error| super::voice_error("Load voice activity model", error))
}
@@ -120,13 +118,7 @@ impl Transcriber {
self.graph_cache.as_ref(),
true,
)?;
- let result = model.transcribe_with(
- &speech,
- &ParakeetParams {
- timestamp_granularity: Some(TimestampGranularity::Segment),
- ..Default::default()
- },
- )?;
+ let result = model.transcribe(&speech)?;
Ok(super::text::filter_transcription_output(&result.text))
}
@@ -161,24 +153,20 @@ impl Transcriber {
aligned_words(result, samples.len())
}
- fn lock(&self) -> MutexGuard<'_, Option<ParakeetModel>> {
+ fn lock(&self) -> MutexGuard<'_, Option<Parakeet>> {
self.loaded.lock().unwrap_or_else(PoisonError::into_inner)
}
}
fn decode_window(
- model: &mut ParakeetModel,
+ model: &mut Parakeet,
samples: &[f32],
is_cancelled: &mut impl FnMut() -> bool,
-) -> Result<Option<TranscriptionResult>> {
+) -> Result<Option<Transcript>> {
if is_cancelled() {
return Ok(None);
}
- let params = ParakeetParams {
- timestamp_granularity: Some(TimestampGranularity::Word),
- ..Default::default()
- };
- let mut result = model.transcribe_with(samples, &params)?;
+ let mut result = model.transcribe(samples)?;
if is_cancelled() {
return Ok(None);
}
@@ -192,19 +180,18 @@ fn decode_window(
let mut padded = Vec::with_capacity(samples.len() + padding);
padded.extend_from_slice(samples);
padded.resize(samples.len() + padding, 0.0);
- result = model.transcribe_with(&padded, &params)?;
+ result = model.transcribe(&padded)?;
}
Ok((!is_cancelled()).then_some(result))
}
fn aligned_words(
- result: TranscriptionResult,
+ result: Transcript,
samples: usize,
) -> crate::voice::Result<Vec<crate::voice::AlignedWord>> {
use crate::voice::{AlignedWord, VoiceError};
result
- .segments
- .ok_or(VoiceError::UnstableTranscript)?
+ .words
.into_iter()
.map(|word| {
if !word.start.is_finite()
@@ -224,11 +211,11 @@ fn aligned_words(
}
fn ensure_loaded<'a>(
- loaded: &'a mut Option<ParakeetModel>,
+ loaded: &'a mut Option<Parakeet>,
model_dir: &Path,
cache: Option<&GraphCache>,
may_build: bool,
-) -> Result<&'a mut ParakeetModel> {
+) -> Result<&'a mut Parakeet> {
match loaded {
Some(model) => Ok(model),
slot => {
@@ -237,10 +224,6 @@ fn ensure_loaded<'a>(
return Err(TranscriptionError::NotDownloaded);
}
}
- let cache = cache.filter(|_| {
- get_ort_accelerator() == OrtAccelerator::CpuOnly
- || OrtAccelerator::available() == [OrtAccelerator::CpuOnly]
- });
let result = if let Some(cache) = cache {
let configuration = format!(
"{};cpu;parallel=true;intra=auto;threads={}",
@@ -260,7 +243,7 @@ fn ensure_loaded<'a>(
}
}
-fn load_plan(model_dir: &Path, plan: LoadPlan<'_>) -> Result<ParakeetModel> {
+fn load_plan(model_dir: &Path, plan: LoadPlan<'_>) -> Result<Parakeet> {
use ort::session::builder::GraphOptimizationLevel;
let directory = match plan {
LoadPlan::Source { save_to: None } => model_dir,
@@ -280,7 +263,7 @@ fn load_plan(model_dir: &Path, plan: LoadPlan<'_>) -> Result<ParakeetModel> {
directory
}
};
- Ok(ParakeetModel::load(directory, &Quantization::Int8)?)
+ Parakeet::load(directory)
}
#[cfg(test)]
@@ -304,32 +287,8 @@ mod tests {
Err(TranscriptionError::NotDownloaded)
));
}
-
- #[test]
- #[ignore = "requires ENSU_TEST_TRANSCRIPTION_MODEL"]
- fn quantized_model_loads_from_source_and_cached_graphs() {
- let model_dir = PathBuf::from(std::env::var("ENSU_TEST_TRANSCRIPTION_MODEL").unwrap());
- let transcriber = Transcriber::new(&model_dir, model_dir.join("vad.onnx"));
- transcriber.load_model().unwrap();
- assert!(transcriber.lock().is_some());
- transcriber.unload_model();
-
- let directory = tempfile::tempdir().unwrap();
- let cache = GraphCache::new(directory.path().to_path_buf(), "test-device".into());
- for cached in [false, true] {
- let model = cache
- .load(&model_dir, ort::info(), true, |plan| {
- match &plan {
- LoadPlan::Source { save_to } => {
- assert!(!cached);
- assert!(save_to.is_some());
- }
- LoadPlan::Cached { .. } => assert!(cached),
- }
- load_plan(&model_dir, plan)
- })
- .unwrap();
- drop(model);
- }
- }
}
+
+#[cfg(test)]
+#[path = "parity.rs"]
+mod parity;
diff --git a/rust/crates/ensu/src/transcription/vad.rs b/rust/crates/ensu/src/transcription/vad.rs
index b1beb87037..b0b8b8de19 100644
--- a/rust/crates/ensu/src/transcription/vad.rs
+++ b/rust/crates/ensu/src/transcription/vad.rs
@@ -3,8 +3,122 @@ use ort::{
session::{Session, builder::GraphOptimizationLevel},
value::TensorRef,
};
-use std::path::Path;
-use transcribe_rs::{TranscribeError, vad::Vad};
+use std::{collections::VecDeque, path::Path};
+
+use super::{Result, TranscriptionError};
+
+pub(crate) trait Vad: Send {
+ fn frame_size(&self) -> usize;
+ fn is_speech(&mut self, frame: &[f32]) -> Result<bool>;
+ fn reset(&mut self);
+ fn drain_prefill(&mut self) -> Vec<f32> {
+ Vec::new()
+ }
+}
+
+pub(super) struct SpeechGate {
+ detector: Box<dyn Vad>,
+ history: VecDeque<Vec<f32>>,
+ pending_prefill: Vec<f32>,
+ prefill_frames: usize,
+ hangover_frames: usize,
+ onset_frames: usize,
+ consecutive_speech: usize,
+ remaining_hangover: usize,
+ active: bool,
+}
+
+impl SpeechGate {
+ pub fn new(detector: Box<dyn Vad>, prefill: usize, hangover: usize, onset: usize) -> Self {
+ Self {
+ detector,
+ history: VecDeque::new(),
+ pending_prefill: Vec::new(),
+ prefill_frames: prefill,
+ hangover_frames: hangover,
+ onset_frames: onset,
+ consecutive_speech: 0,
+ remaining_hangover: 0,
+ active: false,
+ }
+ }
+}
+
+impl Vad for SpeechGate {
+ fn frame_size(&self) -> usize {
+ self.detector.frame_size()
+ }
+
+ fn is_speech(&mut self, frame: &[f32]) -> Result<bool> {
+ let was_active = self.active;
+ let voiced = if self.detector.is_speech(frame)? {
+ self.consecutive_speech += 1;
+ if self.active || self.consecutive_speech >= self.onset_frames {
+ self.active = true;
+ self.remaining_hangover = self.hangover_frames;
+ }
+ self.active
+ } else {
+ self.consecutive_speech = 0;
+ if self.remaining_hangover > 0 {
+ self.remaining_hangover -= 1;
+ true
+ } else {
+ self.active = false;
+ false
+ }
+ };
+ if !was_active && self.active {
+ self.pending_prefill = self.history.iter().flatten().copied().collect();
+ }
+ self.history.push_back(frame.to_vec());
+ while self.history.len() > self.prefill_frames {
+ self.history.pop_front();
+ }
+ Ok(voiced)
+ }
+
+ fn reset(&mut self) {
+ self.detector.reset();
+ self.history.clear();
+ self.pending_prefill.clear();
+ self.consecutive_speech = 0;
+ self.remaining_hangover = 0;
+ self.active = false;
+ }
+
+ fn drain_prefill(&mut self) -> Vec<f32> {
+ std::mem::take(&mut self.pending_prefill)
+ }
+}
+
+#[cfg(test)]
+pub(super) struct EnergyVad {
+ frame_samples: usize,
+ threshold: f32,
+}
+
+#[cfg(test)]
+impl EnergyVad {
+ pub fn new(frame_samples: usize, threshold: f32) -> Self {
+ Self {
+ frame_samples,
+ threshold,
+ }
+ }
+}
+
+#[cfg(test)]
+impl Vad for EnergyVad {
+ fn frame_size(&self) -> usize {
+ self.frame_samples
+ }
+ fn is_speech(&mut self, frame: &[f32]) -> Result<bool> {
+ Ok(frame.iter().map(|v| v * v).sum::<f32>()
+ > self.threshold * self.threshold * frame.len() as f32)
+ }
+ fn reset(&mut self) {}
+}
pub(super) const SILERO_V4_FRAME_SAMPLES: usize = 512;
@@ -15,12 +129,12 @@ pub(crate) struct SileroV4Vad {
threshold: f32,
}
-fn inference(error: impl std::fmt::Display) -> TranscribeError {
- TranscribeError::Inference(format!("Silero v4: {error}"))
+fn inference(error: impl std::fmt::Display) -> TranscriptionError {
+ TranscriptionError::Transcribe(format!("inference error: Silero v4: {error}"))
}
impl SileroV4Vad {
- pub fn new(path: impl AsRef<Path>, threshold: f32) -> Result<Self, TranscribeError> {
+ pub fn new(path: impl AsRef<Path>, threshold: f32) -> Result<Self> {
let session = Session::builder()
.map_err(inference)?
.with_optimization_level(GraphOptimizationLevel::Level3)
@@ -39,7 +153,7 @@ impl SileroV4Vad {
})
}
- fn speech_probability(&mut self, frame: &[f32]) -> Result<f32, TranscribeError> {
+ fn speech_probability(&mut self, frame: &[f32]) -> Result<f32> {
validate_frame(frame)?;
let sample_rate = [16000_i64];
let outputs = self.session.run(inputs![
@@ -85,9 +199,9 @@ impl SileroV4Vad {
}
}
-fn validate_frame(frame: &[f32]) -> Result<(), TranscribeError> {
+fn validate_frame(frame: &[f32]) -> Result<()> {
if frame.len() != SILERO_V4_FRAME_SAMPLES || frame.iter().any(|s| !s.is_finite()) {
- return Err(TranscribeError::Audio(
+ return Err(TranscriptionError::InvalidAudio(
"Silero v4 requires 512 finite samples at 16 kHz".into(),
));
}
@@ -98,7 +212,7 @@ impl Vad for SileroV4Vad {
fn frame_size(&self) -> usize {
SILERO_V4_FRAME_SAMPLES
}
- fn is_speech(&mut self, frame: &[f32]) -> Result<bool, TranscribeError> {
+ fn is_speech(&mut self, frame: &[f32]) -> Result<bool> {
Ok(self.speech_probability(frame)? > self.threshold)
}
fn reset(&mut self) {
@@ -106,3 +220,86 @@ impl Vad for SileroV4Vad {
self.cell.fill(0.0);
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ struct Scripted(VecDeque<bool>);
+
+ impl Vad for Scripted {
+ fn frame_size(&self) -> usize {
+ 4
+ }
+ fn is_speech(&mut self, _: &[f32]) -> Result<bool> {
+ Ok(self.0.pop_front().unwrap())
+ }
+ fn reset(&mut self) {}
+ }
+
+ #[test]
+ fn speech_gate_preserves_onset_prefill_and_hangover() {
+ for (pattern, expected, onset, prefill) in [
+ ("000000", "000000", None, vec![]),
+ ("100000", "000000", None, vec![]),
+ ("110000", "011100", Some(1), vec![0]),
+ ("00110000", "00011100", Some(3), vec![0, 1, 2]),
+ ("001010110000", "000000011100", Some(7), vec![4, 5, 6]),
+ ("011100110000", "001111111100", Some(2), vec![0, 1]),
+ ("111111", "011111", Some(1), vec![0]),
+ ] {
+ let detector = Scripted(pattern.bytes().map(|value| value == b'1').collect());
+ let mut gate = SpeechGate::new(Box::new(detector), 3, 2, 2);
+ let mut actual = String::new();
+ for index in 0..pattern.len() {
+ let voiced = gate.is_speech(&[index as f32; 4]).unwrap();
+ actual.push(if voiced { '1' } else { '0' });
+ if voiced {
+ let wanted: Vec<f32> = if Some(index) == onset {
+ prefill.iter().flat_map(|&v| [v as f32; 4]).collect()
+ } else {
+ Vec::new()
+ };
+ assert_eq!(gate.drain_prefill(), wanted, "{pattern}: frame {index}");
+ }
+ }
+ assert_eq!(actual, expected, "{pattern}");
+ gate.reset();
+ assert!(gate.drain_prefill().is_empty());
+ assert!(!gate.active);
+ assert_eq!(gate.remaining_hangover, 0);
+ assert_eq!(gate.consecutive_speech, 0);
+ }
+ }
+
+ #[test]
+ fn silero_frames_require_finite_samples_at_the_expected_length() {
+ assert!(validate_frame(&[0.0; SILERO_V4_FRAME_SAMPLES]).is_ok());
+ assert!(validate_frame(&[]).is_err());
+ assert!(validate_frame(&[0.0; SILERO_V4_FRAME_SAMPLES - 1]).is_err());
+ assert!(validate_frame(&[f32::NAN; SILERO_V4_FRAME_SAMPLES]).is_err());
+ assert!(validate_frame(&[f32::INFINITY; SILERO_V4_FRAME_SAMPLES]).is_err());
+ }
+
+ #[test]
+ fn speech_reentry_keeps_the_full_prefill_history_after_hangover() {
+ for gap in 11..=14 {
+ let pattern = [vec![true; 2], vec![false; gap], vec![true; 2]].concat();
+ let mut gate = SpeechGate::new(Box::new(Scripted(pattern.into())), 3, 10, 2);
+ for index in 0..gap + 4 {
+ let voiced = gate.is_speech(&[index as f32; 4]).unwrap();
+ assert_eq!(voiced, (1..=11).contains(&index) || index == gap + 3);
+ if voiced {
+ let expected = if index == 1 {
+ vec![0.0; 4]
+ } else if index == gap + 3 {
+ (index - 3..index).flat_map(|i| [i as f32; 4]).collect()
+ } else {
+ Vec::new()
+ };
+ assert_eq!(gate.drain_prefill(), expected, "gap {gap}, frame {index}");
+ }
+ }
+ }
+ }
+}
diff --git a/rust/crates/ensu/tests/data/parakeet-parity.json b/rust/crates/ensu/tests/data/parakeet-parity.json
new file mode 100644
index 0000000000..c0d432649d
--- /dev/null
+++ b/rust/crates/ensu/tests/data/parakeet-parity.json
@@ -0,0 +1,1156 @@
+{
+ "reference_revision": "efc66111d519a434e28d51d94740008a7ce29360",
+ "runtime": "ort 2.0.0-rc.13 default CPU runtime; ORT Build Info: git-branch=rel-1.28.0, git-commit-id=da9b5e3, fp8-kv-cache=1, build type=Release",
+ "model_archive_sha256": "43d37191602727524a7d8c6da0eef11c4ba24320f5b4730f1a2497befc2efa77",
+ "models": {
+ "encoder-model.int8.onnx": "6139d2fa7e1b086097b277c7149725edbab89cc7c7ae64b23c741be4055aff09",
+ "nemo128.onnx": "a9fde1486ebfcc08f328d75ad4610c67835fea58c73ba57e3209a6f6cf019e9f",
+ "decoder_joint-model.int8.onnx": "eea7483ee3d1a30375daedc8ed83e3960c91b098812127a0d99d1c8977667a70",
+ "vocab.txt": "d58544679ea4bc6ac563d1f545eb7d474bd6cfa467f0a6e2c1dc1c7d37e3c35d"
+ },
+ "cases": [
+ {
+ "file": "jfk_full.pcm",
+ "samples": 176000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you. Ask what you can do for your country.",
+ "words": [
+ {
+ "end": 0.4699999690055847,
+ "start": 0.1499999761581421,
+ "text": "And"
+ },
+ {
+ "end": 0.9499999284744263,
+ "start": 0.4699999690055847,
+ "text": "so,"
+ },
+ {
+ "end": 1.1899999380111694,
+ "start": 0.9499999284744263,
+ "text": "my"
+ },
+ {
+ "end": 1.6699999570846558,
+ "start": 1.1899999380111694,
+ "text": "fellow"
+ },
+ {
+ "end": 3.2699999809265137,
+ "start": 1.6699999570846558,
+ "text": "Americans,"
+ },
+ {
+ "end": 3.989999771118164,
+ "start": 3.2699999809265137,
+ "text": "ask"
+ },
+ {
+ "end": 5.190000057220459,
+ "start": 3.989999771118164,
+ "text": "not"
+ },
+ {
+ "end": 5.589999675750732,
+ "start": 5.190000057220459,
+ "text": "what"
+ },
+ {
+ "end": 5.909999847412109,
+ "start": 5.589999675750732,
+ "text": "your"
+ },
+ {
+ "end": 6.46999979019165,
+ "start": 5.909999847412109,
+ "text": "country"
+ },
+ {
+ "end": 6.710000038146973,
+ "start": 6.46999979019165,
+ "text": "can"
+ },
+ {
+ "end": 6.949999809265137,
+ "start": 6.710000038146973,
+ "text": "do"
+ },
+ {
+ "end": 7.269999980926514,
+ "start": 6.949999809265137,
+ "text": "for"
+ },
+ {
+ "end": 8.069999694824219,
+ "start": 7.269999980926514,
+ "text": "you."
+ },
+ {
+ "end": 8.630000114440918,
+ "start": 8.069999694824219,
+ "text": "Ask"
+ },
+ {
+ "end": 8.869999885559082,
+ "start": 8.630000114440918,
+ "text": "what"
+ },
+ {
+ "end": 9.1899995803833,
+ "start": 8.869999885559082,
+ "text": "you"
+ },
+ {
+ "end": 9.429999351501465,
+ "start": 9.1899995803833,
+ "text": "can"
+ },
+ {
+ "end": 9.670000076293945,
+ "start": 9.429999351501465,
+ "text": "do"
+ },
+ {
+ "end": 9.829999923706055,
+ "start": 9.670000076293945,
+ "text": "for"
+ },
+ {
+ "end": 10.069999694824219,
+ "start": 9.829999923706055,
+ "text": "your"
+ },
+ {
+ "end": 10.600000381469727,
+ "start": 10.069999694824219,
+ "text": "country."
+ }
+ ],
+ "sha256": "a29462b8ebd467318000e683b9117ade46230d3255ed2024e7db894abd9b38c9",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you. Ask what you can do for your country.",
+ "speech_samples": 143360,
+ "speech_sha256": "8564ae4ff7e28edc2178d7c7ea175c59ea5f8cce83483cc27ff2eeb35a20d2fd"
+ },
+ {
+ "rate": 44100,
+ "text": "And so, my fellow Americans, ask not what your country can do for you. Ask what you can do for your country.",
+ "speech_samples": 142848,
+ "speech_sha256": "93e1734f8ec94bdd0da7146ec255a8c3834ca1eda0a1ff9efd767c21dedabb41"
+ },
+ {
+ "rate": 48000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you, ask what you can do for your country.",
+ "speech_samples": 145920,
+ "speech_sha256": "d1873c5fcff8e6ca7206b3ce1aa0bce4f2e685b83fe20544765de93820657718"
+ }
+ ]
+ },
+ {
+ "file": "jfk_opening.pcm",
+ "samples": 128000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you.",
+ "words": [
+ {
+ "end": 0.4699999690055847,
+ "start": 0.1499999761581421,
+ "text": "And"
+ },
+ {
+ "end": 0.9499999284744263,
+ "start": 0.4699999690055847,
+ "text": "so,"
+ },
+ {
+ "end": 1.1899999380111694,
+ "start": 0.9499999284744263,
+ "text": "my"
+ },
+ {
+ "end": 1.6699999570846558,
+ "start": 1.1899999380111694,
+ "text": "fellow"
+ },
+ {
+ "end": 3.18999981880188,
+ "start": 1.6699999570846558,
+ "text": "Americans,"
+ },
+ {
+ "end": 3.9099998474121094,
+ "start": 3.18999981880188,
+ "text": "ask"
+ },
+ {
+ "end": 5.109999656677246,
+ "start": 3.9099998474121094,
+ "text": "not"
+ },
+ {
+ "end": 5.589999675750732,
+ "start": 5.109999656677246,
+ "text": "what"
+ },
+ {
+ "end": 5.909999847412109,
+ "start": 5.589999675750732,
+ "text": "your"
+ },
+ {
+ "end": 6.389999866485596,
+ "start": 5.909999847412109,
+ "text": "country"
+ },
+ {
+ "end": 6.710000038146973,
+ "start": 6.389999866485596,
+ "text": "can"
+ },
+ {
+ "end": 6.949999809265137,
+ "start": 6.710000038146973,
+ "text": "do"
+ },
+ {
+ "end": 7.269999980926514,
+ "start": 6.949999809265137,
+ "text": "for"
+ },
+ {
+ "end": 7.880000114440918,
+ "start": 7.269999980926514,
+ "text": "you."
+ }
+ ],
+ "sha256": "176ee248c76689839883ff3c14efb8e5486d13f4fed81f2e1a2f369e71f7a157",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you.",
+ "speech_samples": 101376,
+ "speech_sha256": "ab5e1d6b804c479d262136235b4530e52d177f18ff27d2a8c74f9b676b5d2a69"
+ },
+ {
+ "rate": 44100,
+ "text": "And so, my fellow Americans, ask not what your country can do for you.",
+ "speech_samples": 99328,
+ "speech_sha256": "03d9d42e603a14b6b0e6ce5f6fa174910ae4e18f85c4e124bc9ec20b3d3f86c2"
+ },
+ {
+ "rate": 48000,
+ "text": "And so, my fellow Americans, ask not what your country can do for you.",
+ "speech_samples": 99840,
+ "speech_sha256": "4e24048292cd893cded09587e1687cbc50ddf546ee588e41da2dcf487b0056e2"
+ }
+ ]
+ },
+ {
+ "file": "jfk_overlap.pcm",
+ "samples": 112000,
+ "text": "Not what your country can do for you. Ask what you can do for your country.",
+ "words": [
+ {
+ "end": 1.1899999380111694,
+ "start": 0.1499999761581421,
+ "text": "Not"
+ },
+ {
+ "end": 1.5899999141693115,
+ "start": 1.1899999380111694,
+ "text": "what"
+ },
+ {
+ "end": 1.9099998474121094,
+ "start": 1.5899999141693115,
+ "text": "your"
+ },
+ {
+ "end": 2.4700000286102295,
+ "start": 1.9099998474121094,
+ "text": "country"
+ },
+ {
+ "end": 2.7100000381469727,
+ "start": 2.4700000286102295,
+ "text": "can"
+ },
+ {
+ "end": 2.9499998092651367,
+ "start": 2.7100000381469727,
+ "text": "do"
+ },
+ {
+ "end": 3.18999981880188,
+ "start": 2.9499998092651367,
+ "text": "for"
+ },
+ {
+ "end": 4.069999694824219,
+ "start": 3.18999981880188,
+ "text": "you."
+ },
+ {
+ "end": 4.630000114440918,
+ "start": 4.069999694824219,
+ "text": "Ask"
+ },
+ {
+ "end": 4.949999809265137,
+ "start": 4.630000114440918,
+ "text": "what"
+ },
+ {
+ "end": 5.190000057220459,
+ "start": 4.949999809265137,
+ "text": "you"
+ },
+ {
+ "end": 5.429999828338623,
+ "start": 5.190000057220459,
+ "text": "can"
+ },
+ {
+ "end": 5.670000076293945,
+ "start": 5.429999828338623,
+ "text": "do"
+ },
+ {
+ "end": 5.829999923706055,
+ "start": 5.670000076293945,
+ "text": "for"
+ },
+ {
+ "end": 6.069999694824219,
+ "start": 5.829999923706055,
+ "text": "your"
+ },
+ {
+ "end": 6.519999980926514,
+ "start": 6.069999694824219,
+ "text": "country."
+ }
+ ],
+ "sha256": "e4bf4775256f924dc949a830782d9f29406e67ae712fb4723e550ce9945a809f",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "What your country can do for you Ask what you can do for your country",
+ "speech_samples": 82944,
+ "speech_sha256": "c084c87d1c87b88ef33cc9a1ae1accfb8bf652a3793f580fa3d7b529c1dea17c"
+ },
+ {
+ "rate": 44100,
+ "text": "Not what your country can do for you. Ask what you can do for your country.",
+ "speech_samples": 96768,
+ "speech_sha256": "49096f2469baf644b132ab26180eb0dae13df85e4584aaaf721dcc43c7e454d6"
+ },
+ {
+ "rate": 48000,
+ "text": "What your country can do for you, ask what you can do for your country.",
+ "speech_samples": 86528,
+ "speech_sha256": "fce7d69357fa1085684e658fb17aac00294b8409abc0fd7c8af74c09c9996b74"
+ }
+ ]
+ },
+ {
+ "file": "jfk_padded.pcm",
+ "samples": 96000,
+ "text": "And so, my fellow Americans, ask not.",
+ "words": [
+ {
+ "end": 0.9499999284744263,
+ "start": 0.5499999523162842,
+ "text": "And"
+ },
+ {
+ "end": 1.4299999475479126,
+ "start": 0.9499999284744263,
+ "text": "so,"
+ },
+ {
+ "end": 1.6699999570846558,
+ "start": 1.4299999475479126,
+ "text": "my"
+ },
+ {
+ "end": 2.1499998569488525,
+ "start": 1.6699999570846558,
+ "text": "fellow"
+ },
+ {
+ "end": 3.75,
+ "start": 2.1499998569488525,
+ "text": "Americans,"
+ },
+ {
+ "end": 4.389999866485596,
+ "start": 3.75,
+ "text": "ask"
+ },
+ {
+ "end": 5.880000114440918,
+ "start": 4.389999866485596,
+ "text": "not."
+ }
+ ],
+ "sha256": "333faaee030c07153fa5fa5bde4a5cd714092398bf4bd3facb503f4876693c55",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "And so, my fellow Americans, ask not",
+ "speech_samples": 59904,
+ "speech_sha256": "0d20774db54dd7f0c4e73b47dbc59c23660219eb39be5525b85f2dd1da99936b"
+ },
+ {
+ "rate": 44100,
+ "text": "And so, my fellow Americans, ask not!",
+ "speech_samples": 58880,
+ "speech_sha256": "4501808119c0f1b1831c18187a0269d0224fa3f08d723b1839bdd8ce248ccbb9"
+ },
+ {
+ "rate": 48000,
+ "text": "And so, my fellow Americans, ask not",
+ "speech_samples": 57344,
+ "speech_sha256": "a50ece230bd6caf3416edb8b32bda53af3bc1324bfa24ddb01f484262abb7ae4"
+ }
+ ]
+ },
+ {
+ "file": "jfk_short.pcm",
+ "samples": 12800,
+ "text": "And so",
+ "words": [
+ {
+ "end": 0.3100000023841858,
+ "start": 0.1499999761581421,
+ "text": "And"
+ },
+ {
+ "end": 0.36000001430511475,
+ "start": 0.3100000023841858,
+ "text": "so"
+ }
+ ],
+ "sha256": "a9bedfe56d9a24cc86b37e91ee91fe74999fbadb7ff07f530f77a65dedf26c28",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "And so.",
+ "speech_samples": 20000,
+ "speech_sha256": "a6e0f73e4f88f3369b2153a9f5e7513f7be47719107f1e17bee1fa3db2699fda"
+ },
+ {
+ "rate": 44100,
+ "text": "And so",
+ "speech_samples": 20000,
+ "speech_sha256": "1b4c106c50d994f02c0a4f2921779ab34afe843aeec2333774671cbaca578148"
+ },
+ {
+ "rate": 48000,
+ "text": "",
+ "speech_samples": 20000,
+ "speech_sha256": "3a1541bcdb107e3b9b309a97520981743c55dc81455d1581f8be3dcbe16fdca8"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-128104-0000.pcm",
+ "samples": 93680,
+ "text": "mister Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.",
+ "words": [
+ {
+ "end": 0.6299999952316284,
+ "start": 0.1499999761581421,
+ "text": "mister"
+ },
+ {
+ "end": 1.3499999046325684,
+ "start": 0.6299999952316284,
+ "text": "Quilter"
+ },
+ {
+ "end": 1.5099999904632568,
+ "start": 1.3499999046325684,
+ "text": "is"
+ },
+ {
+ "end": 1.5899999141693115,
+ "start": 1.5099999904632568,
+ "text": "the"
+ },
+ {
+ "end": 2.1499998569488525,
+ "start": 1.5899999141693115,
+ "text": "apostle"
+ },
+ {
+ "end": 2.2300000190734863,
+ "start": 2.1499998569488525,
+ "text": "of"
+ },
+ {
+ "end": 2.3899998664855957,
+ "start": 2.2300000190734863,
+ "text": "the"
+ },
+ {
+ "end": 2.7100000381469727,
+ "start": 2.3899998664855957,
+ "text": "middle"
+ },
+ {
+ "end": 3.2699999809265137,
+ "start": 2.7100000381469727,
+ "text": "classes,"
+ },
+ {
+ "end": 3.429999828338623,
+ "start": 3.2699999809265137,
+ "text": "and"
+ },
+ {
+ "end": 3.5899999141693115,
+ "start": 3.429999828338623,
+ "text": "we"
+ },
+ {
+ "end": 3.75,
+ "start": 3.5899999141693115,
+ "text": "are"
+ },
+ {
+ "end": 4.069999694824219,
+ "start": 3.75,
+ "text": "glad"
+ },
+ {
+ "end": 4.230000019073486,
+ "start": 4.069999694824219,
+ "text": "to"
+ },
+ {
+ "end": 4.630000114440918,
+ "start": 4.230000019073486,
+ "text": "welcome"
+ },
+ {
+ "end": 4.869999885559082,
+ "start": 4.630000114440918,
+ "text": "his"
+ },
+ {
+ "end": 5.639999866485596,
+ "start": 4.869999885559082,
+ "text": "gospel."
+ }
+ ],
+ "sha256": "156e1e1821700d4c4ad31a63e6d901a5088d5ee155fafd02a9d0d2de37f771e6",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "mister Quilter is the apostle of the Middle Classes, and we are glad to welcome his gospel.",
+ "speech_samples": 83456,
+ "speech_sha256": "07870c198e8c0d9ca7f1f913646b1169e09a9db5ad4e636e0b5b41e40a7e3955"
+ },
+ {
+ "rate": 44100,
+ "text": "Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.",
+ "speech_samples": 84480,
+ "speech_sha256": "1a6d6687ef01f23df4db80f5b686362adeee4a2a4a41cb843abfcdebc83afb6a"
+ },
+ {
+ "rate": 48000,
+ "text": "mister Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.",
+ "speech_samples": 83968,
+ "speech_sha256": "d5753656f90fedd32b0571e5da7a69395f35934808f7a6c9625239c93c7e2330"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-128104-0001.pcm",
+ "samples": 77040,
+ "text": "Nor is mister Quilter's manner less interesting than his matter.",
+ "words": [
+ {
+ "end": 0.6299999952316284,
+ "start": 0.22999998927116394,
+ "text": "Nor"
+ },
+ {
+ "end": 0.8700000047683716,
+ "start": 0.6299999952316284,
+ "text": "is"
+ },
+ {
+ "end": 1.1899999380111694,
+ "start": 0.8700000047683716,
+ "text": "mister"
+ },
+ {
+ "end": 1.9900000095367432,
+ "start": 1.1899999380111694,
+ "text": "Quilter's"
+ },
+ {
+ "end": 2.3899998664855957,
+ "start": 1.9900000095367432,
+ "text": "manner"
+ },
+ {
+ "end": 2.7100000381469727,
+ "start": 2.3899998664855957,
+ "text": "less"
+ },
+ {
+ "end": 3.2699999809265137,
+ "start": 2.7100000381469727,
+ "text": "interesting"
+ },
+ {
+ "end": 3.509999990463257,
+ "start": 3.2699999809265137,
+ "text": "than"
+ },
+ {
+ "end": 3.75,
+ "start": 3.509999990463257,
+ "text": "his"
+ },
+ {
+ "end": 4.680000305175781,
+ "start": 3.75,
+ "text": "matter."
+ }
+ ],
+ "sha256": "bca0b38f0be340f804ab1d522f4d2a1b339f3cb237913347d1af0847ae48160e",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "Nor is mister Quilter's manner less interesting than his matter.",
+ "speech_samples": 68096,
+ "speech_sha256": "392720d41ca4e5be5c31b135d4bb2eb5bbfbf28269d548877e31cd04ea20553d"
+ },
+ {
+ "rate": 44100,
+ "text": "Nor is Mr. Quilter's manner less interesting than his matter.",
+ "speech_samples": 67584,
+ "speech_sha256": "5f162b7f1bc5feb2f71101ea5504fc3b50f819a9c515ee20f139dd8748910ff8"
+ },
+ {
+ "rate": 48000,
+ "text": "Nor is mister Quilter's manner less interesting than his matter.",
+ "speech_samples": 67584,
+ "speech_sha256": "8c9470665e2098762e18a6e2bcd1813d34f91a63cd2c3553535162be8070e34d"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-128104-0010.pcm",
+ "samples": 89600,
+ "text": "near the fire, and the ornaments Fred brought home from India on the mantle board.",
+ "words": [
+ {
+ "end": 0.4699999690055847,
+ "start": 0.0,
+ "text": "near"
+ },
+ {
+ "end": 0.6299999952316284,
+ "start": 0.4699999690055847,
+ "text": "the"
+ },
+ {
+ "end": 1.2699999809265137,
+ "start": 0.6299999952316284,
+ "text": "fire,"
+ },
+ {
+ "end": 1.5899999141693115,
+ "start": 1.2699999809265137,
+ "text": "and"
+ },
+ {
+ "end": 1.75,
+ "start": 1.5899999141693115,
+ "text": "the"
+ },
+ {
+ "end": 2.3899998664855957,
+ "start": 1.75,
+ "text": "ornaments"
+ },
+ {
+ "end": 2.7899999618530273,
+ "start": 2.3899998664855957,
+ "text": "Fred"
+ },
+ {
+ "end": 3.109999895095825,
+ "start": 2.7899999618530273,
+ "text": "brought"
+ },
+ {
+ "end": 3.3499999046325684,
+ "start": 3.109999895095825,
+ "text": "home"
+ },
+ {
+ "end": 3.509999990463257,
+ "start": 3.3499999046325684,
+ "text": "from"
+ },
+ {
+ "end": 3.989999771118164,
+ "start": 3.509999990463257,
+ "text": "India"
+ },
+ {
+ "end": 4.150000095367432,
+ "start": 3.989999771118164,
+ "text": "on"
+ },
+ {
+ "end": 4.309999942779541,
+ "start": 4.150000095367432,
+ "text": "the"
+ },
+ {
+ "end": 4.789999961853027,
+ "start": 4.309999942779541,
+ "text": "mantle"
+ },
+ {
+ "end": 5.240000247955322,
+ "start": 4.789999961853027,
+ "text": "board."
+ }
+ ],
+ "sha256": "ae31d7a39145aa312418aed3b926efabec7c1a7a72673ffe9b798ea7bff375be",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "near the fire, and the ornaments Fred brought home from India on the mantle board.",
+ "speech_samples": 77824,
+ "speech_sha256": "27c6464fdab301066108c280a56c73db435430af1523926ac3471c92e15d3059"
+ },
+ {
+ "rate": 44100,
+ "text": "near the fire, and the ornaments Fred brought home from India on the mantle board.",
+ "speech_samples": 78336,
+ "speech_sha256": "fd6b4ed3b4a72daa3f5b06490cc5570df657e4be2efc2d19d8339e48d546b487"
+ },
+ {
+ "rate": 48000,
+ "text": "near the fire, and the ornaments Fred brought home from India on the mantle board.",
+ "speech_samples": 77824,
+ "speech_sha256": "a49116bb8b8d2ab8bf297cfb1ec2ef870d25e630193198f914796850fb1a517b"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-135031-0005.pcm",
+ "samples": 74000,
+ "text": "I begged Ruggedo long ago to send him away, but he would not do so.",
+ "words": [
+ {
+ "end": 0.22999998927116394,
+ "start": 0.0,
+ "text": "I"
+ },
+ {
+ "end": 0.7099999785423279,
+ "start": 0.22999998927116394,
+ "text": "begged"
+ },
+ {
+ "end": 1.5899999141693115,
+ "start": 0.7099999785423279,
+ "text": "Ruggedo"
+ },
+ {
+ "end": 1.8299999237060547,
+ "start": 1.5899999141693115,
+ "text": "long"
+ },
+ {
+ "end": 2.069999933242798,
+ "start": 1.8299999237060547,
+ "text": "ago"
+ },
+ {
+ "end": 2.2300000190734863,
+ "start": 2.069999933242798,
+ "text": "to"
+ },
+ {
+ "end": 2.4700000286102295,
+ "start": 2.2300000190734863,
+ "text": "send"
+ },
+ {
+ "end": 2.629999876022339,
+ "start": 2.4700000286102295,
+ "text": "him"
+ },
+ {
+ "end": 3.0299999713897705,
+ "start": 2.629999876022339,
+ "text": "away,"
+ },
+ {
+ "end": 3.18999981880188,
+ "start": 3.0299999713897705,
+ "text": "but"
+ },
+ {
+ "end": 3.3499999046325684,
+ "start": 3.18999981880188,
+ "text": "he"
+ },
+ {
+ "end": 3.509999990463257,
+ "start": 3.3499999046325684,
+ "text": "would"
+ },
+ {
+ "end": 3.75,
+ "start": 3.509999990463257,
+ "text": "not"
+ },
+ {
+ "end": 3.989999771118164,
+ "start": 3.75,
+ "text": "do"
+ },
+ {
+ "end": 4.440000057220459,
+ "start": 3.989999771118164,
+ "text": "so."
+ }
+ ],
+ "sha256": "519872f29413f32f001b3f3f427f60a85b76a61751caeb4de22db0d409ad4484",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "I begged Ruggado long ago to send him away, but he would not do so.",
+ "speech_samples": 68608,
+ "speech_sha256": "1447444e2cbdef0441c923c763f098878fa79b8996779741124c24f6b2739fda"
+ },
+ {
+ "rate": 44100,
+ "text": "I begged Ruggedo long ago to send him away, but he would not do so.",
+ "speech_samples": 67584,
+ "speech_sha256": "5ac798a76654e173ad207578cea9ee04b86d1159d53d3ea63cbafd08d7c11aba"
+ },
+ {
+ "rate": 48000,
+ "text": "I begged Ruggedo long ago to send him away, but he would not do so.",
+ "speech_samples": 67072,
+ "speech_sha256": "4635e40ae1159fd113f8b363841775473a843998b134510a183b0d8fc628f48f"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-141231-0000.pcm",
+ "samples": 74400,
+ "text": "A man said to the universe, Sir, I exist.",
+ "words": [
+ {
+ "end": 0.4699999690055847,
+ "start": 0.22999998927116394,
+ "text": "A"
+ },
+ {
+ "end": 0.8700000047683716,
+ "start": 0.4699999690055847,
+ "text": "man"
+ },
+ {
+ "end": 1.2699999809265137,
+ "start": 0.8700000047683716,
+ "text": "said"
+ },
+ {
+ "end": 1.4299999475479126,
+ "start": 1.2699999809265137,
+ "text": "to"
+ },
+ {
+ "end": 1.5899999141693115,
+ "start": 1.4299999475479126,
+ "text": "the"
+ },
+ {
+ "end": 2.629999876022339,
+ "start": 1.5899999141693115,
+ "text": "universe,"
+ },
+ {
+ "end": 3.3499999046325684,
+ "start": 2.629999876022339,
+ "text": "Sir,"
+ },
+ {
+ "end": 3.669999837875366,
+ "start": 3.3499999046325684,
+ "text": "I"
+ },
+ {
+ "end": 4.440000057220459,
+ "start": 3.669999837875366,
+ "text": "exist."
+ }
+ ],
+ "sha256": "f186e2e3324e58b6f20dd392b68415bc5df9c33fa72e528a145c563e4ce2f749",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "A man said to the universe, Sir, I exist.",
+ "speech_samples": 59392,
+ "speech_sha256": "890d0049e56bc2b9d4b0ea8081a11b6508bd7e697dd34535355e9d4ed382243c"
+ },
+ {
+ "rate": 44100,
+ "text": "A man said to the universe, Sir, I exist.",
+ "speech_samples": 60928,
+ "speech_sha256": "e4d03dd9b1ab812f50e50b94cea01b7e64c1b1ac5bed14f6e866a359313ec89d"
+ },
+ {
+ "rate": 48000,
+ "text": "A man said to the universe, Sir, I exist.",
+ "speech_samples": 59904,
+ "speech_sha256": "bbc86aaf9791292b51c77492771793f00ee55f58c42de776fb735c3b0ed295a9"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-141231-0020.pcm",
+ "samples": 69120,
+ "text": "Just thrust and parry and victory to the stronger.",
+ "words": [
+ {
+ "end": 0.7099999785423279,
+ "start": 0.1499999761581421,
+ "text": "Just"
+ },
+ {
+ "end": 1.2699999809265137,
+ "start": 0.7099999785423279,
+ "text": "thrust"
+ },
+ {
+ "end": 1.5099999904632568,
+ "start": 1.2699999809265137,
+ "text": "and"
+ },
+ {
+ "end": 2.2300000190734863,
+ "start": 1.5099999904632568,
+ "text": "parry"
+ },
+ {
+ "end": 2.4700000286102295,
+ "start": 2.2300000190734863,
+ "text": "and"
+ },
+ {
+ "end": 3.0299999713897705,
+ "start": 2.4700000286102295,
+ "text": "victory"
+ },
+ {
+ "end": 3.18999981880188,
+ "start": 3.0299999713897705,
+ "text": "to"
+ },
+ {
+ "end": 3.2699999809265137,
+ "start": 3.18999981880188,
+ "text": "the"
+ },
+ {
+ "end": 4.119999885559082,
+ "start": 3.2699999809265137,
+ "text": "stronger."
+ }
+ ],
+ "sha256": "7b9195c0286ecbab0447002131e3964cb0fccab8e83ca8dccf0475adc7e03ac3",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "Just thrust and parry and victory to the stronger.",
+ "speech_samples": 58368,
+ "speech_sha256": "969b46b7c5680605fdb103cae57bdb6eabf6c3335d356d39129acc257fd0a53e"
+ },
+ {
+ "rate": 44100,
+ "text": "Just thrust and parry and victory to the stronger.",
+ "speech_samples": 58368,
+ "speech_sha256": "2776a0e09cd3da5c8795290d93fe1056110ff8bdd5037035cdfa352f936f75b6"
+ },
+ {
+ "rate": 48000,
+ "text": "Just thrust and parry and victory to the stronger.",
+ "speech_samples": 57344,
+ "speech_sha256": "8f14cc6e9b2a9db0d6b8d214420d4d6560ea8e2ab80da4f1d20502ddb77bc7a9"
+ }
+ ]
+ },
+ {
+ "file": "librispeech_1272-141231-0032.pcm",
+ "samples": 71680,
+ "text": "Then the powerful twists that thrust to the side. In and under the guard,",
+ "words": [
+ {
+ "end": 0.7099999785423279,
+ "start": 0.22999998927116394,
+ "text": "Then"
+ },
+ {
+ "end": 0.8700000047683716,
+ "start": 0.7099999785423279,
+ "text": "the"
+ },
+ {
+ "end": 1.2699999809265137,
+ "start": 0.8700000047683716,
+ "text": "powerful"
+ },
+ {
+ "end": 1.6699999570846558,
+ "start": 1.2699999809265137,
+ "text": "twists"
+ },
+ {
+ "end": 1.9099998474121094,
+ "start": 1.6699999570846558,
+ "text": "that"
+ },
+ {
+ "end": 2.309999942779541,
+ "start": 1.9099998474121094,
+ "text": "thrust"
+ },
+ {
+ "end": 2.4700000286102295,
+ "start": 2.309999942779541,
+ "text": "to"
+ },
+ {
+ "end": 2.629999876022339,
+ "start": 2.4700000286102295,
+ "text": "the"
+ },
+ {
+ "end": 3.109999895095825,
+ "start": 2.629999876022339,
+ "text": "side."
+ },
+ {
+ "end": 3.3499999046325684,
+ "start": 3.109999895095825,
+ "text": "In"
+ },
+ {
+ "end": 3.509999990463257,
+ "start": 3.3499999046325684,
+ "text": "and"
+ },
+ {
+ "end": 3.669999837875366,
+ "start": 3.509999990463257,
+ "text": "under"
+ },
+ {
+ "end": 3.8299999237060547,
+ "start": 3.669999837875366,
+ "text": "the"
+ },
+ {
+ "end": 4.360000133514404,
+ "start": 3.8299999237060547,
+ "text": "guard,"
+ }
+ ],
+ "sha256": "601e5f1a2c7454c159a5c29fe903a2999ddac0d73db15f80719c0484d92a6a63",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "Then the powerful twists that thrust it aside. In and under the guard,",
+ "speech_samples": 63488,
+ "speech_sha256": "cb3f41ea6b8318198624a57e9b3af78030456e30d107e4c7bdd8d094be1079f7"
+ },
+ {
+ "rate": 44100,
+ "text": "Then the powerful twist that thrust it aside. In and under the guard.",
+ "speech_samples": 63488,
+ "speech_sha256": "d56c66adff5c2656c2898ddd9ee4347d96f8f183261c1efd9d9cb5229b11c100"
+ },
+ {
+ "rate": 48000,
+ "text": "then the powerful twists that thrust it aside. In and under the guard,",
+ "speech_samples": 63488,
+ "speech_sha256": "5d0c2a61882441567d958590fefd1fc5c5d61bf28f4699d414abf3c799a8e96b"
+ }
+ ]
+ },
+ {
+ "file": "silence.pcm",
+ "samples": 16000,
+ "text": "",
+ "words": [],
+ "sha256": "0c92bddb4e96f3ea9ec9f0f64a668255a6c15527ac09f6f119cafde60c7c4a39",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ },
+ {
+ "rate": 44100,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ },
+ {
+ "rate": 48000,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ }
+ ]
+ },
+ {
+ "file": "single_sample.pcm",
+ "samples": 1,
+ "text": "",
+ "words": [],
+ "sha256": "96a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7",
+ "legacy": [
+ {
+ "rate": 16000,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ },
+ {
+ "rate": 44100,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ },
+ {
+ "rate": 48000,
+ "text": "",
+ "speech_samples": 0,
+ "speech_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ }
+ ]
+ }
+ ],
+ "vad_sha256": "a35ebf52fd3ce5f1469b2a36158dba761bc47b973ea3382b3186ca15b1f5af28",
+ "legacy_reference_commit": "717d7444c1d75d4fe41d68d31f456959d01c50f2",
+ "platform": "macOS aarch64 CPU"
+}
diff --git a/rust/crates/ensu/tests/prepare_transcription_fixtures.py b/rust/crates/ensu/tests/prepare_transcription_fixtures.py
new file mode 100644
index 0000000000..f6554f5b74
--- /dev/null
+++ b/rust/crates/ensu/tests/prepare_transcription_fixtures.py
@@ -0,0 +1,80 @@
+import argparse
+import hashlib
+import io
+import urllib.request
+import wave
+from pathlib import Path
+
+import pyarrow.parquet as pq
+import soundfile
+
+
+def download(directory, name, url, checksum):
+ path = directory / name
+ cached = path.exists()
+ if cached:
+ data = path.read_bytes()
+ else:
+ request = urllib.request.Request(
+ url, headers={"User-Agent": "ente-transcription-parity/1.0"}
+ )
+ with urllib.request.urlopen(request, timeout=60) as response:
+ data = response.read()
+ if hashlib.sha256(data).hexdigest() != checksum:
+ raise ValueError(f"Checksum mismatch: {path}")
+ if not cached:
+ path.write_bytes(data)
+ return path
+
+
+def prepare(directory):
+ directory.mkdir(parents=True, exist_ok=True)
+ download(
+ directory,
+ "silero_vad_v4.onnx",
+ "https://models.ente.com/silero_vad_v4.onnx",
+ "a35ebf52fd3ce5f1469b2a36158dba761bc47b973ea3382b3186ca15b1f5af28",
+ )
+ jfk = download(
+ directory,
+ "jfk.wav",
+ "https://raw.githubusercontent.com/ggerganov/whisper.cpp/284029c07012d2000941a08d38a31ffb71f4734e/samples/jfk.wav",
+ "59dfb9a4acb36fe2a2affc14bacbee2920ff435cb13cc314a08c13f66ba7860e",
+ )
+ librispeech = download(
+ directory,
+ "librispeech.parquet",
+ "https://huggingface.co/datasets/hf-internal-testing/librispeech_asr_dummy/resolve/5be91486e11a2d616f4ec5db8d3fd248585ac07a/clean/validation-00000-of-00001.parquet",
+ "4e69a06fa5edc90921e5e7e39a7084881f8b3ed9c805c574f4f39c6fde27c603",
+ )
+ with wave.open(str(jfk)) as recording:
+ assert recording.getnchannels() == 1
+ assert recording.getsampwidth() == 2
+ assert recording.getframerate() == 16000
+ speech = recording.readframes(recording.getnframes())
+ cases = {
+ "jfk_full": speech,
+ "jfk_opening": speech[: 8 * 32000],
+ "jfk_overlap": speech[4 * 32000 :],
+ "jfk_short": speech[:25600],
+ "jfk_padded": bytes(16000) + speech[: 5 * 32000] + bytes(16000),
+ "silence": bytes(32000),
+ "single_sample": bytes(2),
+ }
+ table = pq.read_table(librispeech)
+ for index in [0, 1, 10, 20, 40, 60, 72]:
+ row = table.slice(index, 1).to_pylist()[0]
+ samples, rate = soundfile.read(io.BytesIO(row["audio"]["bytes"]), dtype="int16")
+ assert rate == 16000 and samples.ndim == 1
+ cases[f"librispeech_{row['id']}"] = samples.astype("<i2").tobytes()
+ corpus = directory / "pcm"
+ corpus.mkdir(exist_ok=True)
+ for name, pcm in cases.items():
+ (corpus / f"{name}.pcm").write_bytes(pcm)
+ print(corpus)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("directory", type=Path)
+ prepare(parser.parse_args().directory)
diff --git a/rust/crates/ensu/tests/transcription-parity.md b/rust/crates/ensu/tests/transcription-parity.md
new file mode 100644
index 0000000000..5723a9a56d
--- /dev/null
+++ b/rust/crates/ensu/tests/transcription-parity.md
@@ -0,0 +1,69 @@
+# Parakeet compatibility tests
+
+The transcription backend is implemented independently using the shipped ONNX graph signatures, NVIDIA's [transducer description](https://arxiv.org/abs/2304.06795), and black-box reference outputs. No implementation code was copied from transcribe-rs.
+
+The compatibility decoder advances one encoder frame on a blank prediction and permits up to ten symbols per frame. It does not use the five duration logits for frame skipping: doing so changes the pinned backend's text and word timestamps. The 250 ms leading silence, 80 ms encoder frames, SentencePiece word grouping, final 50 ms token span, and removal of the leading timestamp offset preserve the existing behavior. VAD prefill uses rolling history, including overlap with previously emitted hangover frames.
+
+`data/parakeet-parity.json` contains outputs captured through the public API of transcribe-rs revision `efc66111d519a434e28d51d94740008a7ce29360`, using `ort` 2.0.0-rc.13 and its bundled ONNX Runtime 1.28.0 on CPU. It checks compatibility with that revision, including its recognition errors; it is not a ground-truth accuracy benchmark.
+
+The corpus has 14 cases and 150 reference words: JFK's full recording, overlapping windows, a short prefix, added silence, seven LibriSpeech excerpts, silence, and a single sample. Input checksums and hashes of all four Parakeet files and the Silero model are checked before inference. The model test requires exact text, word count, word text, and `f32` start/end equality. It also checks Ensu's live/recorded sample alignment, and repeats the corpus with source graphs, newly serialized optimized graphs, and reused cached graphs. Parakeet sessions are reused between cases; recurrent decoder state is initialized for every transcription.
+
+The same opt-in test checks the full legacy PCM β†’ resampler β†’ Silero VAD β†’ Parakeet path against 42 reference results: each input at 16, 44.1, and 48 kHz. It constructs the higher-rate inputs by repeating source samples at the corresponding indices. After speech extraction, both the sample count and the SHA-256 of little-endian `f32` samples must match before the public `Transcriber::transcribe` text is compared. This covers the production VAD smoothing settings and resampling with actual models.
+
+Only reference outputs and hashes are committed. Audio is fetched from pinned revisions of the [whisper.cpp JFK sample](https://github.com/ggerganov/whisper.cpp/blob/284029c07012d2000941a08d38a31ffb71f4734e/samples/jfk.wav) and [LibriSpeech dummy dataset](https://huggingface.co/datasets/hf-internal-testing/librispeech_asr_dummy/tree/5be91486e11a2d616f4ec5db8d3fd248585ac07a). The preparation script verifies both recordings before deriving PCM16 mono inputs at 16 kHz, and downloads the checksum-verified Silero model.
+
+## Run
+
+The recorded platform is macOS arm64 with Rust 1.99.0. Install that toolchain and `uv`, and mount an external scratch volume before starting. The example below uses `/Volumes/DevScratch`; adjust that path for your setup. Start in the repository's `rust/` directory and make a disposable external copy so the original checkout stays free of build outputs:
+
+```sh
+scratch_dir="/Volumes/DevScratch/ensu-transcription-parity"
+mkdir -p "$scratch_dir/workspace/rust" "$scratch_dir/tmp" "$scratch_dir/models"
+rsync -a --exclude target --exclude .git --exclude node_modules ./ "$scratch_dir/workspace/rust/"
+export TMPDIR="$scratch_dir/tmp"
+export TMP="$TMPDIR"
+export TEMP="$TMPDIR"
+export CARGO_TARGET_DIR="$scratch_dir/target"
+export CARGO_BUILD_BUILD_DIR="$scratch_dir/build"
+cd "$scratch_dir/workspace/rust"
+```
+
+Cargo compilation outputs and tempfile-created optimized graphs now go to scratch. These commands reuse your existing package caches and ort's runtime-binary download cache under their normal configuration; they do not relocate those shared caches.
+
+Download [Ensu's model archive](https://models.ente.com/parakeet-v3-int8.tar.gz), verify SHA-256 `43d37191602727524a7d8c6da0eef11c4ba24320f5b4730f1a2497befc2efa77`, and extract it into `$scratch_dir/models`. The archive contains a `parakeet-tdt-0.6b-v3-int8` directory. Then prepare and run:
+
+```sh
+export ENSU_TEST_TRANSCRIPTION_MODEL="$scratch_dir/models/parakeet-tdt-0.6b-v3-int8"
+uv run --no-project --with pyarrow==26.0.0 --with soundfile==0.14.0 \
+ python crates/ensu/tests/prepare_transcription_fixtures.py "$scratch_dir/corpus"
+export ENSU_TEST_TRANSCRIPTION_CORPUS="$scratch_dir/corpus/pcm"
+export ENSU_TEST_VAD_MODEL="$scratch_dir/corpus/silero_vad_v4.onnx"
+cargo +1.99 test --locked -p ente-ensu --features transcription --lib \
+ real_model_text_and_word_timestamps_match_reference -- --ignored --nocapture
+```
+
+The test is ignored by default so ordinary unit tests need neither downloads nor model inference. Use the same runtime and platform as the reference: changing them can change recognition or resampler fingerprints even with identical model files. These checks do not establish physical-device behavior or exhaust the model's supported languages.
+
+## Regenerate reference outputs
+
+Keep the reference dependency in a separate disposable Cargo project outside this workspace. Pin the Git revision above and enable only `onnx`. Pin `ort` and `ort-sys` to `=2.0.0-rc.13` to keep the runtime binding identical. For each prepared `.pcm` file, call:
+
+```rust
+use transcribe_rs::onnx::{
+ Quantization,
+ parakeet::{ParakeetModel, ParakeetParams, TimestampGranularity},
+};
+
+let mut model = ParakeetModel::load(model_directory, &Quantization::Int8)?;
+let samples: Vec<f32> = pcm.chunks_exact(2)
+ .map(|pair| i16::from_le_bytes([pair[0], pair[1]]) as f32 / 32768.0)
+ .collect();
+let result = model.transcribe_with(&samples, &ParakeetParams {
+ timestamp_granularity: Some(TimestampGranularity::Word),
+ ..Default::default()
+})?;
+```
+
+Record `result.text` and every segment's `text`, `start`, and `end`, together with the PCM sample count and SHA-256. Retain the model hashes and reference revision in the fixture. Do not add the reference crate back to the workspace or its development dependencies.
+
+The legacy results were captured from Ensu commit `717d7444c1d75d4fe41d68d31f456959d01c50f2`, whose adapter uses the same pinned dependency. For each source input and rate, construct PCM with the index rule in `parity.rs`, capture the public `Transcriber::transcribe` result, and instrument `extract_speech_from_pcm16` in a disposable copy to capture its sample count and `f32` checksum. Keep the same Silero file, model files, platform, and runtime for reference and replacement.