Config

Struct Config 

Source
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: usize

Duration 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: String

OpenAI model to use for transcription.

Common values: "whisper-1" for OpenAI’s Whisper model.

§endpoint: String

API 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

Source

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
Source

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.

Source

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")));
Source

pub fn uses_on_device(&self) -> bool

Returns true when on-device transcription is enabled.

Source

pub fn on_device_config(&self) -> Option<&OnDeviceConfig>

Returns the enabled on-device configuration if present.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config
where Config: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,