pub struct Config {
pub chunk_duration_secs: usize,
pub model: String,
pub endpoint: String,
pub out_file: Option<PathBuf>,
pub on_device: Option<OnDeviceConfig>,
}Expand description
Configuration for the transcription service.
This struct controls how audio is captured, chunked, and sent to the transcription API. All fields have sensible defaults and can be loaded from a JSON configuration file.
§Examples
§Using defaults
use vtt_rs::Config;
let config = Config::default();
assert_eq!(config.chunk_duration_secs, 5);
assert_eq!(config.model, "whisper-1");§Custom configuration
use vtt_rs::Config;
use std::path::PathBuf;
let config = Config {
chunk_duration_secs: 3,
model: "whisper-1".to_string(),
endpoint: "https://api.openai.com/v1/audio/transcriptions".to_string(),
out_file: Some(PathBuf::from("output.log")),
};§Loading from JSON file
use vtt_rs::Config;
let config = Config::from_file("config.json")?;Fields§
§chunk_duration_secs: usizeDuration of each audio chunk in seconds.
Smaller values (2-3 seconds) provide faster response times but may reduce accuracy. Larger values (5-10 seconds) improve accuracy but increase latency.
model: StringOpenAI model to use for transcription.
Common values: "whisper-1" for OpenAI’s Whisper model.
endpoint: StringAPI endpoint for transcription requests.
Defaults to OpenAI’s endpoint but can be changed to support local Whisper instances or other OpenAI-compatible APIs.
out_file: Option<PathBuf>Optional file path to append transcription logs.
When set, all transcriptions (including silence markers) will be written
to this file in addition to being sent via events. Use None to disable
file logging.
on_device: Option<OnDeviceConfig>Optional on-device configuration.
When present and enabled, the service will run Whisper locally using
the bundled Candle integration instead of calling a remote API.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self>
Loads configuration from a JSON file at the specified path.
The JSON file should contain fields matching the Config struct.
Missing fields will use their default values via serde’s #[serde(default)].
§Examples
use vtt_rs::Config;
let config = Config::from_file("my_config.json")?;
println!("Using model: {}", config.model);§Errors
Returns an error if:
- The file cannot be read
- The file contains invalid JSON
- The JSON structure doesn’t match the expected format
Sourcepub fn load_or_default() -> Result<(Self, Option<PathBuf>)>
pub fn load_or_default() -> Result<(Self, Option<PathBuf>)>
Attempts to load configuration from vtt.config.json in the current directory.
If the default config file exists, it will be loaded. Otherwise, returns default configuration values.
§Examples
use vtt_rs::Config;
let (config, source_path) = Config::load_or_default()?;
if let Some(path) = source_path {
println!("Loaded config from: {}", path.display());
} else {
println!("Using default configuration");
}§Errors
Returns an error if the default config file exists but cannot be read or parsed.
Sourcepub fn resolve_out_path(&self, source: Option<&Path>) -> Option<PathBuf>
pub fn resolve_out_path(&self, source: Option<&Path>) -> Option<PathBuf>
Resolves the output file path relative to the configuration file’s location.
This method handles both absolute and relative paths in out_file:
- Absolute paths are returned as-is
- Relative paths are resolved relative to the config file’s directory
- If no source path is provided, relative paths remain unchanged
§Examples
use vtt_rs::Config;
use std::path::{Path, PathBuf};
let mut config = Config::default();
config.out_file = Some(PathBuf::from("logs/output.log"));
let source = Path::new("/etc/vtt/config.json");
let resolved = config.resolve_out_path(Some(source));
assert_eq!(resolved, Some(PathBuf::from("/etc/vtt/logs/output.log")));Sourcepub fn uses_on_device(&self) -> bool
pub fn uses_on_device(&self) -> bool
Returns true when on-device transcription is enabled.
Sourcepub fn on_device_config(&self) -> Option<&OnDeviceConfig>
pub fn on_device_config(&self) -> Option<&OnDeviceConfig>
Returns the enabled on-device configuration if present.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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