fn handle_callback()

in crates/ratchet-models/src/whisper/task.rs [174:197]


    fn handle_callback(
        &self,
        tokenizer: &WhisperTokenizer,
        new_tokens: &[i32],
        timestamps_seen: &mut i32,
        callback: impl Fn(StreamedSegment),
    ) {
        if tokenizer.is_timestamp(new_tokens[new_tokens.len() - 1]) {
            *timestamps_seen += 1;
            if *timestamps_seen % 2 == 0 {
                let previous_timestamp = new_tokens[..new_tokens.len() - 2]
                    .iter()
                    .rposition(|x| tokenizer.is_timestamp(*x));
                if let Some(previous_timestamp) = previous_timestamp {
                    callback(StreamedSegment::from_tokens(
                        tokenizer,
                        &new_tokens[previous_timestamp..],
                        self.options.time_offset.unwrap_or(0.0),
                        false,
                    ));
                }
            }
        }
    }