vtt_rs/
lib.rs

1//! Voice-to-Text Streaming Library
2//!
3//! This library provides real-time audio transcription capabilities for AI agents
4//! and other applications that need situational awareness through speech recognition.
5//!
6//! # Architecture
7//!
8//! The library is organized into several key components:
9//!
10//! - [`TranscriptionService`]: Main service that orchestrates audio capture and transcription
11//! - [`Config`]: Configuration for chunk duration, API endpoint, and model selection
12//! - [`TranscriptionEvent`]: Events emitted for successful transcriptions and errors
13//!
14//! Audio is captured from the default input device, chunked into configurable segments,
15//! and sent to OpenAI-compatible transcription APIs. Results are delivered via an
16//! event-driven async channel.
17//!
18//! # Examples
19//!
20//! ## Basic Usage
21//!
22//! ```no_run
23//! use vtt_rs::{TranscriptionService, Config, TranscriptionEvent};
24//!
25//! #[tokio::main]
26//! async fn main() -> anyhow::Result<()> {
27//!     let config = Config::default();
28//!     let api_key = std::env::var("OPENAI_API_KEY")?;
29//!
30//!     let mut service = TranscriptionService::new(config, api_key)?;
31//!
32//!     // Start listening and transcribing
33//!     let (mut receiver, _stream) = service.start().await?;
34//!
35//!     // Process transcription events
36//!     while let Some(event) = receiver.recv().await {
37//!         match event {
38//!             TranscriptionEvent::Transcription { chunk_id, text } => {
39//!                 println!("Heard: {}", text);
40//!             }
41//!             TranscriptionEvent::Error { chunk_id, error } => {
42//!                 eprintln!("Error: {}", error);
43//!             }
44//!         }
45//!     }
46//!
47//!     Ok(())
48//! }
49//! ```
50//!
51//! ## Custom Configuration
52//!
53//! ```no_run
54//! use vtt_rs::{Config, TranscriptionService};
55//! use std::path::PathBuf;
56//!
57//! # #[tokio::main]
58//! # async fn main() -> anyhow::Result<()> {
59//! let config = Config {
60//!     chunk_duration_secs: 3,
61//!     model: "whisper-1".to_string(),
62//!     endpoint: "https://api.openai.com/v1/audio/transcriptions".to_string(),
63//!     out_file: Some(PathBuf::from("transcripts.log")),
64//! };
65//!
66//! let api_key = std::env::var("OPENAI_API_KEY")?;
67//! let mut service = TranscriptionService::new(config, api_key)?;
68//! # Ok(())
69//! # }
70//! ```
71
72mod audio;
73mod config;
74mod transcription;
75
76pub use config::{Config, OnDeviceConfig};
77pub use transcription::{TranscriptionEvent, TranscriptionService};
78
79// Re-export commonly used types
80pub use anyhow::{Context, Result};