Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/linux_transcriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Instant;
use color_eyre::eyre::{Result, WrapErr, eyre};
use transcribe_cpp::{Backend, Model, ModelOptions, RunOptions, TimestampKind};

use crate::transcription::OfflineGgufSession;
use crate::offline_gguf::OfflineGgufSession;
use crate::transcription_models::{
ModelDefinition, TranscriptionModelId, TranscriptionSelection, definition,
download_with_progress, model_path, validate,
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ mod microphone_activity;
mod moonshine;
#[cfg(all(target_os = "macos", debug_assertions))]
mod moonshine_lab;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod offline_gguf;
#[cfg(target_os = "macos")]
mod onboarding;
#[cfg(target_os = "macos")]
Expand Down
47 changes: 47 additions & 0 deletions src/offline_gguf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! The GGUF inference session owner shared by the macOS and Linux adapters.
//!
//! Both platforms load the same `transcribe-cpp` models, so the session
//! lifecycle rules that keep inference scratch memory bounded belong in one
//! place rather than per platform.

pub(crate) struct OfflineGgufSession {
model: transcribe_cpp::Model,
session: Option<transcribe_cpp::Session>,
}

impl OfflineGgufSession {
pub(crate) fn new(model: transcribe_cpp::Model) -> transcribe_cpp::Result<Self> {
let session = model.session()?;
Ok(Self {
model,
session: Some(session),
})
}

pub(crate) fn run(
&mut self,
samples: &[f32],
options: &transcribe_cpp::RunOptions,
) -> transcribe_cpp::Result<transcribe_cpp::Transcript> {
// transcribe-cpp 0.1.x retains input-sized scheduler buffers for the
// session lifetime. Drop each used session before creating its
// successor so a long inference cannot pin that high-water mark or
// overlap two sessions' persistent decoder state.
let mut session = match self.session.take() {
Some(session) => session,
None => self.model.session()?,
};
let result = session.run(samples, options);
drop(session);
match self.model.session() {
Ok(session) => {
self.session = Some(session);
result
}
Err(recovery_error) => match result {
Ok(_) => Err(recovery_error),
Err(run_error) => Err(run_error),
},
}
}
}
3 changes: 2 additions & 1 deletion src/parakeet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ use crate::dictation::{DictationClip, DictationProtocol, pad_for_parakeet};
use crate::dictation_processor::ProcessingObservation;
use crate::history::{History, HistoryDraft, HistoryKind};
use crate::meeting::{self, TranscriptEntry, TranscriptPublication};
use crate::offline_gguf::OfflineGgufSession;
use crate::paste::{PasteMode, Paster};
use crate::suppression::InputActivity;
#[cfg(test)]
use crate::text_replacements::ReplacementSet;
use crate::transcription::{OfflineGgufSession, Transcriber, WarmTranscriber};
use crate::transcription::{Transcriber, WarmTranscriber};
use crate::transcription_models::{
TranscriptionModelId, TranscriptionSelection, model_path, validate,
};
Expand Down
42 changes: 0 additions & 42 deletions src/transcription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ pub struct WarmTranscriber {
active: Option<Transcriber>,
}

pub(crate) struct OfflineGgufSession {
model: transcribe_cpp::Model,
session: Option<transcribe_cpp::Session>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TranscriptSegment {
Expand Down Expand Up @@ -127,43 +122,6 @@ impl WarmTranscriber {
}
}

impl OfflineGgufSession {
pub(crate) fn new(model: transcribe_cpp::Model) -> transcribe_cpp::Result<Self> {
let session = model.session()?;
Ok(Self {
model,
session: Some(session),
})
}

pub(crate) fn run(
&mut self,
samples: &[f32],
options: &transcribe_cpp::RunOptions,
) -> transcribe_cpp::Result<transcribe_cpp::Transcript> {
// transcribe-cpp 0.1.x retains input-sized scheduler buffers for the
// session lifetime. Drop each used session before creating its
// successor so a long inference cannot pin that high-water mark or
// overlap two sessions' persistent decoder state.
let mut session = match self.session.take() {
Some(session) => session,
None => self.model.session()?,
};
let result = session.run(samples, options);
drop(session);
match self.model.session() {
Ok(session) => {
self.session = Some(session);
result
}
Err(recovery_error) => match result {
Ok(_) => Err(recovery_error),
Err(run_error) => Err(run_error),
},
}
}
}

#[cfg(test)]
mod tests {
use super::{Transcript, UNIFIED_ENGLISH_TRAILING_SILENCE_SAMPLES, prepare_gguf_samples};
Expand Down