- lib.rs rewritten from scaffold to full app setup (~70 lines) - AppState holds Arc<LocalEngine> for Whisper and Parakeet - commands/models.rs: download, check, list, load for both engines Maps legacy size strings (Tiny/Base/Small/Medium) to ModelId - commands/transcription.rs: transcribe_pcm, transcribe_file, transcribe_pcm_parakeet Delegates to LocalEngine.transcribe_sync() + post_process_segments() - commands/audio.rs: save_audio via kon_audio::write_wav - commands/windows.rs: open_task_window, open_viewer_window - commands/llm.rs: 8 stub commands preserved for frontend compatibility - tray.rs: extracted system tray setup (show, status, quit, click-to-show) - Close-to-tray behaviour preserved - All 25 v0.2 command names preserved for Svelte frontend compatibility - clippy clean Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use tauri::Manager;
|
|
|
|
use kon_core::types::AudioSamples;
|
|
|
|
/// Save PCM f32 samples as a WAV file. Returns the file path.
|
|
#[tauri::command]
|
|
pub async fn save_audio(
|
|
app: tauri::AppHandle,
|
|
samples: Vec<f32>,
|
|
output_folder: Option<String>,
|
|
) -> Result<String, String> {
|
|
let recordings_dir = if let Some(ref folder) = output_folder {
|
|
if !folder.is_empty() {
|
|
PathBuf::from(folder)
|
|
} else {
|
|
app.path()
|
|
.app_local_data_dir()
|
|
.map_err(|e: tauri::Error| e.to_string())?
|
|
.join("recordings")
|
|
}
|
|
} else {
|
|
app.path()
|
|
.app_local_data_dir()
|
|
.map_err(|e: tauri::Error| e.to_string())?
|
|
.join("recordings")
|
|
};
|
|
|
|
std::fs::create_dir_all(&recordings_dir)
|
|
.map_err(|e| format!("Failed to create recordings dir: {e}"))?;
|
|
|
|
let timestamp = std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.unwrap_or_default()
|
|
.as_secs();
|
|
let filename = format!("kon-{timestamp}.wav");
|
|
let path = recordings_dir.join(&filename);
|
|
let path_clone = path.clone();
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
let audio = AudioSamples::mono_16khz(samples);
|
|
kon_audio::write_wav(&path_clone, &audio).map_err(|e| e.to_string())
|
|
})
|
|
.await
|
|
.map_err(|e| e.to_string())??;
|
|
|
|
Ok(path.to_string_lossy().to_string())
|
|
}
|