Skip to main content

gui_integration/
gui_integration.rs

1//! GUI-integration patterns.
2//!
3//! This file is a sketch — adapt the patterns to your specific GUI
4//! framework (egui, iced, tauri, slint, etc.). The key ideas:
5//!
6//! 1. Create the engine once and reuse it across calls.
7//! 2. Call `warmup()` once after construction to reduce first-call latency.
8//! 3. Run `transcribe()` off the UI thread (it blocks for a few hundred ms).
9
10use memo_stt::SttEngine;
11
12fn handle_record_button_click(
13    engine: &mut SttEngine,
14) -> Result<String, Box<dyn std::error::Error>> {
15    let samples = capture_audio()?;
16    let text = engine.transcribe(&samples)?;
17    Ok(text)
18}
19
20fn setup_realtime_transcription() -> Result<SttEngine, Box<dyn std::error::Error>> {
21    let engine = SttEngine::new_default(16000)?;
22    engine.warmup()?;
23    Ok(engine)
24}
25
26fn capture_audio() -> Result<Vec<i16>, Box<dyn std::error::Error>> {
27    // Replace with your audio-capture implementation (cpal, rodio, your
28    // framework's audio API, etc.). Must produce 16-bit mono PCM at the
29    // sample rate you passed to `SttEngine::new_default`.
30    Ok(vec![0i16; 16_000])
31}
32
33fn main() -> Result<(), Box<dyn std::error::Error>> {
34    let mut engine = setup_realtime_transcription()?;
35    let _ = handle_record_button_click(&mut engine);
36
37    println!("GUI integration sketch — see source for patterns:");
38    println!("  1. Create SttEngine once, reuse for many transcriptions.");
39    println!("  2. Call warmup() after construction.");
40    println!("  3. Call transcribe() off the UI thread.");
41    Ok(())
42}