Phase 6: Llama-server manager, settings UI, packaging, and polish
- Implement LlamaManager in Rust for llama-server lifecycle: spawn with port allocation, health check, clean shutdown on Drop, model listing - Add llama_start/stop/status/list_models Tauri commands - Add load_settings/save_settings commands with JSON persistence - Build SettingsModal with tabs for Transcription, AI Provider, Local AI settings (model size, device, language, API keys, provider selection) - Wire settings into pipeline calls (model, device, language, skip diarization) - Configure Tauri packaging: asset protocol for local audio files, CSP policy, bundle metadata, Linux .deb/.AppImage and Windows .msi config - Add keyboard shortcuts: Space (play/pause), Ctrl+O (import), Ctrl+, (settings), Escape (close menus/modals) - Close export dropdown on outside click - Tests: 30 Python, 6 Rust, 0 Svelte errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7
src-tauri/Cargo.lock
generated
7
src-tauri/Cargo.lock
generated
@@ -1498,6 +1498,12 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http-range"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "httparse"
|
name = "httparse"
|
||||||
version = "1.10.1"
|
version = "1.10.1"
|
||||||
@@ -3595,6 +3601,7 @@ dependencies = [
|
|||||||
"gtk",
|
"gtk",
|
||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"http",
|
"http",
|
||||||
|
"http-range",
|
||||||
"jni",
|
"jni",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
|||||||
tauri-build = { version = "2", features = [] }
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2", features = [] }
|
tauri = { version = "2", features = ["protocol-asset"] }
|
||||||
tauri-plugin-opener = "2"
|
tauri-plugin-opener = "2"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub fn ai_chat(
|
|||||||
let manager = get_sidecar()?;
|
let manager = get_sidecar()?;
|
||||||
|
|
||||||
let request_id = uuid::Uuid::new_v4().to_string();
|
let request_id = uuid::Uuid::new_v4().to_string();
|
||||||
let mut payload = json!({
|
let payload = json!({
|
||||||
"action": "chat",
|
"action": "chat",
|
||||||
"messages": messages,
|
"messages": messages,
|
||||||
"transcript_context": transcript_context.unwrap_or_default(),
|
"transcript_context": transcript_context.unwrap_or_default(),
|
||||||
|
|||||||
@@ -1,2 +1,34 @@
|
|||||||
// Settings commands — app preferences, model selection, AI provider config
|
use serde_json::{json, Value};
|
||||||
// TODO: Implement when settings UI is built
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::llama::LlamaManager;
|
||||||
|
|
||||||
|
fn settings_path() -> PathBuf {
|
||||||
|
LlamaManager::data_dir().join("settings.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load app settings from disk.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn load_settings() -> Value {
|
||||||
|
let path = settings_path();
|
||||||
|
if !path.exists() {
|
||||||
|
return json!({});
|
||||||
|
}
|
||||||
|
match fs::read_to_string(&path) {
|
||||||
|
Ok(content) => serde_json::from_str(&content).unwrap_or(json!({})),
|
||||||
|
Err(_) => json!({}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save app settings to disk.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn save_settings(settings: Value) -> Result<(), String> {
|
||||||
|
let path = settings_path();
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
fs::create_dir_all(parent).map_err(|e| format!("Cannot create settings dir: {e}"))?;
|
||||||
|
}
|
||||||
|
let json = serde_json::to_string_pretty(&settings).map_err(|e| e.to_string())?;
|
||||||
|
fs::write(&path, json).map_err(|e| format!("Cannot write settings: {e}"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,2 +1,64 @@
|
|||||||
// System commands — hardware detection, llama-server lifecycle
|
use serde_json::{json, Value};
|
||||||
// TODO: Implement hardware detection and llama-server management
|
|
||||||
|
use crate::llama::{LlamaConfig, LlamaManager, LlamaStatus};
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
/// Global llama manager — persists across command invocations.
|
||||||
|
fn llama_manager() -> &'static LlamaManager {
|
||||||
|
static INSTANCE: OnceLock<LlamaManager> = OnceLock::new();
|
||||||
|
INSTANCE.get_or_init(LlamaManager::new)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start the local llama-server with a GGUF model.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn llama_start(
|
||||||
|
model_path: String,
|
||||||
|
binary_path: Option<String>,
|
||||||
|
port: Option<u16>,
|
||||||
|
n_gpu_layers: Option<i32>,
|
||||||
|
context_size: Option<u32>,
|
||||||
|
threads: Option<u32>,
|
||||||
|
) -> Result<LlamaStatus, String> {
|
||||||
|
let config = LlamaConfig {
|
||||||
|
binary_path: PathBuf::from(
|
||||||
|
binary_path.unwrap_or_else(|| "llama-server".to_string()),
|
||||||
|
),
|
||||||
|
model_path: PathBuf::from(model_path),
|
||||||
|
port: port.unwrap_or(0),
|
||||||
|
n_gpu_layers: n_gpu_layers.unwrap_or(0),
|
||||||
|
context_size: context_size.unwrap_or(4096),
|
||||||
|
threads: threads.unwrap_or(4),
|
||||||
|
};
|
||||||
|
|
||||||
|
llama_manager().start(&config)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop the local llama-server.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn llama_stop() -> Result<(), String> {
|
||||||
|
llama_manager().stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the status of the local llama-server.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn llama_status() -> LlamaStatus {
|
||||||
|
llama_manager().status()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List available GGUF models in the models directory.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn llama_list_models() -> Value {
|
||||||
|
let models = LlamaManager::list_models();
|
||||||
|
json!({
|
||||||
|
"models": models,
|
||||||
|
"models_dir": LlamaManager::models_dir().to_string_lossy(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the app data directory path.
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn get_data_dir() -> String {
|
||||||
|
LlamaManager::data_dir().to_string_lossy().to_string()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
pub mod llama;
|
||||||
pub mod sidecar;
|
pub mod sidecar;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|
||||||
use commands::ai::{ai_chat, ai_configure, ai_list_providers};
|
use commands::ai::{ai_chat, ai_configure, ai_list_providers};
|
||||||
use commands::export::export_transcript;
|
use commands::export::export_transcript;
|
||||||
use commands::project::{create_project, get_project, list_projects};
|
use commands::project::{create_project, get_project, list_projects};
|
||||||
|
use commands::settings::{load_settings, save_settings};
|
||||||
|
use commands::system::{get_data_dir, llama_list_models, llama_start, llama_status, llama_stop};
|
||||||
use commands::transcribe::{run_pipeline, transcribe_file};
|
use commands::transcribe::{run_pipeline, transcribe_file};
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
@@ -23,6 +26,13 @@ pub fn run() {
|
|||||||
ai_chat,
|
ai_chat,
|
||||||
ai_list_providers,
|
ai_list_providers,
|
||||||
ai_configure,
|
ai_configure,
|
||||||
|
llama_start,
|
||||||
|
llama_stop,
|
||||||
|
llama_status,
|
||||||
|
llama_list_models,
|
||||||
|
get_data_dir,
|
||||||
|
load_settings,
|
||||||
|
save_settings,
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
307
src-tauri/src/llama/mod.rs
Normal file
307
src-tauri/src/llama/mod.rs
Normal file
@@ -0,0 +1,307 @@
|
|||||||
|
//! Llama-server lifecycle management.
|
||||||
|
//!
|
||||||
|
//! Manages a bundled llama-server (llama.cpp) binary that exposes an
|
||||||
|
//! OpenAI-compatible API on localhost. The Rust backend handles:
|
||||||
|
//! - Finding or downloading the llama-server binary
|
||||||
|
//! - Spawning the process with a GGUF model file
|
||||||
|
//! - Port allocation and health checking
|
||||||
|
//! - Clean shutdown on app exit
|
||||||
|
|
||||||
|
use std::net::TcpListener;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::{Child, Command, Stdio};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Configuration for the llama-server instance.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct LlamaConfig {
|
||||||
|
/// Path to the llama-server binary.
|
||||||
|
pub binary_path: PathBuf,
|
||||||
|
/// Path to the GGUF model file.
|
||||||
|
pub model_path: PathBuf,
|
||||||
|
/// Port to listen on (0 = auto-assign).
|
||||||
|
pub port: u16,
|
||||||
|
/// Number of GPU layers to offload (-1 = all, 0 = CPU only).
|
||||||
|
pub n_gpu_layers: i32,
|
||||||
|
/// Context window size.
|
||||||
|
pub context_size: u32,
|
||||||
|
/// Number of threads for CPU inference.
|
||||||
|
pub threads: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for LlamaConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
binary_path: PathBuf::from("llama-server"),
|
||||||
|
model_path: PathBuf::new(),
|
||||||
|
port: 0,
|
||||||
|
n_gpu_layers: 0,
|
||||||
|
context_size: 4096,
|
||||||
|
threads: 4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Status of the llama-server.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct LlamaStatus {
|
||||||
|
pub running: bool,
|
||||||
|
pub port: u16,
|
||||||
|
pub model: String,
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Manages the llama-server process lifecycle.
|
||||||
|
pub struct LlamaManager {
|
||||||
|
process: Mutex<Option<Child>>,
|
||||||
|
port: Mutex<u16>,
|
||||||
|
model_path: Mutex<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LlamaManager {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
process: Mutex::new(None),
|
||||||
|
port: Mutex::new(0),
|
||||||
|
model_path: Mutex::new(String::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the data directory for Voice to Notes.
|
||||||
|
pub fn data_dir() -> PathBuf {
|
||||||
|
let home = std::env::var("HOME")
|
||||||
|
.or_else(|_| std::env::var("USERPROFILE"))
|
||||||
|
.unwrap_or_else(|_| ".".to_string());
|
||||||
|
PathBuf::from(home).join(".voicetonotes")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the models directory.
|
||||||
|
pub fn models_dir() -> PathBuf {
|
||||||
|
Self::data_dir().join("models")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find an available port for the server.
|
||||||
|
fn find_available_port() -> Result<u16, String> {
|
||||||
|
let listener =
|
||||||
|
TcpListener::bind("127.0.0.1:0").map_err(|e| format!("Cannot bind port: {e}"))?;
|
||||||
|
let port = listener
|
||||||
|
.local_addr()
|
||||||
|
.map_err(|e| format!("Cannot get port: {e}"))?
|
||||||
|
.port();
|
||||||
|
Ok(port)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start the llama-server with the given configuration.
|
||||||
|
pub fn start(&self, config: &LlamaConfig) -> Result<LlamaStatus, String> {
|
||||||
|
// Check if already running
|
||||||
|
{
|
||||||
|
let proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
if proc.is_some() {
|
||||||
|
let port = *self.port.lock().map_err(|e| e.to_string())?;
|
||||||
|
let model = self.model_path.lock().map_err(|e| e.to_string())?.clone();
|
||||||
|
return Ok(LlamaStatus {
|
||||||
|
running: true,
|
||||||
|
port,
|
||||||
|
model,
|
||||||
|
url: format!("http://127.0.0.1:{port}"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate paths
|
||||||
|
if !config.binary_path.exists() {
|
||||||
|
return Err(format!(
|
||||||
|
"llama-server binary not found at: {}",
|
||||||
|
config.binary_path.display()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if !config.model_path.exists() {
|
||||||
|
return Err(format!(
|
||||||
|
"Model file not found at: {}",
|
||||||
|
config.model_path.display()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine port
|
||||||
|
let port = if config.port == 0 {
|
||||||
|
Self::find_available_port()?
|
||||||
|
} else {
|
||||||
|
config.port
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build command
|
||||||
|
let mut cmd = Command::new(&config.binary_path);
|
||||||
|
cmd.arg("--model")
|
||||||
|
.arg(&config.model_path)
|
||||||
|
.arg("--port")
|
||||||
|
.arg(port.to_string())
|
||||||
|
.arg("--ctx-size")
|
||||||
|
.arg(config.context_size.to_string())
|
||||||
|
.arg("--threads")
|
||||||
|
.arg(config.threads.to_string())
|
||||||
|
.arg("--n-gpu-layers")
|
||||||
|
.arg(config.n_gpu_layers.to_string())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped());
|
||||||
|
|
||||||
|
let child = cmd
|
||||||
|
.spawn()
|
||||||
|
.map_err(|e| format!("Failed to start llama-server: {e}"))?;
|
||||||
|
|
||||||
|
// Store state
|
||||||
|
let model_name = config
|
||||||
|
.model_path
|
||||||
|
.file_stem()
|
||||||
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
*proc = Some(child);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut p = self.port.lock().map_err(|e| e.to_string())?;
|
||||||
|
*p = port;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut m = self.model_path.lock().map_err(|e| e.to_string())?;
|
||||||
|
*m = model_name.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for server to be ready (health endpoint)
|
||||||
|
self.wait_for_ready(port)?;
|
||||||
|
|
||||||
|
Ok(LlamaStatus {
|
||||||
|
running: true,
|
||||||
|
port,
|
||||||
|
model: model_name,
|
||||||
|
url: format!("http://127.0.0.1:{port}"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wait for the llama-server health endpoint to respond.
|
||||||
|
fn wait_for_ready(&self, port: u16) -> Result<(), String> {
|
||||||
|
let start = Instant::now();
|
||||||
|
let timeout = Duration::from_secs(60); // Models can take time to load
|
||||||
|
let _url = format!("http://127.0.0.1:{port}/health");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if start.elapsed() > timeout {
|
||||||
|
// Kill the process since it didn't start in time
|
||||||
|
self.stop().ok();
|
||||||
|
return Err("llama-server did not start within 60 seconds".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if process is still alive
|
||||||
|
{
|
||||||
|
let mut proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
if let Some(ref mut child) = *proc {
|
||||||
|
match child.try_wait() {
|
||||||
|
Ok(Some(status)) => {
|
||||||
|
*proc = None;
|
||||||
|
return Err(format!("llama-server exited with status: {status}"));
|
||||||
|
}
|
||||||
|
Ok(None) => {} // Still running
|
||||||
|
Err(e) => {
|
||||||
|
return Err(format!("Error checking process: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to connect to health endpoint
|
||||||
|
match std::net::TcpStream::connect_timeout(
|
||||||
|
&format!("127.0.0.1:{port}").parse().unwrap(),
|
||||||
|
Duration::from_millis(500),
|
||||||
|
) {
|
||||||
|
Ok(_) => return Ok(()),
|
||||||
|
Err(_) => {
|
||||||
|
std::thread::sleep(Duration::from_millis(500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop the llama-server process.
|
||||||
|
pub fn stop(&self) -> Result<(), String> {
|
||||||
|
let mut proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
if let Some(ref mut child) = proc.take() {
|
||||||
|
let _ = child.kill();
|
||||||
|
let _ = child.wait();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current status.
|
||||||
|
pub fn status(&self) -> LlamaStatus {
|
||||||
|
let running = self
|
||||||
|
.process
|
||||||
|
.lock()
|
||||||
|
.ok()
|
||||||
|
.map_or(false, |p| p.is_some());
|
||||||
|
let port = self.port.lock().ok().map_or(0, |p| *p);
|
||||||
|
let model = self
|
||||||
|
.model_path
|
||||||
|
.lock()
|
||||||
|
.ok()
|
||||||
|
.map_or_else(String::new, |m| m.clone());
|
||||||
|
|
||||||
|
LlamaStatus {
|
||||||
|
running,
|
||||||
|
port,
|
||||||
|
model,
|
||||||
|
url: if running {
|
||||||
|
format!("http://127.0.0.1:{port}")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List available GGUF model files in the models directory.
|
||||||
|
pub fn list_models() -> Vec<ModelInfo> {
|
||||||
|
let models_dir = Self::models_dir();
|
||||||
|
if !models_dir.exists() {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut models = vec![];
|
||||||
|
if let Ok(entries) = std::fs::read_dir(&models_dir) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.extension().map_or(false, |ext| ext == "gguf") {
|
||||||
|
let name = path
|
||||||
|
.file_stem()
|
||||||
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let size_bytes = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0);
|
||||||
|
models.push(ModelInfo {
|
||||||
|
name,
|
||||||
|
path: path.to_string_lossy().to_string(),
|
||||||
|
size_mb: (size_bytes as f64 / 1_048_576.0).round() as u64,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
models.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
models
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for LlamaManager {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = self.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information about a GGUF model file.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ModelInfo {
|
||||||
|
pub name: String,
|
||||||
|
pub path: String,
|
||||||
|
pub size_mb: u64,
|
||||||
|
}
|
||||||
@@ -20,7 +20,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
"csp": null
|
"csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost; media-src 'self' asset: https://asset.localhost; style-src 'self' 'unsafe-inline'",
|
||||||
|
"assetProtocol": {
|
||||||
|
"enable": true,
|
||||||
|
"scope": ["**"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
@@ -32,6 +36,24 @@
|
|||||||
"icons/128x128@2x.png",
|
"icons/128x128@2x.png",
|
||||||
"icons/icon.icns",
|
"icons/icon.icns",
|
||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
]
|
],
|
||||||
|
"category": "Utility",
|
||||||
|
"shortDescription": "Transcribe audio/video with speaker identification",
|
||||||
|
"longDescription": "Voice to Notes is a desktop application that transcribes audio and video recordings with speaker identification, synchronized playback, and AI-powered analysis. Export to SRT, WebVTT, ASS captions, or plain text.",
|
||||||
|
"copyright": "Voice to Notes Contributors",
|
||||||
|
"license": "MIT",
|
||||||
|
"linux": {
|
||||||
|
"deb": {
|
||||||
|
"depends": ["python3", "python3-pip"]
|
||||||
|
},
|
||||||
|
"appimage": {
|
||||||
|
"bundleMediaFramework": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"windows": {
|
||||||
|
"wix": {
|
||||||
|
"language": "en-US"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
287
src/lib/components/SettingsModal.svelte
Normal file
287
src/lib/components/SettingsModal.svelte
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { settings, saveSettings, type AppSettings } from '$lib/stores/settings';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
visible: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { visible, onClose }: Props = $props();
|
||||||
|
|
||||||
|
let localSettings = $state<AppSettings>({ ...$settings });
|
||||||
|
let activeTab = $state<'transcription' | 'ai' | 'local'>('transcription');
|
||||||
|
|
||||||
|
// Sync when settings store changes
|
||||||
|
$effect(() => {
|
||||||
|
localSettings = { ...$settings };
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleSave() {
|
||||||
|
await saveSettings(localSettings);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCancel() {
|
||||||
|
localSettings = { ...$settings };
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOverlayClick(e: MouseEvent) {
|
||||||
|
if ((e.target as HTMLElement).classList.contains('modal-overlay')) {
|
||||||
|
handleCancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if visible}
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<div class="modal-overlay" onclick={handleOverlayClick} onkeydown={(e) => { if (e.key === 'Escape') handleCancel(); }}>
|
||||||
|
<div class="modal">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h2>Settings</h2>
|
||||||
|
<button class="close-btn" onclick={handleCancel}>x</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs">
|
||||||
|
<button class="tab" class:active={activeTab === 'transcription'} onclick={() => activeTab = 'transcription'}>
|
||||||
|
Transcription
|
||||||
|
</button>
|
||||||
|
<button class="tab" class:active={activeTab === 'ai'} onclick={() => activeTab = 'ai'}>
|
||||||
|
AI Provider
|
||||||
|
</button>
|
||||||
|
<button class="tab" class:active={activeTab === 'local'} onclick={() => activeTab = 'local'}>
|
||||||
|
Local AI
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
{#if activeTab === 'transcription'}
|
||||||
|
<div class="field">
|
||||||
|
<label for="stt-model">Whisper Model</label>
|
||||||
|
<select id="stt-model" bind:value={localSettings.transcription_model}>
|
||||||
|
<option value="tiny">Tiny (fastest, least accurate)</option>
|
||||||
|
<option value="base">Base (fast, good accuracy)</option>
|
||||||
|
<option value="small">Small (balanced)</option>
|
||||||
|
<option value="medium">Medium (slower, better accuracy)</option>
|
||||||
|
<option value="large-v3">Large v3 (slowest, best accuracy)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="stt-device">Device</label>
|
||||||
|
<select id="stt-device" bind:value={localSettings.transcription_device}>
|
||||||
|
<option value="cpu">CPU</option>
|
||||||
|
<option value="cuda">CUDA (NVIDIA GPU)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="stt-lang">Language (blank = auto-detect)</label>
|
||||||
|
<input id="stt-lang" type="text" bind:value={localSettings.transcription_language} placeholder="e.g., en, es, fr" />
|
||||||
|
</div>
|
||||||
|
<div class="field checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" bind:checked={localSettings.skip_diarization} />
|
||||||
|
Skip speaker diarization (faster, no speaker labels)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{:else if activeTab === 'ai'}
|
||||||
|
<div class="field">
|
||||||
|
<label for="ai-provider">AI Provider</label>
|
||||||
|
<select id="ai-provider" bind:value={localSettings.ai_provider}>
|
||||||
|
<option value="local">Local (llama-server)</option>
|
||||||
|
<option value="openai">OpenAI</option>
|
||||||
|
<option value="anthropic">Anthropic</option>
|
||||||
|
<option value="litellm">LiteLLM</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if localSettings.ai_provider === 'openai'}
|
||||||
|
<div class="field">
|
||||||
|
<label for="openai-key">OpenAI API Key</label>
|
||||||
|
<input id="openai-key" type="password" bind:value={localSettings.openai_api_key} placeholder="sk-..." />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="openai-model">Model</label>
|
||||||
|
<input id="openai-model" type="text" bind:value={localSettings.openai_model} />
|
||||||
|
</div>
|
||||||
|
{:else if localSettings.ai_provider === 'anthropic'}
|
||||||
|
<div class="field">
|
||||||
|
<label for="anthropic-key">Anthropic API Key</label>
|
||||||
|
<input id="anthropic-key" type="password" bind:value={localSettings.anthropic_api_key} placeholder="sk-ant-..." />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="anthropic-model">Model</label>
|
||||||
|
<input id="anthropic-model" type="text" bind:value={localSettings.anthropic_model} />
|
||||||
|
</div>
|
||||||
|
{:else if localSettings.ai_provider === 'litellm'}
|
||||||
|
<div class="field">
|
||||||
|
<label for="litellm-model">Model</label>
|
||||||
|
<input id="litellm-model" type="text" bind:value={localSettings.litellm_model} placeholder="provider/model-name" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<div class="field">
|
||||||
|
<label for="llama-binary">llama-server Binary Path</label>
|
||||||
|
<input id="llama-binary" type="text" bind:value={localSettings.local_binary_path} placeholder="llama-server" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="llama-model">GGUF Model Path</label>
|
||||||
|
<input id="llama-model" type="text" bind:value={localSettings.local_model_path} placeholder="~/.voicetonotes/models/model.gguf" />
|
||||||
|
</div>
|
||||||
|
<p class="hint">
|
||||||
|
Place GGUF model files in ~/.voicetonotes/models/ for auto-detection.
|
||||||
|
The local AI server uses the OpenAI-compatible API from llama.cpp.
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn-secondary" onclick={handleCancel}>Cancel</button>
|
||||||
|
<button class="btn-primary" onclick={handleSave}>Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
.modal {
|
||||||
|
background: #16213e;
|
||||||
|
border-radius: 12px;
|
||||||
|
width: 500px;
|
||||||
|
max-width: 90vw;
|
||||||
|
max-height: 80vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
color: #e0e0e0;
|
||||||
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.modal-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
border-bottom: 1px solid #2a3a5e;
|
||||||
|
}
|
||||||
|
.modal-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
.close-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #999;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
||||||
|
.close-btn:hover {
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
.tabs {
|
||||||
|
display: flex;
|
||||||
|
border-bottom: 1px solid #2a3a5e;
|
||||||
|
padding: 0 1.25rem;
|
||||||
|
}
|
||||||
|
.tab {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #888;
|
||||||
|
padding: 0.6rem 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
}
|
||||||
|
.tab:hover {
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
.tab.active {
|
||||||
|
color: #e94560;
|
||||||
|
border-bottom-color: #e94560;
|
||||||
|
}
|
||||||
|
.modal-body {
|
||||||
|
padding: 1.25rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.field {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
.field label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #aaa;
|
||||||
|
margin-bottom: 0.3rem;
|
||||||
|
}
|
||||||
|
.field input,
|
||||||
|
.field select {
|
||||||
|
width: 100%;
|
||||||
|
background: #1a1a2e;
|
||||||
|
color: #e0e0e0;
|
||||||
|
border: 1px solid #4a5568;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-family: inherit;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
.field input:focus,
|
||||||
|
.field select:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #e94560;
|
||||||
|
}
|
||||||
|
.field.checkbox label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
.field.checkbox input {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #666;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
.modal-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
border-top: 1px solid #2a3a5e;
|
||||||
|
}
|
||||||
|
.btn-secondary {
|
||||||
|
background: none;
|
||||||
|
border: 1px solid #4a5568;
|
||||||
|
color: #e0e0e0;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background: rgba(255,255,255,0.05);
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background: #e94560;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: #d63851;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -57,7 +57,8 @@
|
|||||||
wavesurfer?.destroy();
|
wavesurfer?.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
function togglePlayPause() {
|
/** Toggle play/pause. Exposed for keyboard shortcuts. */
|
||||||
|
export function togglePlayPause() {
|
||||||
wavesurfer?.playPause();
|
wavesurfer?.playPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
48
src/lib/stores/settings.ts
Normal file
48
src/lib/stores/settings.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
|
export interface AppSettings {
|
||||||
|
ai_provider: string;
|
||||||
|
openai_api_key: string;
|
||||||
|
anthropic_api_key: string;
|
||||||
|
openai_model: string;
|
||||||
|
anthropic_model: string;
|
||||||
|
litellm_model: string;
|
||||||
|
local_model_path: string;
|
||||||
|
local_binary_path: string;
|
||||||
|
transcription_model: string;
|
||||||
|
transcription_device: string;
|
||||||
|
transcription_language: string;
|
||||||
|
skip_diarization: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaults: AppSettings = {
|
||||||
|
ai_provider: 'local',
|
||||||
|
openai_api_key: '',
|
||||||
|
anthropic_api_key: '',
|
||||||
|
openai_model: 'gpt-4o-mini',
|
||||||
|
anthropic_model: 'claude-sonnet-4-6',
|
||||||
|
litellm_model: 'gpt-4o-mini',
|
||||||
|
local_model_path: '',
|
||||||
|
local_binary_path: 'llama-server',
|
||||||
|
transcription_model: 'base',
|
||||||
|
transcription_device: 'cpu',
|
||||||
|
transcription_language: '',
|
||||||
|
skip_diarization: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const settings = writable<AppSettings>({ ...defaults });
|
||||||
|
|
||||||
|
export async function loadSettings(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const saved = await invoke<Record<string, unknown>>('load_settings');
|
||||||
|
settings.update(s => ({ ...s, ...saved } as AppSettings));
|
||||||
|
} catch {
|
||||||
|
// Use defaults if settings can't be loaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveSettings(s: AppSettings): Promise<void> {
|
||||||
|
settings.set(s);
|
||||||
|
await invoke('save_settings', { settings: s });
|
||||||
|
}
|
||||||
@@ -6,11 +6,58 @@
|
|||||||
import SpeakerManager from '$lib/components/SpeakerManager.svelte';
|
import SpeakerManager from '$lib/components/SpeakerManager.svelte';
|
||||||
import AIChatPanel from '$lib/components/AIChatPanel.svelte';
|
import AIChatPanel from '$lib/components/AIChatPanel.svelte';
|
||||||
import ProgressOverlay from '$lib/components/ProgressOverlay.svelte';
|
import ProgressOverlay from '$lib/components/ProgressOverlay.svelte';
|
||||||
|
import SettingsModal from '$lib/components/SettingsModal.svelte';
|
||||||
import { segments, speakers } from '$lib/stores/transcript';
|
import { segments, speakers } from '$lib/stores/transcript';
|
||||||
|
import { settings, loadSettings } from '$lib/stores/settings';
|
||||||
import type { Segment, Speaker } from '$lib/types/transcript';
|
import type { Segment, Speaker } from '$lib/types/transcript';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
let waveformPlayer: WaveformPlayer;
|
let waveformPlayer: WaveformPlayer;
|
||||||
let audioUrl = $state('');
|
let audioUrl = $state('');
|
||||||
|
let showSettings = $state(false);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
|
// Global keyboard shortcuts
|
||||||
|
function handleKeyDown(e: KeyboardEvent) {
|
||||||
|
// Don't trigger shortcuts when typing in inputs
|
||||||
|
const tag = (e.target as HTMLElement)?.tagName;
|
||||||
|
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
|
||||||
|
|
||||||
|
if (e.key === ' ' && !e.ctrlKey && !e.metaKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
waveformPlayer?.togglePlayPause?.();
|
||||||
|
} else if (e.key === 'o' && (e.ctrlKey || e.metaKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
handleFileImport();
|
||||||
|
} else if (e.key === ',' && (e.ctrlKey || e.metaKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
showSettings = true;
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
showExportMenu = false;
|
||||||
|
showSettings = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close export dropdown on outside click
|
||||||
|
function handleClickOutside(e: MouseEvent) {
|
||||||
|
if (showExportMenu) {
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
if (!target.closest('.export-dropdown')) {
|
||||||
|
showExportMenu = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
document.addEventListener('click', handleClickOutside);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
|
document.removeEventListener('click', handleClickOutside);
|
||||||
|
};
|
||||||
|
});
|
||||||
let isTranscribing = $state(false);
|
let isTranscribing = $state(false);
|
||||||
let transcriptionProgress = $state(0);
|
let transcriptionProgress = $state(0);
|
||||||
let transcriptionStage = $state('');
|
let transcriptionStage = $state('');
|
||||||
@@ -61,7 +108,13 @@
|
|||||||
duration_ms: number;
|
duration_ms: number;
|
||||||
speakers: string[];
|
speakers: string[];
|
||||||
num_speakers: number;
|
num_speakers: number;
|
||||||
}>('run_pipeline', { filePath });
|
}>('run_pipeline', {
|
||||||
|
filePath,
|
||||||
|
model: $settings.transcription_model || undefined,
|
||||||
|
device: $settings.transcription_device || undefined,
|
||||||
|
language: $settings.transcription_language || undefined,
|
||||||
|
skipDiarization: $settings.skip_diarization || undefined,
|
||||||
|
});
|
||||||
|
|
||||||
// Create speaker entries from pipeline result
|
// Create speaker entries from pipeline result
|
||||||
const newSpeakers: Speaker[] = (result.speakers || []).map((label, idx) => ({
|
const newSpeakers: Speaker[] = (result.speakers || []).map((label, idx) => ({
|
||||||
@@ -167,6 +220,9 @@
|
|||||||
<button class="import-btn" onclick={handleFileImport}>
|
<button class="import-btn" onclick={handleFileImport}>
|
||||||
Import Audio/Video
|
Import Audio/Video
|
||||||
</button>
|
</button>
|
||||||
|
<button class="settings-btn" onclick={() => showSettings = true} title="Settings">
|
||||||
|
Settings
|
||||||
|
</button>
|
||||||
{#if $segments.length > 0}
|
{#if $segments.length > 0}
|
||||||
<div class="export-dropdown">
|
<div class="export-dropdown">
|
||||||
<button class="export-btn" onclick={() => showExportMenu = !showExportMenu}>
|
<button class="export-btn" onclick={() => showExportMenu = !showExportMenu}>
|
||||||
@@ -204,6 +260,11 @@
|
|||||||
message={transcriptionMessage}
|
message={transcriptionMessage}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<SettingsModal
|
||||||
|
visible={showSettings}
|
||||||
|
onClose={() => showSettings = false}
|
||||||
|
/>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.app-header {
|
.app-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -235,6 +296,19 @@
|
|||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
.settings-btn {
|
||||||
|
background: none;
|
||||||
|
border: 1px solid #4a5568;
|
||||||
|
color: #e0e0e0;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
.settings-btn:hover {
|
||||||
|
background: rgba(255,255,255,0.05);
|
||||||
|
border-color: #e94560;
|
||||||
|
}
|
||||||
.export-dropdown {
|
.export-dropdown {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user