Skip to main content

UnifiedStreamingConfig

Struct UnifiedStreamingConfig 

Source
pub struct UnifiedStreamingConfig {
    pub left_context_secs: f32,
    pub chunk_secs: f32,
    pub right_context_secs: f32,
}

Fields§

§left_context_secs: f32§chunk_secs: f32§right_context_secs: f32

Implementations§

Source§

impl UnifiedStreamingConfig

Source

pub fn validate(self) -> Result<Self>

Source

pub fn left_context_frames(self) -> usize

Source

pub fn chunk_frames(self) -> usize

Source

pub fn right_context_frames(self) -> usize

Source

pub fn total_window_frames(self) -> usize

Source

pub fn left_context_samples(self) -> usize

Source

pub fn chunk_samples(self) -> usize

Examples found in repository?
examples/shared_model.rs (line 100)
95fn run_unified(model_dir: &str, audio: &[f32]) -> Result<(), Box<dyn std::error::Error>> {
96    let handle = ParakeetUnifiedHandle::load(model_dir, None)?;
97    let mut a = ParakeetUnified::from_shared(&handle);
98    let mut b = ParakeetUnified::from_shared(&handle);
99
100    let chunk_size = a.streaming_config().chunk_samples();
101    for chunk_data in audio.chunks(chunk_size) {
102        a.transcribe_chunk(chunk_data)?;
103        b.transcribe_chunk(chunk_data)?;
104    }
105    a.flush()?;
106    b.flush()?;
107
108    println!("A: {}", a.get_transcript());
109    println!("B: {}", b.get_transcript());
110    assert_eq!(
111        a.get_transcript(),
112        b.get_transcript(),
113        "shared model must be deterministic"
114    );
115    println!("same");
116    Ok(())
117}
More examples
Hide additional examples
examples/unified.rs (line 66)
22fn main() -> Result<(), Box<dyn std::error::Error>> {
23    let start_time = Instant::now();
24    let args: Vec<String> = env::args().collect();
25
26    let audio_path = if args.len() > 1 {
27        &args[1]
28    } else {
29        "6_speakers.wav"
30    };
31
32    let use_streaming = args.len() > 2 && args[2] == "streaming";
33
34    // Load audio
35    let mut reader = hound::WavReader::open(audio_path)?;
36    let spec = reader.spec();
37
38    if spec.sample_rate != 16000 {
39        return Err(format!("Expected 16kHz, got {}Hz", spec.sample_rate).into());
40    }
41
42    let mut audio: Vec<f32> = match spec.sample_format {
43        hound::SampleFormat::Float => reader.samples::<f32>().collect::<Result<Vec<_>, _>>()?,
44        hound::SampleFormat::Int => reader
45            .samples::<i16>()
46            .map(|s| s.map(|s| s as f32 / 32768.0))
47            .collect::<Result<Vec<_>, _>>()?,
48    };
49
50    if spec.channels > 1 {
51        audio = audio
52            .chunks(spec.channels as usize)
53            .map(|c| c.iter().sum::<f32>() / spec.channels as f32)
54            .collect();
55    }
56
57    let duration = audio.len() as f32 / 16000.0;
58    println!("Audio: {:.1}s, {}Hz, {} ch", duration, spec.sample_rate, spec.channels);
59
60    let mut model = ParakeetUnified::from_pretrained("./unified", None)?;
61    let load_time = start_time.elapsed();
62    println!("Model loaded in {:.2}s", load_time.as_secs_f32());
63
64    if use_streaming {
65        let config = model.streaming_config();
66        let chunk_size = config.chunk_samples();
67        println!("Streaming mode: {:.0}ms chunks", config.chunk_secs * 1000.0);
68
69        let transcribe_start = Instant::now();
70        print!("Streaming: ");
71
72        for chunk in audio.chunks(chunk_size) {
73            let text = model.transcribe_chunk(chunk)?;
74            if !text.is_empty() {
75                print!("{}", text);
76                std::io::stdout().flush()?;
77            }
78        }
79
80        let remaining = model.flush()?;
81        if !remaining.is_empty() {
82            print!("{}", remaining);
83        }
84
85        let result = model.get_timed_transcript(TimestampMode::Sentences);
86        println!("\n\nFinal: {}", result.text);
87
88        println!("\nSentences:");
89        for segment in &result.tokens {
90            println!("[{:.2}s - {:.2}s]: {}", segment.start, segment.end, segment.text);
91        }
92
93        let elapsed = transcribe_start.elapsed();
94        println!(
95            "Transcribed in {:.2}s (audio: {:.1}s, RTF: {:.2}x)",
96            elapsed.as_secs_f32(),
97            duration,
98            duration / elapsed.as_secs_f32()
99        );
100    } else {
101        println!("Offline mode (with word timestamps)");
102
103        let transcribe_start = Instant::now();
104        let result = model.transcribe_samples(
105            audio,
106            spec.sample_rate,
107            spec.channels,
108            Some(TimestampMode::Words),
109        )?;
110        let elapsed = transcribe_start.elapsed();
111
112        println!("Result: {}", result.text);
113
114        println!("\nWords (first 20):");
115        for word in result.tokens.iter().take(20) {
116            println!("[{:.2}s - {:.2}s]: {}", word.start, word.end, word.text);
117        }
118
119        println!(
120            "Transcribed in {:.2}s (audio: {:.1}s, RTF: {:.2}x)",
121            elapsed.as_secs_f32(),
122            duration,
123            duration / elapsed.as_secs_f32()
124        );
125    }
126
127    Ok(())
128}
Source

pub fn right_context_samples(self) -> usize

Source

pub fn total_window_samples(self) -> usize

Source

pub fn chunk_encoder_frames(self) -> usize

Source

pub fn left_context_encoder_frames(self) -> usize

Trait Implementations§

Source§

impl Clone for UnifiedStreamingConfig

Source§

fn clone(&self) -> UnifiedStreamingConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnifiedStreamingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UnifiedStreamingConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for UnifiedStreamingConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more