pub mod capture;
pub mod enroll;
pub mod install_model;
pub mod reflect;
pub mod review;
pub mod transcribe;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct VoiceCommand {
#[command(subcommand)]
pub command: VoiceSubcommands,
}
#[derive(Subcommand)]
pub enum VoiceSubcommands {
Capture(capture::CaptureCommand),
Transcribe(transcribe::TranscribeCommand),
Reflect(reflect::ReflectCommand),
Review(review::ReviewCommand),
InstallModel(install_model::InstallModelCommand),
Enroll(enroll::EnrollCommand),
}
impl VoiceCommand {
pub async fn execute(self) -> Result<()> {
match self.command {
VoiceSubcommands::Capture(cmd) => cmd.execute(),
VoiceSubcommands::Transcribe(cmd) => cmd.execute(),
VoiceSubcommands::Reflect(cmd) => cmd.execute().await,
VoiceSubcommands::Review(cmd) => cmd.execute(),
VoiceSubcommands::InstallModel(cmd) => cmd.execute(),
VoiceSubcommands::Enroll(cmd) => cmd.execute(),
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn voice_subcommands_capture_variant() {
let cmd = VoiceCommand {
command: VoiceSubcommands::Capture(capture::CaptureCommand {
idle_after: 5,
output: None,
device: None,
}),
};
assert!(matches!(cmd.command, VoiceSubcommands::Capture(_)));
}
#[test]
fn voice_subcommands_transcribe_variant() {
let cmd = VoiceCommand {
command: VoiceSubcommands::Transcribe(transcribe::TranscribeCommand {
wav: PathBuf::from("/tmp/x.wav"),
backend: None,
model: None,
format: None,
speaker: None,
threshold: None,
speaker_model: None,
}),
};
assert!(matches!(cmd.command, VoiceSubcommands::Transcribe(_)));
}
#[test]
fn voice_subcommands_reflect_variant() {
let cmd = VoiceCommand {
command: VoiceSubcommands::Reflect(reflect::ReflectCommand {
transcript: Some(PathBuf::from("/tmp/t.jsonl")),
session: None,
}),
};
assert!(matches!(cmd.command, VoiceSubcommands::Reflect(_)));
}
#[test]
fn voice_subcommands_install_model_variant() {
let cmd = VoiceCommand {
command: VoiceSubcommands::InstallModel(install_model::InstallModelCommand {
dest: None,
force: false,
variant: install_model::Variant::WhisperTinyEn,
}),
};
assert!(matches!(cmd.command, VoiceSubcommands::InstallModel(_)));
}
#[tokio::test]
async fn voice_command_dispatches_install_model_via_execute() {
use crate::voice::models::REQUIRED_FILES;
let tmp = tempfile::TempDir::new().unwrap();
for f in REQUIRED_FILES {
std::fs::write(tmp.path().join(f), b"placeholder").unwrap();
}
let cmd = VoiceCommand {
command: VoiceSubcommands::InstallModel(install_model::InstallModelCommand {
dest: Some(tmp.path().to_path_buf()),
force: false,
variant: install_model::Variant::WhisperTinyEn,
}),
};
cmd.execute()
.await
.expect("install-model dispatch should succeed on pre-staged dir");
}
}