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: f32Implementations§
Source§impl UnifiedStreamingConfig
impl UnifiedStreamingConfig
pub fn validate(self) -> Result<Self>
pub fn left_context_frames(self) -> usize
pub fn chunk_frames(self) -> usize
pub fn right_context_frames(self) -> usize
pub fn total_window_frames(self) -> usize
pub fn left_context_samples(self) -> usize
Sourcepub fn chunk_samples(self) -> usize
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
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}pub fn right_context_samples(self) -> usize
pub fn total_window_samples(self) -> usize
pub fn chunk_encoder_frames(self) -> usize
pub fn left_context_encoder_frames(self) -> usize
Trait Implementations§
Source§impl Clone for UnifiedStreamingConfig
impl Clone for UnifiedStreamingConfig
Source§fn clone(&self) -> UnifiedStreamingConfig
fn clone(&self) -> UnifiedStreamingConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnifiedStreamingConfig
impl Debug for UnifiedStreamingConfig
Source§impl Default for UnifiedStreamingConfig
impl Default for UnifiedStreamingConfig
impl Copy for UnifiedStreamingConfig
Auto Trait Implementations§
impl Freeze for UnifiedStreamingConfig
impl RefUnwindSafe for UnifiedStreamingConfig
impl Send for UnifiedStreamingConfig
impl Sync for UnifiedStreamingConfig
impl Unpin for UnifiedStreamingConfig
impl UnsafeUnpin for UnifiedStreamingConfig
impl UnwindSafe for UnifiedStreamingConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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